1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
28 #include "gtkmarshalers.h"
39 static void gtk_item_class_init (GtkItemClass *klass);
40 static void gtk_item_init (GtkItem *item);
41 static void gtk_item_realize (GtkWidget *widget);
42 static gint gtk_item_enter (GtkWidget *widget,
43 GdkEventCrossing *event);
44 static gint gtk_item_leave (GtkWidget *widget,
45 GdkEventCrossing *event);
48 static guint item_signals[LAST_SIGNAL] = { 0 };
52 gtk_item_get_type (void)
54 static GType item_type = 0;
58 static const GTypeInfo item_info =
60 sizeof (GtkItemClass),
62 NULL, /* base_finalize */
63 (GClassInitFunc) gtk_item_class_init,
64 NULL, /* class_finalize */
65 NULL, /* class_data */
68 (GInstanceInitFunc) gtk_item_init,
69 NULL, /* value_table */
72 item_type = g_type_register_static (GTK_TYPE_BIN, "GtkItem",
73 &item_info, G_TYPE_FLAG_ABSTRACT);
80 gtk_item_class_init (GtkItemClass *class)
82 GObjectClass *object_class;
83 GtkWidgetClass *widget_class;
85 object_class = (GObjectClass*) class;
86 widget_class = (GtkWidgetClass*) class;
88 widget_class->realize = gtk_item_realize;
89 widget_class->enter_notify_event = gtk_item_enter;
90 widget_class->leave_notify_event = gtk_item_leave;
93 class->deselect = NULL;
96 item_signals[SELECT] =
97 g_signal_new ("select",
98 G_OBJECT_CLASS_TYPE (object_class),
100 G_STRUCT_OFFSET (GtkItemClass, select),
102 _gtk_marshal_VOID__VOID,
104 item_signals[DESELECT] =
105 g_signal_new ("deselect",
106 G_OBJECT_CLASS_TYPE (object_class),
108 G_STRUCT_OFFSET (GtkItemClass, deselect),
110 _gtk_marshal_VOID__VOID,
112 item_signals[TOGGLE] =
113 g_signal_new ("toggle",
114 G_OBJECT_CLASS_TYPE (object_class),
116 G_STRUCT_OFFSET (GtkItemClass, toggle),
118 _gtk_marshal_VOID__VOID,
120 widget_class->activate_signal = item_signals[TOGGLE];
124 gtk_item_init (GtkItem *item)
126 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
130 gtk_item_select (GtkItem *item)
132 g_signal_emit (item, item_signals[SELECT], 0);
136 gtk_item_deselect (GtkItem *item)
138 g_signal_emit (item, item_signals[DESELECT], 0);
142 gtk_item_toggle (GtkItem *item)
144 g_signal_emit (item, item_signals[TOGGLE], 0);
149 gtk_item_realize (GtkWidget *widget)
151 GdkWindowAttr attributes;
152 gint attributes_mask;
154 g_return_if_fail (GTK_IS_ITEM (widget));
156 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
158 attributes.x = widget->allocation.x;
159 attributes.y = widget->allocation.y;
160 attributes.width = widget->allocation.width;
161 attributes.height = widget->allocation.height;
162 attributes.window_type = GDK_WINDOW_CHILD;
163 attributes.wclass = GDK_INPUT_OUTPUT;
164 attributes.visual = gtk_widget_get_visual (widget);
165 attributes.colormap = gtk_widget_get_colormap (widget);
166 attributes.event_mask = (gtk_widget_get_events (widget) |
168 GDK_BUTTON_PRESS_MASK |
169 GDK_BUTTON_RELEASE_MASK |
170 GDK_ENTER_NOTIFY_MASK |
171 GDK_LEAVE_NOTIFY_MASK |
172 GDK_POINTER_MOTION_MASK);
174 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
175 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
176 gdk_window_set_user_data (widget->window, widget);
178 widget->style = gtk_style_attach (widget->style, widget->window);
179 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
180 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
184 gtk_item_enter (GtkWidget *widget,
185 GdkEventCrossing *event)
187 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
188 g_return_val_if_fail (event != NULL, FALSE);
190 return gtk_widget_event (widget->parent, (GdkEvent*) event);
194 gtk_item_leave (GtkWidget *widget,
195 GdkEventCrossing *event)
197 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
198 g_return_val_if_fail (event != NULL, FALSE);
200 return gtk_widget_event (widget->parent, (GdkEvent*) event);