1 /*
2 * font-combo-menu-item.c
3 * Copyright (C) 2009 Jim Evins <evins@snaught.com>.
4 *
5 * This file is part of gLabels.
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
21 #include <config.h>
22
23 #include "font-combo-menu-item.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27
28 #include "font-sample.h"
29 #include "marshal.h"
30
31
32
33 /*===========================================*/
34 /* Private macros and constants. */
35 /*===========================================*/
36
37 #define SAMPLE_W 32
38 #define SAMPLE_H 24
39
40
41 /*===========================================*/
42 /* Private types */
43 /*===========================================*/
44
45 struct _glFontComboMenuItemPrivate {
46
47 gchar *font_family;
48
49 };
50
51
52 /*===========================================*/
53 /* Private globals */
54 /*===========================================*/
55
56
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
60
61 static void gl_font_combo_menu_item_finalize (GObject *object);
62
63
64 /****************************************************************************/
65 /* Boilerplate Object stuff. */
66 /****************************************************************************/
G_DEFINE_TYPE(glFontComboMenuItem,gl_font_combo_menu_item,GTK_TYPE_MENU_ITEM)67 G_DEFINE_TYPE (glFontComboMenuItem, gl_font_combo_menu_item, GTK_TYPE_MENU_ITEM)
68
69
70 /*****************************************************************************/
71 /* Class Init Function. */
72 /*****************************************************************************/
73 static void
74 gl_font_combo_menu_item_class_init (glFontComboMenuItemClass *class)
75 {
76 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
77
78 gl_font_combo_menu_item_parent_class = g_type_class_peek_parent (class);
79
80 gobject_class->finalize = gl_font_combo_menu_item_finalize;
81 }
82
83
84 /*****************************************************************************/
85 /* Object Instance Init Function. */
86 /*****************************************************************************/
87 static void
gl_font_combo_menu_item_init(glFontComboMenuItem * this)88 gl_font_combo_menu_item_init (glFontComboMenuItem *this)
89 {
90 this->priv = g_new0 (glFontComboMenuItemPrivate, 1);
91 }
92
93
94 /*****************************************************************************/
95 /* Finalize Method. */
96 /*****************************************************************************/
97 static void
gl_font_combo_menu_item_finalize(GObject * object)98 gl_font_combo_menu_item_finalize (GObject *object)
99 {
100 glFontComboMenuItem *this = GL_FONT_COMBO_MENU_ITEM (object);
101
102 g_return_if_fail (object != NULL);
103 g_return_if_fail (GL_IS_FONT_COMBO_MENU_ITEM (object));
104
105 g_free (this->priv->font_family);
106 g_free (this->priv);
107
108 G_OBJECT_CLASS (gl_font_combo_menu_item_parent_class)->finalize (object);
109 }
110
111
112 /*****************************************************************************/
113 /** New Object Generator. */
114 /*****************************************************************************/
115 GtkWidget *
gl_font_combo_menu_item_new(gchar * font_family)116 gl_font_combo_menu_item_new (gchar *font_family)
117 {
118 glFontComboMenuItem *this;
119 GtkWidget *hbox;
120 GtkWidget *sample;
121 GtkWidget *label;
122 PangoLanguage *language;
123 gchar *tip;
124
125 /*
126 * Allow text samples to be localized.
127 *
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.
131 */
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;
140
141 this = g_object_new (GL_TYPE_FONT_COMBO_MENU_ITEM, NULL);
142
143 this->priv->font_family = g_strdup (font_family);
144
145 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
146 gtk_container_add (GTK_CONTAINER (this), hbox);
147
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);
150
151 label = gtk_label_new (font_family);
152 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
153
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>",
157 _("Sample text"),
158 font_family,
159 lower_case_text,
160 upper_case_text,
161 numbers_special_text,
162 sample_text);
163 gtk_widget_set_tooltip_markup (GTK_WIDGET (this), tip);
164 g_free (tip);
165
166 return GTK_WIDGET (this);
167 }
168
169
170 /*****************************************************************************/
171 /* Get family. */
172 /*****************************************************************************/
173 gchar *
gl_font_combo_menu_item_get_family(glFontComboMenuItem * this)174 gl_font_combo_menu_item_get_family (glFontComboMenuItem *this)
175 {
176 return g_strdup (this->priv->font_family);
177 }
178
179
180
181 /*
182 * Local Variables: -- emacs
183 * mode: C -- emacs
184 * c-basic-offset: 8 -- emacs
185 * tab-width: 8 -- emacs
186 * indent-tabs-mode: nil -- emacs
187 * End: -- emacs
188 */
189