]> git.sur5r.net Git - glabels/blob - glabels2/src/font-combo-menu-item.c
2009-09-22 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / font-combo-menu-item.c
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 /****************************************************************************/
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
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
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 *
116 gl_font_combo_menu_item_new (gchar *font_family)
117 {
118         glFontComboMenuItem *this;
119         GtkWidget           *hbox;
120         GtkWidget           *sample;
121         GtkWidget           *label;
122         gchar               *markup;
123
124         this = g_object_new (GL_TYPE_FONT_COMBO_MENU_ITEM, NULL);
125
126         this->priv->font_family = g_strdup (font_family);
127
128         hbox = gtk_hbox_new (FALSE, 6);
129         gtk_container_add (GTK_CONTAINER (this), hbox);
130
131         sample = gl_font_sample_new (SAMPLE_W, SAMPLE_H, "Aa", font_family);
132         gtk_box_pack_start (GTK_BOX (hbox), sample, FALSE, FALSE, 0);
133
134         label = gtk_label_new (font_family);
135         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
136
137         markup = g_strdup_printf ("<span font_family=\"%s\" size=\"x-large\">ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789</span>",
138                                   font_family);
139         gtk_widget_set_tooltip_markup (GTK_WIDGET (this), markup);
140         g_free (markup);
141
142         return GTK_WIDGET (this);
143 }
144
145
146 /*****************************************************************************/
147 /* Get family.                                                               */
148 /*****************************************************************************/
149 gchar *
150 gl_font_combo_menu_item_get_family (glFontComboMenuItem *this)
151 {
152         return g_strdup (this->priv->font_family);
153 }
154
155
156
157 /*
158  * Local Variables:       -- emacs
159  * mode: C                -- emacs
160  * c-basic-offset: 8      -- emacs
161  * tab-width: 8           -- emacs
162  * indent-tabs-mode: nil  -- emacs
163  * End:                   -- emacs
164  */