]> git.sur5r.net Git - glabels/blob - glabels2/src/font-combo-menu-item.c
2009-09-08 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 "font-sample.h"
26 #include "marshal.h"
27 #include <glib/gi18n.h>
28 #include <gtk/gtkmenuitem.h>
29 #include <gtk/gtkseparatormenuitem.h>
30 #include <gtk/gtkhbox.h>
31 #include <gtk/gtklabel.h>
32
33
34
35 /*===========================================*/
36 /* Private macros and constants.             */
37 /*===========================================*/
38
39 #define SAMPLE_W 32
40 #define SAMPLE_H 24
41
42
43 /*===========================================*/
44 /* Private types                             */
45 /*===========================================*/
46
47 struct _glFontComboMenuItemPrivate {
48
49         gchar *font_family;
50
51 };
52
53
54 /*===========================================*/
55 /* Private globals                           */
56 /*===========================================*/
57
58
59 /*===========================================*/
60 /* Local function prototypes                 */
61 /*===========================================*/
62
63 static void gl_font_combo_menu_item_finalize    (GObject                *object);
64
65
66 /****************************************************************************/
67 /* Boilerplate Object stuff.                                                */
68 /****************************************************************************/
69 G_DEFINE_TYPE (glFontComboMenuItem, gl_font_combo_menu_item, GTK_TYPE_MENU_ITEM);
70
71
72 /*****************************************************************************/
73 /* Class Init Function.                                                      */
74 /*****************************************************************************/
75 static void
76 gl_font_combo_menu_item_class_init (glFontComboMenuItemClass *class)
77 {
78         GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
79
80         gl_font_combo_menu_item_parent_class = g_type_class_peek_parent (class);
81
82         gobject_class->finalize = gl_font_combo_menu_item_finalize;
83 }
84
85
86 /*****************************************************************************/
87 /* Object Instance Init Function.                                            */
88 /*****************************************************************************/
89 static void
90 gl_font_combo_menu_item_init (glFontComboMenuItem *this)
91 {
92         this->priv = g_new0 (glFontComboMenuItemPrivate, 1);
93 }
94
95
96 /*****************************************************************************/
97 /* Finalize Method.                                                          */
98 /*****************************************************************************/
99 static void
100 gl_font_combo_menu_item_finalize (GObject *object)
101 {
102         glFontComboMenuItem *this = GL_FONT_COMBO_MENU_ITEM (object);
103
104         g_return_if_fail (object != NULL);
105         g_return_if_fail (GL_IS_FONT_COMBO_MENU_ITEM (object));
106
107         g_free (this->priv->font_family);
108         g_free (this->priv);
109
110         G_OBJECT_CLASS (gl_font_combo_menu_item_parent_class)->finalize (object);
111 }
112
113
114 /*****************************************************************************/
115 /** New Object Generator.                                                    */
116 /*****************************************************************************/
117 GtkWidget *
118 gl_font_combo_menu_item_new (gchar *font_family)
119 {
120         glFontComboMenuItem *this;
121         GtkWidget           *hbox;
122         GtkWidget           *sample;
123         GtkWidget           *label;
124         gchar               *markup;
125
126         this = g_object_new (GL_TYPE_FONT_COMBO_MENU_ITEM, NULL);
127
128         this->priv->font_family = g_strdup (font_family);
129
130         hbox = gtk_hbox_new (FALSE, 6);
131         gtk_container_add (GTK_CONTAINER (this), hbox);
132
133         sample = gl_font_sample_new (SAMPLE_W, SAMPLE_H, "Aa", font_family);
134         gtk_box_pack_start (GTK_BOX (hbox), sample, FALSE, FALSE, 0);
135
136         label = gtk_label_new (font_family);
137         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
138
139         markup = g_strdup_printf ("<span font_family=\"%s\" size=\"x-large\">ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789</span>",
140                                   font_family);
141         gtk_widget_set_tooltip_markup (GTK_WIDGET (this), markup);
142         g_free (markup);
143
144         return GTK_WIDGET (this);
145 }
146
147
148 /*****************************************************************************/
149 /* Get family.                                                               */
150 /*****************************************************************************/
151 gchar *
152 gl_font_combo_menu_item_get_family (glFontComboMenuItem *this)
153 {
154         return g_strdup (this->priv->font_family);
155 }
156
157
158
159 /*
160  * Local Variables:       -- emacs
161  * mode: C                -- emacs
162  * c-basic-offset: 8      -- emacs
163  * tab-width: 8           -- emacs
164  * indent-tabs-mode: nil  -- emacs
165  * End:                   -- emacs
166  */