]> Pileus Git - ~andy/gtk/blob - gtk/gtkitem.c
Rename the variables for the color bitmap to have "color" in their name,
[~andy/gtk] / gtk / gtkitem.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include <config.h>
28 #include "gtkitem.h"
29 #include "gtkmarshalers.h"
30 #include "gtkintl.h"
31 #include "gtkalias.h"
32
33
34 enum {
35   SELECT,
36   DESELECT,
37   TOGGLE,
38   LAST_SIGNAL
39 };
40
41
42 static void gtk_item_class_init (GtkItemClass     *klass);
43 static void gtk_item_init       (GtkItem          *item);
44 static void gtk_item_realize    (GtkWidget        *widget);
45 static gint gtk_item_enter      (GtkWidget        *widget,
46                                  GdkEventCrossing *event);
47 static gint gtk_item_leave      (GtkWidget        *widget,
48                                  GdkEventCrossing *event);
49
50
51 static guint item_signals[LAST_SIGNAL] = { 0 };
52
53
54 GType
55 gtk_item_get_type (void)
56 {
57   static GType item_type = 0;
58
59   if (!item_type)
60     {
61       static const GTypeInfo item_info =
62       {
63         sizeof (GtkItemClass),
64         NULL,           /* base_init */
65         NULL,           /* base_finalize */
66         (GClassInitFunc) gtk_item_class_init,
67         NULL,           /* class_finalize */
68         NULL,           /* class_data */
69         sizeof (GtkItem),
70         0,              /* n_preallocs */
71         (GInstanceInitFunc) gtk_item_init,
72         NULL,           /* value_table */
73       };
74
75       item_type = g_type_register_static (GTK_TYPE_BIN, I_("GtkItem"),
76                                           &item_info, G_TYPE_FLAG_ABSTRACT);
77     }
78
79   return item_type;
80 }
81
82 static void
83 gtk_item_class_init (GtkItemClass *class)
84 {
85   GObjectClass *object_class;
86   GtkWidgetClass *widget_class;
87
88   object_class = (GObjectClass*) class;
89   widget_class = (GtkWidgetClass*) class;
90
91   widget_class->realize = gtk_item_realize;
92   widget_class->enter_notify_event = gtk_item_enter;
93   widget_class->leave_notify_event = gtk_item_leave;
94
95   class->select = NULL;
96   class->deselect = NULL;
97   class->toggle = NULL;
98
99   item_signals[SELECT] =
100     g_signal_new (I_("select"),
101                   G_OBJECT_CLASS_TYPE (object_class),
102                   G_SIGNAL_RUN_FIRST,
103                   G_STRUCT_OFFSET (GtkItemClass, select),
104                   NULL, NULL,
105                   _gtk_marshal_VOID__VOID,
106                   G_TYPE_NONE, 0);
107   item_signals[DESELECT] =
108     g_signal_new (I_("deselect"),
109                   G_OBJECT_CLASS_TYPE (object_class),
110                   G_SIGNAL_RUN_FIRST,
111                   G_STRUCT_OFFSET (GtkItemClass, deselect),
112                   NULL, NULL,
113                   _gtk_marshal_VOID__VOID,
114                   G_TYPE_NONE, 0);
115   item_signals[TOGGLE] =
116     g_signal_new (I_("toggle"),
117                   G_OBJECT_CLASS_TYPE (object_class),
118                   G_SIGNAL_RUN_FIRST,
119                   G_STRUCT_OFFSET (GtkItemClass, toggle),
120                   NULL, NULL,
121                   _gtk_marshal_VOID__VOID,
122                   G_TYPE_NONE, 0);
123   widget_class->activate_signal = item_signals[TOGGLE];
124 }
125
126 static void
127 gtk_item_init (GtkItem *item)
128 {
129   GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
130 }
131
132 void
133 gtk_item_select (GtkItem *item)
134 {
135   g_signal_emit (item, item_signals[SELECT], 0);
136 }
137
138 void
139 gtk_item_deselect (GtkItem *item)
140 {
141   g_signal_emit (item, item_signals[DESELECT], 0);
142 }
143
144 void
145 gtk_item_toggle (GtkItem *item)
146 {
147   g_signal_emit (item, item_signals[TOGGLE], 0);
148 }
149
150
151 static void
152 gtk_item_realize (GtkWidget *widget)
153 {
154   GdkWindowAttr attributes;
155   gint attributes_mask;
156
157   g_return_if_fail (GTK_IS_ITEM (widget));
158
159   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
160
161   attributes.x = widget->allocation.x;
162   attributes.y = widget->allocation.y;
163   attributes.width = widget->allocation.width;
164   attributes.height = widget->allocation.height;
165   attributes.window_type = GDK_WINDOW_CHILD;
166   attributes.wclass = GDK_INPUT_OUTPUT;
167   attributes.visual = gtk_widget_get_visual (widget);
168   attributes.colormap = gtk_widget_get_colormap (widget);
169   attributes.event_mask = (gtk_widget_get_events (widget) |
170                            GDK_EXPOSURE_MASK |
171                            GDK_BUTTON_PRESS_MASK |
172                            GDK_BUTTON_RELEASE_MASK |
173                            GDK_ENTER_NOTIFY_MASK |
174                            GDK_LEAVE_NOTIFY_MASK |
175                            GDK_POINTER_MOTION_MASK);
176
177   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
178   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
179   gdk_window_set_user_data (widget->window, widget);
180
181   widget->style = gtk_style_attach (widget->style, widget->window);
182   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
183   gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
184 }
185
186 static gint
187 gtk_item_enter (GtkWidget        *widget,
188                 GdkEventCrossing *event)
189 {
190   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
191   g_return_val_if_fail (event != NULL, FALSE);
192
193   return gtk_widget_event (widget->parent, (GdkEvent*) event);
194 }
195
196 static gint
197 gtk_item_leave (GtkWidget        *widget,
198                 GdkEventCrossing *event)
199 {
200   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
201   g_return_val_if_fail (event != NULL, FALSE);
202
203   return gtk_widget_event (widget->parent, (GdkEvent*) event);
204 }
205
206 #define __GTK_ITEM_C__
207 #include "gtkaliasdef.c"