]> git.sur5r.net Git - glabels/blob - src/color-combo-color-menu-item.c
Imported Upstream version 3.0.0
[glabels] / src / color-combo-color-menu-item.c
1 /*
2  *  color-combo-color-menu-item.c
3  *  Copyright (C) 2008  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 "color-combo-color-menu-item.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtk.h>
27
28 #include "color-swatch.h"
29 #include "color.h"
30 #include "marshal.h"
31
32
33
34 /*===========================================*/
35 /* Private macros and constants.             */
36 /*===========================================*/
37
38 #define SIZE 20
39
40
41 /*===========================================*/
42 /* Private types                             */
43 /*===========================================*/
44
45 struct _glColorComboColorMenuItemPrivate {
46
47         gint       id;
48
49         GtkWidget *swatch;
50 };
51
52
53 /*===========================================*/
54 /* Private globals                           */
55 /*===========================================*/
56
57
58 /*===========================================*/
59 /* Local function prototypes                 */
60 /*===========================================*/
61
62 static void gl_color_combo_color_menu_item_finalize    (GObject                *object);
63
64
65 /****************************************************************************/
66 /* Boilerplate Object stuff.                                                */
67 /****************************************************************************/
68 G_DEFINE_TYPE (glColorComboColorMenuItem, gl_color_combo_color_menu_item, GTK_TYPE_MENU_ITEM)
69
70
71 /*****************************************************************************/
72 /* Class Init Function.                                                      */
73 /*****************************************************************************/
74 static void
75 gl_color_combo_color_menu_item_class_init (glColorComboColorMenuItemClass *class)
76 {
77         GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
78
79         gl_color_combo_color_menu_item_parent_class = g_type_class_peek_parent (class);
80
81         gobject_class->finalize = gl_color_combo_color_menu_item_finalize;
82 }
83
84
85 /*****************************************************************************/
86 /* Object Instance Init Function.                                            */
87 /*****************************************************************************/
88 static void
89 gl_color_combo_color_menu_item_init (glColorComboColorMenuItem *this)
90 {
91         this->priv = g_new0 (glColorComboColorMenuItemPrivate, 1);
92 }
93
94
95 /*****************************************************************************/
96 /* Finalize Method.                                                          */
97 /*****************************************************************************/
98 static void
99 gl_color_combo_color_menu_item_finalize (GObject *object)
100 {
101         glColorComboColorMenuItem *this = GL_COLOR_COMBO_COLOR_MENU_ITEM (object);
102
103         g_return_if_fail (object != NULL);
104         g_return_if_fail (GL_IS_COLOR_COMBO_COLOR_MENU_ITEM (object));
105
106         g_free (this->priv);
107
108         G_OBJECT_CLASS (gl_color_combo_color_menu_item_parent_class)->finalize (object);
109 }
110
111
112 /*****************************************************************************/
113 /** New Object Generator.                                                    */
114 /*****************************************************************************/
115 GtkWidget *
116 gl_color_combo_color_menu_item_new (gint         id,
117                                     guint        color,
118                                     const gchar *tip)
119 {
120         glColorComboColorMenuItem *this;
121
122         this = g_object_new (GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM, NULL);
123
124         this->priv->id = id;
125
126         this->priv->swatch = gl_color_swatch_new (SIZE, SIZE, color);
127         gtk_container_add (GTK_CONTAINER (this), this->priv->swatch);
128
129         gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip);
130
131         return GTK_WIDGET (this);
132 }
133
134
135 /*****************************************************************************/
136 /* Set color.                                                                */
137 /*****************************************************************************/
138 void
139 gl_color_combo_color_menu_item_set_color(glColorComboColorMenuItem *this,
140                                          gint                       id,
141                                          guint                      color,
142                                          const gchar               *tip)
143 {
144         this->priv->id = id;
145
146         gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch), color);
147
148         gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip);
149 }
150
151
152 /*****************************************************************************/
153 /* Get id.                                                                   */
154 /*****************************************************************************/
155 gint
156 gl_color_combo_color_menu_item_get_id (glColorComboColorMenuItem *this)
157 {
158         return this->priv->id;
159 }
160
161
162
163 /*
164  * Local Variables:       -- emacs
165  * mode: C                -- emacs
166  * c-basic-offset: 8      -- emacs
167  * tab-width: 8           -- emacs
168  * indent-tabs-mode: nil  -- emacs
169  * End:                   -- emacs
170  */