2 * font-combo-menu-item.c
3 * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "font-combo-menu-item.h"
25 #include <glib/gi18n.h>
28 #include "font-sample.h"
33 /*===========================================*/
34 /* Private macros and constants. */
35 /*===========================================*/
41 /*===========================================*/
43 /*===========================================*/
45 struct _glFontComboMenuItemPrivate {
52 /*===========================================*/
54 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
61 static void gl_font_combo_menu_item_finalize (GObject *object);
64 /****************************************************************************/
65 /* Boilerplate Object stuff. */
66 /****************************************************************************/
67 G_DEFINE_TYPE (glFontComboMenuItem, gl_font_combo_menu_item, GTK_TYPE_MENU_ITEM)
70 /*****************************************************************************/
71 /* Class Init Function. */
72 /*****************************************************************************/
74 gl_font_combo_menu_item_class_init (glFontComboMenuItemClass *class)
76 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
78 gl_font_combo_menu_item_parent_class = g_type_class_peek_parent (class);
80 gobject_class->finalize = gl_font_combo_menu_item_finalize;
84 /*****************************************************************************/
85 /* Object Instance Init Function. */
86 /*****************************************************************************/
88 gl_font_combo_menu_item_init (glFontComboMenuItem *this)
90 this->priv = g_new0 (glFontComboMenuItemPrivate, 1);
94 /*****************************************************************************/
95 /* Finalize Method. */
96 /*****************************************************************************/
98 gl_font_combo_menu_item_finalize (GObject *object)
100 glFontComboMenuItem *this = GL_FONT_COMBO_MENU_ITEM (object);
102 g_return_if_fail (object != NULL);
103 g_return_if_fail (GL_IS_FONT_COMBO_MENU_ITEM (object));
105 g_free (this->priv->font_family);
108 G_OBJECT_CLASS (gl_font_combo_menu_item_parent_class)->finalize (object);
112 /*****************************************************************************/
113 /** New Object Generator. */
114 /*****************************************************************************/
116 gl_font_combo_menu_item_new (gchar *font_family)
118 glFontComboMenuItem *this;
122 PangoLanguage *language;
126 * Allow text samples to be localized.
128 * FIXME: if we could extract enough meta information from the fonts
129 * themselves, perhaps rather than setting these globally for the
130 * current locale, they could be unique to each font family.
132 const char *short_sample_text = C_("Short sample text", "Aa");
133 const char *lower_case_text = C_("Lower case sample text",
134 "abcdefghijklmnopqrstuvwxyz");
135 const char *upper_case_text = C_("Upper case sample text",
136 "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
137 const char *numbers_special_text = C_("Numbers and special characters sample text",
138 "0123456789 .:,;(*!?)");
139 const char *sample_text;
141 this = g_object_new (GL_TYPE_FONT_COMBO_MENU_ITEM, NULL);
143 this->priv->font_family = g_strdup (font_family);
145 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
146 gtk_container_add (GTK_CONTAINER (this), hbox);
148 sample = gl_font_sample_new (SAMPLE_W, SAMPLE_H, short_sample_text, font_family);
149 gtk_box_pack_start (GTK_BOX (hbox), sample, FALSE, FALSE, 0);
151 label = gtk_label_new (font_family);
152 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
154 language = pango_language_get_default ();
155 sample_text = pango_language_get_sample_string (language);
156 tip = g_strdup_printf ("%s:\n\n<span font_family=\"%s\" size=\"x-large\">%s\n%s\n%s\n\n%s</span>",
161 numbers_special_text,
163 gtk_widget_set_tooltip_markup (GTK_WIDGET (this), tip);
166 return GTK_WIDGET (this);
170 /*****************************************************************************/
172 /*****************************************************************************/
174 gl_font_combo_menu_item_get_family (glFontComboMenuItem *this)
176 return g_strdup (this->priv->font_family);
182 * Local Variables: -- emacs
184 * c-basic-offset: 8 -- emacs
185 * tab-width: 8 -- emacs
186 * indent-tabs-mode: nil -- emacs