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/.
29 #include "gtkmarshalers.h"
41 static void gtk_item_class_init (GtkItemClass *klass);
42 static void gtk_item_init (GtkItem *item);
43 static void gtk_item_realize (GtkWidget *widget);
44 static gint gtk_item_enter (GtkWidget *widget,
45 GdkEventCrossing *event);
46 static gint gtk_item_leave (GtkWidget *widget,
47 GdkEventCrossing *event);
50 static guint item_signals[LAST_SIGNAL] = { 0 };
54 gtk_item_get_type (void)
56 static GType item_type = 0;
60 static const GTypeInfo item_info =
62 sizeof (GtkItemClass),
64 NULL, /* base_finalize */
65 (GClassInitFunc) gtk_item_class_init,
66 NULL, /* class_finalize */
67 NULL, /* class_data */
70 (GInstanceInitFunc) gtk_item_init,
71 NULL, /* value_table */
74 item_type = g_type_register_static (GTK_TYPE_BIN, "GtkItem",
75 &item_info, G_TYPE_FLAG_ABSTRACT);
82 gtk_item_class_init (GtkItemClass *class)
84 GObjectClass *object_class;
85 GtkWidgetClass *widget_class;
87 object_class = (GObjectClass*) class;
88 widget_class = (GtkWidgetClass*) class;
90 widget_class->realize = gtk_item_realize;
91 widget_class->enter_notify_event = gtk_item_enter;
92 widget_class->leave_notify_event = gtk_item_leave;
95 class->deselect = NULL;
98 item_signals[SELECT] =
99 g_signal_new ("select",
100 G_OBJECT_CLASS_TYPE (object_class),
102 G_STRUCT_OFFSET (GtkItemClass, select),
104 _gtk_marshal_VOID__VOID,
106 item_signals[DESELECT] =
107 g_signal_new ("deselect",
108 G_OBJECT_CLASS_TYPE (object_class),
110 G_STRUCT_OFFSET (GtkItemClass, deselect),
112 _gtk_marshal_VOID__VOID,
114 item_signals[TOGGLE] =
115 g_signal_new ("toggle",
116 G_OBJECT_CLASS_TYPE (object_class),
118 G_STRUCT_OFFSET (GtkItemClass, toggle),
120 _gtk_marshal_VOID__VOID,
122 widget_class->activate_signal = item_signals[TOGGLE];
126 gtk_item_init (GtkItem *item)
128 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
132 gtk_item_select (GtkItem *item)
134 g_signal_emit (item, item_signals[SELECT], 0);
138 gtk_item_deselect (GtkItem *item)
140 g_signal_emit (item, item_signals[DESELECT], 0);
144 gtk_item_toggle (GtkItem *item)
146 g_signal_emit (item, item_signals[TOGGLE], 0);
151 gtk_item_realize (GtkWidget *widget)
153 GdkWindowAttr attributes;
154 gint attributes_mask;
156 g_return_if_fail (GTK_IS_ITEM (widget));
158 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
160 attributes.x = widget->allocation.x;
161 attributes.y = widget->allocation.y;
162 attributes.width = widget->allocation.width;
163 attributes.height = widget->allocation.height;
164 attributes.window_type = GDK_WINDOW_CHILD;
165 attributes.wclass = GDK_INPUT_OUTPUT;
166 attributes.visual = gtk_widget_get_visual (widget);
167 attributes.colormap = gtk_widget_get_colormap (widget);
168 attributes.event_mask = (gtk_widget_get_events (widget) |
170 GDK_BUTTON_PRESS_MASK |
171 GDK_BUTTON_RELEASE_MASK |
172 GDK_ENTER_NOTIFY_MASK |
173 GDK_LEAVE_NOTIFY_MASK |
174 GDK_POINTER_MOTION_MASK);
176 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
177 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
178 gdk_window_set_user_data (widget->window, widget);
180 widget->style = gtk_style_attach (widget->style, widget->window);
181 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
182 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
186 gtk_item_enter (GtkWidget *widget,
187 GdkEventCrossing *event)
189 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
190 g_return_val_if_fail (event != NULL, FALSE);
192 return gtk_widget_event (widget->parent, (GdkEvent*) event);
196 gtk_item_leave (GtkWidget *widget,
197 GdkEventCrossing *event)
199 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
200 g_return_val_if_fail (event != NULL, FALSE);
202 return gtk_widget_event (widget->parent, (GdkEvent*) event);
205 #define __GTK_ITEM_C__
206 #include "gtkaliasdef.c"