2 * This file is part of hildon-libs
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
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
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.
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
26 * SECTION:hildon-font-selection-dialog
27 * @short_description: A widget used to allow users to select a font
28 * with certain properties
30 * Font selection can be made using this widget. Users can select font name,
31 * size, style, etc. Users can also preview text in the selected font.
37 #include <gtk/gtkstock.h>
38 #include <gtk/gtkcombobox.h>
39 #include <gtk/gtktogglebutton.h>
40 #include <gtk/gtkcheckbutton.h>
41 #include <gtk/gtklabel.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkliststore.h>
44 #include <gtk/gtknotebook.h>
47 #include <gdk/gdkkeysyms.h>
49 #include "hildon-font-selection-dialog.h"
50 #include <hildon-widgets/hildon-caption.h>
51 #include <hildon-widgets/hildon-color-selector.h>
52 #include <hildon-widgets/hildon-color-button.h>
59 #define _(String) dgettext(PACKAGE, String)
61 #define SUPERSCRIPT_RISE 3333
62 #define SUBSCRIPT_LOW -3333
67 * These are what we use as the standard font sizes, for the size list.
69 static const guint16 font_sizes[] =
71 6, 8, 10, 12, 16, 24, 32
74 #define HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(obj) \
75 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
76 HILDON_TYPE_FONT_SELECTION_DIALOG, \
77 HildonFontSelectionDialogPrivate))
79 /*None of designed api function works, so now it all comes down to
80 *use properties to achieve what we are supposed to achieve*/
96 PROP_STRIKETHROUGH_SET,
104 _HildonFontSelectionDialogPrivate HildonFontSelectionDialogPrivate;
106 struct _HildonFontSelectionDialogPrivate
108 GtkNotebook *notebook;
113 GtkWidget *cbx_font_type;
114 GtkWidget *cbx_font_size;
115 GtkWidget *font_color_button;
119 GtkWidget *chk_italic;
120 GtkWidget *chk_underline;
123 GtkWidget *chk_strikethrough;
124 GtkWidget *cbx_positioning;
127 PangoFontFamily **families;
130 /*color_set is used to show whether the color is inconsistent
131 * The handler id is used to block the signal emission
132 * when we change the color setting*/
136 /* font_scaling is the scaling factor applied to font
137 * scale in the preview dialog */
139 gdouble font_scaling;
140 gulong color_modified_signal_handler;
143 /*combo box active row indicator -2--inconsistent, -1--undefined
144 * please make sure that you use settings_init settings_apply
145 * and settings_destroy, dont even try to touch this structure
146 * without using the three above interface functions, of course
147 * if you know what you are doing, do as you please ;-)*/
150 HildonFontSelectionDialog
151 *fsd; /*pointer to our font selection dialog*/
153 gint family; /*combo box indicator*/
154 gint size; /*combo box indicator*/
155 GdkColor *color; /*free after read the setting*/
156 gboolean color_inconsist;
157 gint weight; /*bit mask*/
158 gint style; /*bit mask*/
159 gint underline; /*bit mask*/
160 gint strikethrough; /*bit mask*/
161 gint position; /*combo box indicator*/
163 }HildonFontSelectionDialogSettings;
166 hildon_font_selection_dialog_preview_key_press
171 /*Some tools from gtk_font_selection*/
172 static int cmp_families (const void *a, const void *b);
174 static void hildon_font_selection_dialog_show_preview
175 (HildonFontSelectionDialog
178 static PangoAttrList*
179 hildon_font_selection_dialog_create_attrlist
180 (HildonFontSelectionDialog
181 *fontsel, guint start_index,
184 static void hildon_font_selection_dialog_show_available_positionings
185 (HildonFontSelectionDialogPrivate
188 static void hildon_font_selection_dialog_show_available_fonts
189 (HildonFontSelectionDialog
192 static void hildon_font_selection_dialog_show_available_sizes
193 (HildonFontSelectionDialogPrivate
196 static void hildon_font_selection_dialog_class_init
197 (HildonFontSelectionDialogClass
200 static void hildon_font_selection_dialog_init
201 (HildonFontSelectionDialog
204 static void hildon_font_selection_dialog_finalize
207 static void hildon_font_selection_dialog_construct_notebook
208 (HildonFontSelectionDialog
211 static void color_modified_cb (HildonColorButton *button,
215 static void check_tags (gpointer data,
218 static void settings_init (HildonFontSelectionDialogSettings
220 HildonFontSelectionDialog
223 static void settings_apply (HildonFontSelectionDialogSettings
226 static void settings_destroy (HildonFontSelectionDialogSettings
229 static void bit_mask_toggle (gint mask, GtkToggleButton*
230 button, GObject *object,
232 const gchar *prop_set);
234 static void combo_active (gint active, GtkComboBox *box,
237 const gchar *prop_set);
239 static void add_preview_text_attr (PangoAttrList *list,
240 PangoAttribute *attr,
244 static void toggle_clicked (GtkButton *button,
249 static GtkDialogClass *font_selection_dialog_parent_class = NULL;
251 GType hildon_font_selection_dialog_get_type(void)
253 static GType font_selection_dialog_type = 0;
255 if (!font_selection_dialog_type) {
256 static const GTypeInfo fontsel_diag_info = {
257 sizeof(HildonFontSelectionDialogClass),
258 NULL, /* base_init */
259 NULL, /* base_finalize */
260 (GClassInitFunc) hildon_font_selection_dialog_class_init,
261 NULL, /* class_finalize */
262 NULL, /* class_data */
263 sizeof(HildonFontSelectionDialog),
265 (GInstanceInitFunc) hildon_font_selection_dialog_init,
268 font_selection_dialog_type =
269 g_type_register_static(GTK_TYPE_DIALOG,
270 "HildonFontSelectionDialog",
271 &fontsel_diag_info, 0);
274 return font_selection_dialog_type;
278 hildon_font_selection_dialog_get_property (GObject *object,
284 GdkColor *color = NULL;
286 HildonFontSelectionDialogPrivate *priv =
287 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(
288 HILDON_FONT_SELECTION_DIALOG(object));
294 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_font_type));
295 if(i >= 0 && i < priv->n_families)
296 g_value_set_string(value,
297 pango_font_family_get_name(priv->families[i]));
299 g_value_set_string(value, "Sans");
302 case PROP_FAMILY_SET:
303 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_font_type));
304 if(i >= 0 && i < priv->n_families)
305 g_value_set_boolean(value, TRUE);
307 g_value_set_boolean(value, FALSE);
311 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_font_size));
312 if(i >= 0 && i < G_N_ELEMENTS(font_sizes))
313 g_value_set_int(value, font_sizes[i]);
315 g_value_set_int(value, 16);
319 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_font_size));
320 if(i >= 0 && i < G_N_ELEMENTS(font_sizes))
321 g_value_set_boolean(value, TRUE);
323 g_value_set_boolean(value, FALSE);
327 color = hildon_color_button_get_color
328 (HILDON_COLOR_BUTTON(priv->font_color_button));
329 g_value_set_boxed(value, (gconstpointer) color);
331 gdk_color_free(color);
335 g_value_set_boolean(value, priv->color_set);
339 g_value_set_boolean(value,
340 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->chk_bold)));
344 g_value_set_boolean(value,
345 !gtk_toggle_button_get_inconsistent
346 (GTK_TOGGLE_BUTTON(priv->chk_bold)));
350 g_value_set_boolean(value,
351 gtk_toggle_button_get_active
352 (GTK_TOGGLE_BUTTON(priv->chk_italic)));
355 case PROP_ITALIC_SET:
356 g_value_set_boolean(value,
357 !gtk_toggle_button_get_inconsistent
358 (GTK_TOGGLE_BUTTON(priv->chk_italic)));
362 g_value_set_boolean(value,
363 gtk_toggle_button_get_active
364 (GTK_TOGGLE_BUTTON(priv->chk_underline)));
367 case PROP_UNDERLINE_SET:
368 g_value_set_boolean(value,
369 !gtk_toggle_button_get_inconsistent
370 (GTK_TOGGLE_BUTTON(priv->chk_underline)));
373 case PROP_STRIKETHROUGH:
374 g_value_set_boolean(value,
375 gtk_toggle_button_get_active
376 (GTK_TOGGLE_BUTTON(priv->chk_strikethrough)));
379 case PROP_STRIKETHROUGH_SET:
380 g_value_set_boolean(value,
381 !gtk_toggle_button_get_inconsistent
382 (GTK_TOGGLE_BUTTON(priv->chk_strikethrough)));
386 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_positioning));
388 g_value_set_int(value, 1);
389 else if(i == 2)/*sub*/
390 g_value_set_int(value, -1);
392 g_value_set_int(value, 0);
395 case PROP_FONT_SCALING:
396 g_value_set_double(value, priv->font_scaling);
399 case PROP_POSITION_SET:
400 i = gtk_combo_box_get_active(GTK_COMBO_BOX(priv->cbx_positioning));
402 g_value_set_boolean(value, TRUE);
404 g_value_set_boolean(value, FALSE);
407 case PROP_PREVIEW_TEXT:
408 g_value_set_string(value,
409 hildon_font_selection_dialog_get_preview_text(
410 HILDON_FONT_SELECTION_DIALOG(object)));
414 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
420 hildon_font_selection_dialog_set_property (GObject *object,
428 GdkColor *color = NULL;
431 HildonFontSelectionDialogPrivate *priv =
432 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(
433 HILDON_FONT_SELECTION_DIALOG(object));
434 black.red = black.green = black.blue = 0;
439 str = g_value_get_string(value);
440 for(i = 0; i < priv->n_families; i++)
442 if(strcmp(str, pango_font_family_get_name(priv->families[i]))
445 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_font_type), i);
451 case PROP_FAMILY_SET:
452 b = g_value_get_boolean(value);
454 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_font_type), -1);
458 size = g_value_get_int(value);
459 for(i = 0; i < G_N_ELEMENTS(font_sizes); i++)
461 if(size == font_sizes[i])
463 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_font_size), i);
470 b = g_value_get_boolean(value);
472 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_font_size), -1);
476 color = (GdkColor *) g_value_get_boxed(value);
478 hildon_color_button_set_color(HILDON_COLOR_BUTTON
479 (priv->font_color_button),
482 hildon_color_button_set_color(HILDON_COLOR_BUTTON
483 (priv->font_color_button),
488 priv->color_set = g_value_get_boolean(value);
491 /*set color to black, but block our signal handler*/
492 g_signal_handler_block((gpointer) priv->font_color_button,
493 priv->color_modified_signal_handler);
495 hildon_color_button_set_color(HILDON_COLOR_BUTTON
496 (priv->font_color_button),
499 g_signal_handler_unblock((gpointer) priv->font_color_button,
500 priv->color_modified_signal_handler);
505 /*this call will make sure that we dont get extra clicked signal*/
506 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_bold),
508 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_bold),
509 g_value_get_boolean(value));
513 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_bold),
514 !g_value_get_boolean(value));
518 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
520 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_italic),
521 g_value_get_boolean(value));
524 case PROP_ITALIC_SET:
525 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
526 !g_value_get_boolean(value));
530 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
531 (priv->chk_underline),
533 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_underline),
534 g_value_get_boolean(value));
537 case PROP_UNDERLINE_SET:
538 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_underline),
539 !g_value_get_boolean(value));
542 case PROP_STRIKETHROUGH:
543 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
544 (priv->chk_strikethrough),
546 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_strikethrough),
547 g_value_get_boolean(value));
550 case PROP_STRIKETHROUGH_SET:
551 gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
552 (priv->chk_strikethrough),
553 !g_value_get_boolean(value));
557 i = g_value_get_int(value);
559 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 1);
561 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 2);
563 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 0);
566 case PROP_FONT_SCALING:
567 priv->font_scaling = g_value_get_double(value);
570 case PROP_POSITION_SET:
571 b = g_value_get_boolean(value);
573 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), -1);
576 case PROP_PREVIEW_TEXT:
577 hildon_font_selection_dialog_set_preview_text(
578 HILDON_FONT_SELECTION_DIALOG(object),
579 g_value_get_string(value));
583 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589 hildon_font_selection_dialog_class_init(HildonFontSelectionDialogClass *
592 GObjectClass *gobject_class;
594 font_selection_dialog_parent_class = g_type_class_peek_parent(klass);
595 gobject_class = G_OBJECT_CLASS(klass);
596 gobject_class->finalize = hildon_font_selection_dialog_finalize;
597 gobject_class->get_property = hildon_font_selection_dialog_get_property;
598 gobject_class->set_property = hildon_font_selection_dialog_set_property;
600 /* Install property to the class */
601 g_object_class_install_property(gobject_class, PROP_FAMILY,
602 g_param_spec_string("family",
603 "Font family", "String defines"
604 " the font family", "Sans",
607 g_object_class_install_property(gobject_class, PROP_FAMILY_SET,
608 g_param_spec_boolean ("family-set",
609 "family inconsistent state",
610 "Whether the family property"
611 " is inconsistent", FALSE,
612 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
614 g_object_class_install_property(gobject_class, PROP_SIZE,
615 g_param_spec_int ("size",
621 g_object_class_install_property(gobject_class, PROP_SIZE_SET,
622 g_param_spec_boolean ("size-set",
623 "size inconsistent state",
624 "Whether the size property"
625 " is inconsistent", FALSE,
626 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
628 g_object_class_install_property(gobject_class, PROP_COLOR,
629 g_param_spec_boxed ("color",
631 "gdk color for the text",
635 g_object_class_install_property(gobject_class, PROP_COLOR_SET,
636 g_param_spec_boolean ("color-set",
637 "color inconsistent state",
638 "Whether the color property"
639 " is inconsistent", FALSE,
640 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
642 g_object_class_install_property(gobject_class, PROP_BOLD,
643 g_param_spec_boolean ("bold",
645 "Whether the text is bold",
649 g_object_class_install_property(gobject_class, PROP_BOLD_SET,
650 g_param_spec_boolean ("bold-set",
651 "bold inconsistent state",
653 " is inconsistent", FALSE,
654 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
656 g_object_class_install_property(gobject_class, PROP_ITALIC,
657 g_param_spec_boolean ("italic",
659 "Whether the text is italic",
663 g_object_class_install_property(gobject_class, PROP_ITALIC_SET,
664 g_param_spec_boolean ("italic-set",
665 "italic inconsistent state",
667 " is inconsistent", FALSE,
668 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
670 g_object_class_install_property(gobject_class, PROP_UNDERLINE,
671 g_param_spec_boolean ("underline",
673 "Whether the text is underlined",
677 g_object_class_install_property(gobject_class, PROP_UNDERLINE_SET,
678 g_param_spec_boolean ("underline-set",
679 "underline inconsistent state",
680 "Whether the underline"
681 " is inconsistent", FALSE,
682 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
684 g_object_class_install_property(gobject_class, PROP_STRIKETHROUGH,
685 g_param_spec_boolean ("strikethrough",
686 "strikethroughed text",
687 "Whether the text is strikethroughed",
691 g_object_class_install_property(gobject_class, PROP_STRIKETHROUGH_SET,
692 g_param_spec_boolean ("strikethrough-set",
693 "strikethrough inconsistent state",
694 "Whether the strikethrough"
695 " is inconsistent", FALSE,
696 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
698 g_object_class_install_property(gobject_class, PROP_POSITION,
699 g_param_spec_int ("position",
701 "Font position super or subscript",
705 /* FIXME This was introduced in 0.14.1. We don't have documentation for
706 * properties anyways, but once it's there it needs to be marked as
708 g_object_class_install_property(gobject_class, PROP_FONT_SCALING,
709 g_param_spec_double ("font-scaling",
711 "Font scaling for the preview dialog",
715 g_object_class_install_property(gobject_class, PROP_POSITION_SET,
716 g_param_spec_boolean ("position-set",
717 "position inconsistent state",
718 "Whether the position"
719 " is inconsistent", FALSE,
720 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
722 g_object_class_install_property(gobject_class, PROP_PREVIEW_TEXT,
723 g_param_spec_string("preview-text",
725 "the text in preview dialog, which does"
726 "not include the reference text",
731 g_type_class_add_private(klass,
732 sizeof(struct _HildonFontSelectionDialogPrivate));
737 hildon_font_selection_dialog_init(HildonFontSelectionDialog *fontseldiag)
739 HildonFontSelectionDialogPrivate *priv =
740 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fontseldiag);
741 GtkWidget *preview_button;
743 priv->notebook = GTK_NOTEBOOK(gtk_notebook_new());
745 hildon_font_selection_dialog_construct_notebook(fontseldiag);
747 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fontseldiag)->vbox),
748 GTK_WIDGET(priv->notebook), TRUE, TRUE, 0);
750 /* Add dialog buttons */
751 gtk_dialog_add_button(GTK_DIALOG(fontseldiag),
752 _("ecdg_bd_font_dialog_ok"),
755 preview_button = gtk_button_new_with_label(_("ecdg_bd_font_dialog_preview"));
756 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fontseldiag)->action_area),
757 preview_button, FALSE, TRUE, 0);
758 g_signal_connect_swapped(preview_button, "clicked",
760 (hildon_font_selection_dialog_show_preview),
762 gtk_widget_show(preview_button);
764 gtk_dialog_add_button(GTK_DIALOG(fontseldiag),
765 _("ecdg_bd_font_dialog_cancel"),
766 GTK_RESPONSE_CANCEL);
768 /*Set default preview text*/
769 priv->preview_text = g_strdup(_("ecdg_fi_preview_font_preview_text"));
771 gtk_window_set_title(GTK_WINDOW(fontseldiag), _("ecdg_ti_font"));
772 /*here is the line to make sure that notebook has the default focus*/
773 gtk_container_set_focus_child(GTK_CONTAINER(GTK_DIALOG(fontseldiag)->vbox),
774 GTK_WIDGET(priv->notebook));
778 hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog
782 GtkWidget *vbox_tab[3];
783 GtkWidget *font_color_box;
784 GtkWidget *caption_control;
787 HildonFontSelectionDialogPrivate *priv =
788 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fontsel);
790 for (i = 0; i < 3; i++)
791 vbox_tab[i] = gtk_vbox_new(TRUE, 0);
794 GTK_SIZE_GROUP(gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL));
796 /* Build the first page of the GtkNotebook: font style */
797 priv->cbx_font_type = gtk_combo_box_new_text();
798 hildon_font_selection_dialog_show_available_fonts(fontsel);
799 caption_control = hildon_caption_new(group,
800 _("ecdg_fi_font_font"),
803 HILDON_CAPTION_OPTIONAL);
804 gtk_box_pack_start(GTK_BOX(vbox_tab[0]), caption_control,
807 priv->cbx_font_size = gtk_combo_box_new_text();
808 hildon_font_selection_dialog_show_available_sizes(priv);
809 caption_control = hildon_caption_new(group,
810 _("ecdg_fi_font_size"),
813 HILDON_CAPTION_OPTIONAL);
814 gtk_box_pack_start(GTK_BOX(vbox_tab[0]), caption_control,
817 font_color_box = gtk_hbox_new(FALSE, 0);
818 priv->font_color_button = hildon_color_button_new();
819 priv->color_set = FALSE;
820 priv->font_scaling = 1.0;
821 priv->color_modified_signal_handler =
822 g_signal_connect(G_OBJECT(priv->font_color_button), "notify::color",
823 G_CALLBACK(color_modified_cb), (gpointer) priv);
824 gtk_box_pack_start(GTK_BOX(font_color_box),
825 priv->font_color_button, FALSE, FALSE, 0);
828 hildon_caption_new(group, _("ecdg_fi_font_colour_selector"),
830 NULL, HILDON_CAPTION_OPTIONAL);
832 gtk_box_pack_start(GTK_BOX(vbox_tab[0]), caption_control,
835 /* Build the second page of the GtkNotebook: font formatting */
836 priv->chk_bold = gtk_check_button_new();
837 caption_control = hildon_caption_new(group,
838 _("ecdg_fi_font_bold"),
841 HILDON_CAPTION_OPTIONAL);
842 gtk_box_pack_start(GTK_BOX(vbox_tab[1]), caption_control,
844 g_signal_connect(G_OBJECT(priv->chk_bold), "clicked",
845 G_CALLBACK(toggle_clicked), NULL);
847 priv->chk_italic = gtk_check_button_new();
849 hildon_caption_new(group, _("ecdg_fi_font_italic"),
851 NULL, HILDON_CAPTION_OPTIONAL);
852 gtk_box_pack_start(GTK_BOX(vbox_tab[1]), caption_control,
854 g_signal_connect(G_OBJECT(priv->chk_italic), "clicked",
855 G_CALLBACK(toggle_clicked), NULL);
857 priv->chk_underline = gtk_check_button_new();
859 hildon_caption_new(group, _("ecdg_fi_font_underline"),
860 priv->chk_underline, NULL,
861 HILDON_CAPTION_OPTIONAL);
862 gtk_box_pack_start(GTK_BOX(vbox_tab[1]), caption_control,
864 g_signal_connect(G_OBJECT(priv->chk_underline), "clicked",
865 G_CALLBACK(toggle_clicked), NULL);
867 /* Build the third page of the GtkNotebook: other font properties */
868 priv->chk_strikethrough = gtk_check_button_new();
870 hildon_caption_new(group, _("ecdg_fi_font_strikethrough"),
871 priv->chk_strikethrough, NULL,
872 HILDON_CAPTION_OPTIONAL);
873 gtk_box_pack_start(GTK_BOX(vbox_tab[2]), caption_control,
875 g_signal_connect(G_OBJECT(priv->chk_strikethrough), "clicked",
876 G_CALLBACK(toggle_clicked), NULL);
878 priv->cbx_positioning = gtk_combo_box_new_text();
879 hildon_font_selection_dialog_show_available_positionings(priv);
881 hildon_caption_new(group, _("ecdg_fi_font_special"),
882 priv->cbx_positioning, NULL,
883 HILDON_CAPTION_OPTIONAL);
884 gtk_box_pack_start(GTK_BOX(vbox_tab[2]), caption_control,
887 /* Populate notebook */
888 gtk_notebook_insert_page(priv->notebook, vbox_tab[0], NULL, 0);
889 gtk_notebook_insert_page(priv->notebook, vbox_tab[1], NULL, 1);
890 gtk_notebook_insert_page(priv->notebook, vbox_tab[2], NULL, 2);
891 gtk_notebook_set_tab_label_text(priv->notebook, vbox_tab[0],
892 _("ecdg_ti_font_dialog_style"));
893 gtk_notebook_set_tab_label_text(priv->notebook, vbox_tab[1],
894 _("ecdg_ti_font_dialog_format"));
895 gtk_notebook_set_tab_label_text(priv->notebook, vbox_tab[2],
896 _("ecdg_ti_font_dialog_other"));
898 gtk_widget_show_all(GTK_WIDGET(priv->notebook));
902 color_modified_cb(HildonColorButton *button,
906 HildonFontSelectionDialogPrivate *priv =
907 (HildonFontSelectionDialogPrivate *) fsd_priv;
909 priv->color_set = TRUE;
913 hildon_font_selection_dialog_finalize(GObject * object)
915 HildonFontSelectionDialogPrivate *priv;
916 HildonFontSelectionDialog *fontsel;
918 g_assert(HILDON_IS_FONT_SELECTION_DIALOG(object));
919 fontsel = HILDON_FONT_SELECTION_DIALOG(object);
921 priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fontsel);
923 g_free(priv->preview_text);
924 g_free(priv->families);
926 if (G_OBJECT_CLASS(font_selection_dialog_parent_class)->finalize)
927 G_OBJECT_CLASS(font_selection_dialog_parent_class)->finalize(object);
931 cmp_families(const void *a, const void *b)
934 pango_font_family_get_name(*(PangoFontFamily **) a);
936 pango_font_family_get_name(*(PangoFontFamily **) b);
938 return g_utf8_collate(a_name, b_name);
941 /* Exits the preview dialog with GTK_RESPONSE_CANCEL if Esc key
944 hildon_font_selection_dialog_preview_key_press(GtkWidget * widget,
951 if (event->keyval == GDK_Escape)
953 gtk_dialog_response(GTK_DIALOG(widget), GTK_RESPONSE_CANCEL);
961 add_preview_text_attr(PangoAttrList *list, PangoAttribute *attr,
962 guint start, guint len)
964 attr->start_index = start;
965 attr->end_index = start + len;
966 pango_attr_list_insert(list, attr);
969 static PangoAttrList*
970 hildon_font_selection_dialog_create_attrlist(HildonFontSelectionDialog *
971 fontsel, guint start_index, guint len)
974 PangoAttribute *attr;
976 gboolean family_set, size_set, color_set, bold, bold_set,
977 italic, italic_set, underline, underline_set,
978 strikethrough, strikethrough_set, position_set;
979 GdkColor *color = NULL;
980 gchar *family = NULL;
981 gdouble font_scaling = 1.0;
983 list = pango_attr_list_new();
985 g_object_get(G_OBJECT(fontsel),
986 "family", &family, "family-set", &family_set,
987 "size", &size, "size-set", &size_set,
988 "color", &color, "color-set", &color_set,
989 "bold", &bold, "bold-set", &bold_set,
990 "italic", &italic, "italic-set", &italic_set,
991 "underline", &underline, "underline-set", &underline_set,
992 "strikethrough", &strikethrough, "strikethrough-set",
993 &strikethrough_set, "position", &position,
994 "position-set", &position_set,
995 "font-scaling", &font_scaling,
1001 attr = pango_attr_family_new(family);
1002 add_preview_text_attr(list, attr, start_index, len);
1009 attr = pango_attr_size_new(size * PANGO_SCALE);
1010 add_preview_text_attr(list, attr, start_index, len);
1016 attr = pango_attr_foreground_new(color->red, color->green, color->blue);
1017 add_preview_text_attr(list, attr, start_index, len);
1021 gdk_color_free(color);
1027 attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD);
1029 attr = pango_attr_weight_new(PANGO_WEIGHT_NORMAL);
1031 add_preview_text_attr(list, attr, start_index, len);
1038 attr = pango_attr_style_new(PANGO_STYLE_ITALIC);
1040 attr = pango_attr_style_new(PANGO_STYLE_NORMAL);
1042 add_preview_text_attr(list, attr, start_index, len);
1049 attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
1051 attr = pango_attr_underline_new(PANGO_UNDERLINE_NONE);
1053 add_preview_text_attr(list, attr, start_index, len);
1057 if(strikethrough_set)
1060 attr = pango_attr_strikethrough_new(TRUE);
1062 attr = pango_attr_strikethrough_new(FALSE);
1064 add_preview_text_attr(list, attr, start_index, len);
1073 attr = pango_attr_rise_new(SUPERSCRIPT_RISE);
1076 attr = pango_attr_rise_new(SUBSCRIPT_LOW);
1079 attr = pango_attr_rise_new(0);
1083 add_preview_text_attr(list, attr, start_index, len);
1086 /*font scaling for preview*/
1089 attr = pango_attr_scale_new(font_scaling);
1090 add_preview_text_attr(list, attr, 0, len + start_index);
1097 hildon_font_selection_dialog_show_preview(HildonFontSelectionDialog *
1100 HildonFontSelectionDialogPrivate *priv =
1101 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fontsel);
1103 gboolean family_set, size_set;
1104 PangoAttribute *attr;
1105 PangoAttrList *list;
1106 GtkWidget *preview_dialog;
1107 GtkWidget *preview_label;
1109 gboolean position_set = FALSE;
1111 gboolean show_ref = FALSE;
1113 g_object_get(G_OBJECT(fontsel), "position-set", &position_set, NULL);
1115 g_object_get(G_OBJECT(fontsel), "position", &position, NULL);
1116 if (position == 1 || position == -1)
1120 /*Preview dialog init*/
1122 gtk_dialog_new_with_buttons(_("ecdg_ti_preview_font"), NULL,
1124 GTK_DIALOG_DESTROY_WITH_PARENT |
1125 GTK_DIALOG_NO_SEPARATOR,
1126 _("ecdg_bd_font_dialog_ok"),
1127 GTK_RESPONSE_ACCEPT,
1130 str = (show_ref) ? g_strconcat(_("ecdg_fi_preview_font_preview_reference"), priv->preview_text, 0) :
1131 g_strdup (priv->preview_text);
1133 preview_label = gtk_label_new(str);
1134 gtk_label_set_line_wrap(GTK_LABEL(preview_label), TRUE);
1139 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(preview_dialog)->vbox),
1143 /* set keypress handler (ESC hardkey) */
1144 g_signal_connect(G_OBJECT(preview_dialog), "key-press-event",
1145 G_CALLBACK(hildon_font_selection_dialog_preview_key_press),
1150 list = (show_ref) ? hildon_font_selection_dialog_create_attrlist(fontsel,
1151 strlen(_("ecdg_fi_preview_font_preview_reference")),
1152 strlen(priv->preview_text)) :
1153 hildon_font_selection_dialog_create_attrlist(fontsel,
1155 strlen(priv->preview_text));
1157 g_object_get(G_OBJECT(fontsel), "family", &str, "family-set",
1158 &family_set, "size", &size, "size-set", &size_set,
1160 /*make reference text to have the same fontface and size*/
1163 attr = pango_attr_family_new(str);
1164 add_preview_text_attr(list, attr, 0, strlen(_("ecdg_fi_preview_font_preview_reference")));
1171 attr = pango_attr_size_new(size * PANGO_SCALE);
1172 add_preview_text_attr(list, attr, 0, strlen(_("ecdg_fi_preview_font_preview_reference")));
1175 gtk_label_set_attributes(GTK_LABEL(preview_label), list);
1176 pango_attr_list_unref(list);
1178 /*And show the dialog*/
1179 gtk_window_set_transient_for(GTK_WINDOW(preview_dialog),
1180 GTK_WINDOW(fontsel));
1181 gtk_widget_show_all(preview_dialog);
1182 gtk_dialog_run(GTK_DIALOG(preview_dialog));
1183 gtk_widget_destroy(preview_dialog);
1187 static gboolean is_internal_font(const gchar * name){
1188 return strcmp(name, "DeviceSymbols") == 0
1189 || strcmp(name, "Nokia Smiley" ) == 0
1190 || strcmp(name, "NewCourier" ) == 0
1191 || strcmp(name, "NewTimes" ) == 0
1192 || strcmp(name, "SwissA" ) == 0
1193 || strcmp(name, "Nokia Sans" ) == 0
1194 || strcmp(name, "Nokia Sans Cn") == 0;
1197 static void filter_out_internal_fonts(PangoFontFamily **families, int *n_families){
1199 int n; /* counts valid fonts */
1200 const gchar * name = NULL;
1202 for(i = 0, n = 0; i < *n_families; i++){
1204 name = pango_font_family_get_name(families[i]);
1206 if(!is_internal_font(name)){
1208 if(i!=n){ /* there are filtered out families */
1209 families[n] = families[i]; /* shift the current family */
1212 n++; /* count one more valid */
1214 }/* foreach font family */
1221 hildon_font_selection_dialog_show_available_fonts(HildonFontSelectionDialog
1227 HildonFontSelectionDialogPrivate *priv =
1228 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fontsel);
1230 pango_context_list_families(gtk_widget_get_pango_context
1231 (GTK_WIDGET(fontsel)), &priv->families,
1234 filter_out_internal_fonts(priv->families, &priv->n_families);
1236 qsort(priv->families, priv->n_families, sizeof(PangoFontFamily *),
1240 for (i = 0; i < priv->n_families; i++)
1242 const gchar *name = pango_font_family_get_name(priv->families[i]);
1244 gtk_combo_box_append_text(GTK_COMBO_BOX(priv->cbx_font_type),
1251 hildon_font_selection_dialog_show_available_positionings
1252 (HildonFontSelectionDialogPrivate
1255 gtk_combo_box_append_text(GTK_COMBO_BOX(priv->cbx_positioning),
1256 _("ecdg_va_font_printpos_1"));
1257 gtk_combo_box_append_text(GTK_COMBO_BOX(priv->cbx_positioning),
1258 _("ecdg_va_font_printpos_2"));
1259 gtk_combo_box_append_text(GTK_COMBO_BOX(priv->cbx_positioning),
1260 _("ecdg_va_font_printpos_3"));
1263 /*Loads the sizes from a pre-allocated table*/
1265 hildon_font_selection_dialog_show_available_sizes
1266 (HildonFontSelectionDialogPrivate
1272 for (i = 0; i < G_N_ELEMENTS(font_sizes); i++)
1274 size_str = g_strdup_printf ("%i%s",
1276 _("ecdg_va_font_size_trailer"));
1278 gtk_combo_box_append_text(GTK_COMBO_BOX(priv->cbx_font_size),
1284 /* WARNING: This function is called only from deprecated API */
1286 void check_tags(gpointer data, gpointer user_data)
1289 GdkColor *fore_color = NULL;
1290 gint p_size, p_weight, p_style, p_underline, p_rise;
1291 gboolean b_st, ff_s, size_s, fgc_s, w_s, ss_s, u_s, sth_s, r_s;
1293 GtkTextTag *tag = (GtkTextTag*) data;
1294 HildonFontSelectionDialogSettings *settings =
1295 (HildonFontSelectionDialogSettings *) user_data;
1296 HildonFontSelectionDialogPrivate *priv =
1297 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(settings->fsd);
1299 /*get all the properties*/
1300 g_object_get(G_OBJECT(tag),
1301 "family", &font_family, "family-set", &ff_s,
1302 "size", &p_size, "size-set", &size_s,
1303 "foreground-gdk", &fore_color, "foreground-set", &fgc_s,
1304 "weight", &p_weight, "weight-set", &w_s,
1305 "style", &p_style, "style-set", &ss_s,
1306 "underline", &p_underline, "underline-set", &u_s,
1307 "strikethrough", &b_st, "strikethrough-set", &sth_s,
1308 "rise", &p_rise, "rise-set", & r_s,
1311 /* Check that the given values are valid.
1312 * If not, set the combobox row indicator to 'inconsistent' */
1318 for(i = 0; i < priv->n_families; i++)
1320 if(strcmp(font_family,
1321 pango_font_family_get_name(priv->families[i])) == 0)
1328 if(settings->family == -1)
1329 settings->family = new_f;
1330 else if(settings->family != -2 &&
1331 settings->family != new_f)
1332 settings->family = -2;/*inconsist*/
1334 g_free(font_family);
1342 for(i = 0; i < G_N_ELEMENTS(font_sizes); i++)
1344 if(p_size == font_sizes[i] * PANGO_SCALE)
1351 if(settings->size == -1)
1352 settings->size = new_size;
1353 else if(settings->size != -2 &&
1354 settings->size != new_size)
1355 settings->size = -2;/*inconsist*/
1358 if(fgc_s && settings->color == NULL
1359 && !settings->color_inconsist)
1360 settings->color = fore_color;
1361 else if(fore_color != NULL)
1363 if(!gdk_color_equal(fore_color, settings->color)
1365 settings->color_inconsist = TRUE;
1367 gdk_color_free(fore_color);
1371 settings->weight |= p_weight == PANGO_WEIGHT_NORMAL ? OFF_BIT : ON_BIT;
1374 settings->style |= p_style == PANGO_STYLE_NORMAL ? OFF_BIT : ON_BIT;
1377 settings->underline |=
1378 p_underline == PANGO_UNDERLINE_NONE ? OFF_BIT : ON_BIT;
1381 settings->strikethrough |= b_st ? ON_BIT : OFF_BIT;
1388 new_rs = 0;/*normal*/
1389 else if (p_rise > 0)
1390 new_rs = 1;/*super*/
1394 if(settings->position == -1)
1395 settings->position = new_rs;
1396 else if(settings->position != -2 &&
1397 settings->position != new_rs)
1398 settings->position = -2;/*inconsist*/
1402 /* WARNING: This function is called only from deprecated API */
1404 void check_attrs(gpointer data, gpointer user_data)
1406 PangoAttribute *attr = (PangoAttribute *) data;
1407 HildonFontSelectionDialogSettings *settings =
1408 (HildonFontSelectionDialogSettings *) user_data;
1409 HildonFontSelectionDialogPrivate *priv =
1410 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(settings->fsd);
1415 gint size, weight, style, underline, strikethrough, rise;
1416 gint new_f = -1, new_size = -1, new_rise = -1;
1418 /* Check that the given values are valid.
1419 * If not, set the combobox row indicator to 'inconsistent' */
1420 switch(attr->klass->type)
1422 case PANGO_ATTR_FAMILY:
1423 family = ((PangoAttrString *) attr)->value;
1425 for(i = 0; i < priv->n_families; i++)
1428 pango_font_family_get_name(priv->families[i])) == 0)
1435 if(settings->family == -1)
1436 settings->family = new_f;
1437 else if(settings->family != -2 &&
1438 settings->family != new_f)
1439 settings->family = -2;/*inconsist*/
1442 case PANGO_ATTR_SIZE:
1443 size = ((PangoAttrInt *) attr)->value;
1445 for(i = 0; i < G_N_ELEMENTS(font_sizes); i++)
1447 if(size == font_sizes[i] * PANGO_SCALE)
1454 if(settings->size == -1)
1455 settings->size = new_size;
1456 else if(settings->size != -2 &&
1457 settings->size != new_size)
1458 settings->size = -2;/*inconsist*/
1461 case PANGO_ATTR_FOREGROUND:
1462 color.red = ((PangoAttrColor *) attr)->color.red;
1463 color.green = ((PangoAttrColor *) attr)->color.green;
1464 color.blue = ((PangoAttrColor *) attr)->color.blue;
1466 if(!settings->color_inconsist && settings->color == NULL)
1467 settings->color = gdk_color_copy(&color);
1468 else if(settings->color != NULL &&
1469 !gdk_color_equal(&color, settings->color))
1470 settings->color_inconsist = TRUE;
1473 case PANGO_ATTR_WEIGHT:
1474 weight = ((PangoAttrInt *) attr)->value;
1476 settings->weight |= weight == PANGO_WEIGHT_NORMAL ? OFF_BIT : ON_BIT;
1479 case PANGO_ATTR_STYLE:
1480 style = ((PangoAttrInt *) attr)->value;
1482 settings->style |= style == PANGO_STYLE_NORMAL ? OFF_BIT : ON_BIT;
1485 case PANGO_ATTR_UNDERLINE:
1486 underline = ((PangoAttrInt *) attr)->value;
1488 settings->underline |=
1489 underline == PANGO_UNDERLINE_NONE ? OFF_BIT : ON_BIT;
1492 case PANGO_ATTR_STRIKETHROUGH:
1493 strikethrough = ((PangoAttrInt *) attr)->value;
1495 settings->strikethrough |= strikethrough ? ON_BIT : OFF_BIT;
1498 case PANGO_ATTR_RISE:
1499 rise = ((PangoAttrInt *) attr)->value;
1502 new_rise = 0;/*normal*/
1504 new_rise = 1;/*super*/
1506 new_rise = 2;/*sub*/
1508 if(settings->position == -1)
1509 settings->position = new_rise;
1510 else if(settings->position != -2 &&
1511 settings->position != new_rise)
1512 settings->position = -2;/*inconsist*/
1519 pango_attribute_destroy(attr);
1522 /* WARNING: This function is called only from deprecated API */
1524 settings_init(HildonFontSelectionDialogSettings *settings,
1525 HildonFontSelectionDialog *fsd)
1527 settings->fsd = fsd;
1528 settings->family = -1;
1529 settings->size = -1;
1530 settings->color = NULL;
1531 settings->color_inconsist = FALSE;
1532 settings->weight = 0;
1533 settings->style = 0;
1534 settings->underline = 0;
1535 settings->strikethrough = 0;
1536 settings->position = -1;
1539 /* WARNING: This function is called only from deprecated API */
1541 bit_mask_toggle(gint mask, GtkToggleButton *button,
1542 GObject *object, const gchar *prop,
1543 const gchar *prop_set)
1547 gtk_toggle_button_set_inconsistent(button, TRUE);
1550 gtk_toggle_button_set_inconsistent(button, FALSE);
1553 gtk_toggle_button_set_active(button, TRUE);
1555 gtk_toggle_button_set_active(button, FALSE);
1557 g_object_notify(object, prop);
1560 g_object_notify(object, prop_set);
1563 /* WARNING: This function is called only from deprecated API */
1565 combo_active(gint active, GtkComboBox *box,
1566 GObject *object, const gchar *prop, const gchar *prop_set)
1568 /*probaly not the best function, but we need all these
1569 * parameters to keep things together*/
1574 gtk_combo_box_set_active(box, active);
1575 g_object_notify(object, prop);
1578 gtk_combo_box_set_active(box, -1);
1580 g_object_notify(object, prop_set);
1583 /* WARNING: This function is called only from deprecated API */
1585 settings_apply(HildonFontSelectionDialogSettings *settings)
1588 HildonFontSelectionDialogPrivate *priv =
1589 HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(settings->fsd);
1592 combo_active(settings->family, GTK_COMBO_BOX(priv->cbx_font_type),
1593 G_OBJECT(settings->fsd), "family", "family-set");
1596 combo_active(settings->size, GTK_COMBO_BOX(priv->cbx_font_size),
1597 G_OBJECT(settings->fsd), "size", "size-set");
1599 /*block our signal handler indicating color has been changed by
1600 * the user before set the color, and unblock it after setting
1603 if(settings->color == NULL || settings->color_inconsist)
1607 black.red = black.green = black.blue = 0;
1608 g_signal_handler_block((gpointer) priv->font_color_button,
1609 priv->color_modified_signal_handler);
1611 g_object_set(G_OBJECT(settings->fsd), "color", &black, "color-set",
1614 g_signal_handler_unblock((gpointer) priv->font_color_button,
1615 priv->color_modified_signal_handler);
1618 g_object_set(G_OBJECT(settings->fsd), "color", settings->color, NULL);
1621 bit_mask_toggle(settings->weight, GTK_TOGGLE_BUTTON(priv->chk_bold),
1622 G_OBJECT(settings->fsd), "bold", "bold-set");
1625 bit_mask_toggle(settings->style, GTK_TOGGLE_BUTTON(priv->chk_italic),
1626 G_OBJECT(settings->fsd), "italic", "italic-set");
1629 bit_mask_toggle(settings->underline,
1630 GTK_TOGGLE_BUTTON(priv->chk_underline),
1631 G_OBJECT(settings->fsd), "underline", "underline-set");
1634 bit_mask_toggle(settings->strikethrough,
1635 GTK_TOGGLE_BUTTON(priv->chk_strikethrough),
1636 G_OBJECT(settings->fsd), "strikethrough",
1637 "strikethrough-set");
1640 combo_active(settings->position, GTK_COMBO_BOX(priv->cbx_positioning),
1641 G_OBJECT(settings->fsd), "position", "position-set");
1645 settings_destroy(HildonFontSelectionDialogSettings *settings)
1647 if(settings->color != NULL)
1648 gdk_color_free(settings->color);
1652 toggle_clicked(GtkButton *button, gpointer unused)
1654 GtkToggleButton *t_b = GTK_TOGGLE_BUTTON(button);
1656 /*we have to remove the inconsistent state ourselves*/
1657 if(gtk_toggle_button_get_inconsistent(t_b))
1659 gtk_toggle_button_set_inconsistent(t_b, FALSE);
1660 gtk_toggle_button_set_active(t_b, FALSE);
1664 /*******************/
1665 /*Public functions*/
1666 /*******************/
1669 * hildon_font_selection_dialog_new:
1670 * @parent: the parent window
1671 * @title: the title of font selection dialog
1673 * If NULL is passed for title, then default title
1674 * "Font" will be used.
1676 * Returns: a new #HildonFontSelectionDialog
1679 hildon_font_selection_dialog_new(GtkWindow * parent,
1680 const gchar * title)
1682 HildonFontSelectionDialog *fontseldiag;
1684 fontseldiag = g_object_new(HILDON_TYPE_FONT_SELECTION_DIALOG,
1685 "has-separator", FALSE, NULL);
1688 gtk_window_set_title(GTK_WINDOW(fontseldiag), title);
1691 gtk_window_set_transient_for(GTK_WINDOW(fontseldiag), parent);
1693 return GTK_WIDGET(fontseldiag);
1697 * hildon_font_selection_dialog_get_preview_text:
1698 * @fsd: the font selection dialog
1700 * Gets the text in preview dialog, which does not include the
1701 * reference text. The returned string must be freed by the user.
1703 * Returns: a string pointer
1706 hildon_font_selection_dialog_get_preview_text(HildonFontSelectionDialog * fsd)
1708 HildonFontSelectionDialogPrivate *priv;
1710 g_return_val_if_fail(HILDON_IS_FONT_SELECTION_DIALOG(fsd), FALSE);
1711 priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fsd);
1712 return g_strdup(priv->preview_text);
1716 * hildon_font_selection_dialog_set_preview_text:
1717 * @fsd: the font selection dialog
1718 * @text: the text to be displayed in the preview dialog
1720 * The default preview text is
1721 * "The quick brown fox jumped over the lazy dogs"
1724 hildon_font_selection_dialog_set_preview_text(HildonFontSelectionDialog *
1725 fsd, const gchar * text)
1727 HildonFontSelectionDialogPrivate *priv = NULL;
1729 g_return_if_fail(HILDON_IS_FONT_SELECTION_DIALOG(fsd));
1730 g_return_if_fail(text);
1732 priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fsd);
1734 g_free(priv->preview_text);
1735 priv->preview_text = g_strdup(text);
1736 g_object_notify (G_OBJECT (fsd), "preview-text");
1740 * hildon_font_selection_dialog_get_text_tag:
1741 * @fsd: the font selection dialog
1743 * Get the #GtkTextTag for selections. This function
1744 * is deprecated. The best way to use
1745 * the text tags is to reuse them as much as possible.
1746 * The recommended way is to get the properties of the font
1747 * selection dialog on GTK_RESPONSE_OK, and according to
1748 * these properties use the tags that you have pre-created.
1750 * Returns: a #GtkTextTag having corresponding properties
1754 hildon_font_selection_dialog_get_text_tag (HildonFontSelectionDialog *fsd)
1757 gint size, position;
1758 gboolean family_set, size_set, color_set, bold, bold_set,
1759 italic, italic_set, underline, underline_set,
1760 strikethrough, strikethrough_set, position_set;
1761 GdkColor *color = NULL;
1762 gchar *family = NULL;
1764 tag = gtk_text_tag_new(NULL);
1766 g_object_get(G_OBJECT(fsd),
1767 "family", &family, "family-set", &family_set,
1768 "size", &size, "size-set", &size_set,
1769 "color", &color, "color-set", &color_set,
1770 "bold", &bold, "bold-set", &bold_set,
1771 "italic", &italic, "italic-set", &italic_set,
1772 "underline", &underline, "underline-set", &underline_set,
1773 "strikethrough", &strikethrough, "strikethrough-set",
1774 &strikethrough_set, "position", &position,
1775 "position-set", &position_set, NULL);
1778 g_object_set(G_OBJECT(tag), "family",
1779 family, "family-set", TRUE, NULL);
1781 g_object_set(G_OBJECT(tag), "family-set", FALSE, NULL);
1787 g_object_set(G_OBJECT(tag), "size", size * PANGO_SCALE,
1788 "size-set", TRUE, NULL);
1790 g_object_set(G_OBJECT(tag), "size-set", FALSE, NULL);
1794 g_object_set(G_OBJECT(tag), "foreground-gdk", color,
1795 "foreground-set", TRUE ,NULL);
1797 g_object_set(G_OBJECT(tag), "foreground-set", FALSE, NULL);
1800 gdk_color_free(color);
1806 g_object_set(G_OBJECT(tag), "weight", PANGO_WEIGHT_BOLD, NULL);
1808 g_object_set(G_OBJECT(tag), "weight", PANGO_WEIGHT_NORMAL, NULL);
1810 g_object_set(G_OBJECT(tag), "weight-set", TRUE, NULL);
1813 g_object_set(G_OBJECT(tag), "weight-set", FALSE, NULL);
1819 g_object_set(G_OBJECT(tag), "style", PANGO_STYLE_ITALIC, NULL);
1821 g_object_set(G_OBJECT(tag), "style", PANGO_STYLE_NORMAL, NULL);
1823 g_object_set(G_OBJECT(tag), "style-set", TRUE, NULL);
1826 g_object_set(G_OBJECT(tag), "style-set", FALSE, NULL);
1832 g_object_set(G_OBJECT(tag), "underline", PANGO_UNDERLINE_SINGLE, NULL);
1834 g_object_set(G_OBJECT(tag), "underline", PANGO_UNDERLINE_NONE, NULL);
1836 g_object_set(G_OBJECT(tag), "underline-set", TRUE, NULL);
1839 g_object_set(G_OBJECT(tag), "underline-set", FALSE, NULL);
1842 if(strikethrough_set)
1845 g_object_set(G_OBJECT(tag), "strikethrough", TRUE, NULL);
1847 g_object_set(G_OBJECT(tag), "strikethrough", FALSE, NULL);
1849 g_object_set(G_OBJECT(tag), "strikethrough-set", TRUE, NULL);
1852 g_object_set(G_OBJECT(tag), "strikethrough-set", FALSE, NULL);
1860 g_object_set(G_OBJECT(tag), "rise", SUPERSCRIPT_RISE, NULL);
1863 g_object_set(G_OBJECT(tag), "rise", SUBSCRIPT_LOW, NULL);
1866 g_object_set(G_OBJECT(tag), "rise", 0, NULL);
1869 g_object_set(G_OBJECT(tag), "rise-set", TRUE, NULL);
1872 g_object_set(G_OBJECT(tag), "rise-set", FALSE, NULL);
1878 * hildon_font_selection_dialog_set_buffer:
1879 * @fsd: the font selection dialog
1880 * @buffer: a #GtkTextBuffer containing the text to which the selections will
1881 * be applied. Applying is responsibility of application.
1883 * This is deprecated. GtkTextBuffer is not enough
1884 * to get the attributes of currently selected text. Please
1885 * inspect the attributes yourself, and set the properties of
1886 * font selection dialog to reflect your inspection.
1889 hildon_font_selection_dialog_set_buffer (HildonFontSelectionDialog *fsd,
1890 GtkTextBuffer *buffer)
1892 GtkTextIter begin, end, iter;
1893 HildonFontSelectionDialogSettings settings;
1895 gtk_text_buffer_get_selection_bounds(buffer, &begin, &end);
1897 settings_init(&settings, fsd);
1901 /* Keep original settings if the selection includes nothing */
1902 if(gtk_text_iter_compare(&iter, &end) == 0)
1906 slist = gtk_text_iter_get_tags(&iter);
1907 g_slist_foreach(slist, check_tags, (gpointer) &settings);
1908 g_slist_free(slist);
1911 /* Apply the user settings to the selected text */
1912 while(gtk_text_iter_compare(&iter, &end) < 0)
1916 slist = gtk_text_iter_get_tags(&iter);
1917 g_slist_foreach(slist, check_tags, (gpointer) &settings);
1918 g_slist_free(slist);
1920 if(!gtk_text_iter_forward_cursor_position(&iter))
1924 settings_apply(&settings);
1925 settings_destroy(&settings);
1929 * hildon_font_selection_dialog_get_font:
1930 * @fsd: the font selection dialog
1932 * This is deprecated. @PangoAttrList needs
1933 * starting index, and end index on construction.
1935 * Returns: pointer to @PangoAttrList
1938 *hildon_font_selection_dialog_get_font(HildonFontSelectionDialog * fsd)
1940 HildonFontSelectionDialogPrivate *priv
1941 = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(fsd);
1943 g_return_val_if_fail(HILDON_IS_FONT_SELECTION_DIALOG(fsd), FALSE);
1944 /*an approve of none working api, should have ask for start_index,
1945 * and length in bytes of the string, currently using preview_text
1948 return hildon_font_selection_dialog_create_attrlist(fsd,
1949 0, strlen(priv->preview_text));
1953 * hildon_font_selection_dialog_set_font:
1954 * @fsd: the font selection dialog
1955 * @list: the pango attribute list
1957 * This is a deprecated.
1959 * Sets the font to the dialog.
1962 hildon_font_selection_dialog_set_font(HildonFontSelectionDialog * fsd,
1963 PangoAttrList * list)
1965 PangoAttrIterator *iter;
1966 HildonFontSelectionDialogSettings settings;
1968 iter = pango_attr_list_get_iterator(list);
1970 settings_init(&settings, fsd);
1976 slist = pango_attr_iterator_get_attrs(iter);
1977 g_slist_foreach(slist, check_attrs, (gpointer) &settings);
1978 g_slist_free(slist);
1980 if(!pango_attr_iterator_next(iter))
1984 pango_attr_iterator_destroy(iter);
1986 settings_apply(&settings);
1987 settings_destroy(&settings);