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"
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);
51 static guint item_signals[LAST_SIGNAL] = { 0 };
55 gtk_item_get_type (void)
57 static GType item_type = 0;
61 static const GTypeInfo item_info =
63 sizeof (GtkItemClass),
65 NULL, /* base_finalize */
66 (GClassInitFunc) gtk_item_class_init,
67 NULL, /* class_finalize */
68 NULL, /* class_data */
71 (GInstanceInitFunc) gtk_item_init,
72 NULL, /* value_table */
75 item_type = g_type_register_static (GTK_TYPE_BIN, I_("GtkItem"),
76 &item_info, G_TYPE_FLAG_ABSTRACT);
83 gtk_item_class_init (GtkItemClass *class)
85 GObjectClass *object_class;
86 GtkWidgetClass *widget_class;
88 object_class = (GObjectClass*) class;
89 widget_class = (GtkWidgetClass*) class;
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;
96 class->deselect = NULL;
99 item_signals[SELECT] =
100 g_signal_new (I_("select"),
101 G_OBJECT_CLASS_TYPE (object_class),
103 G_STRUCT_OFFSET (GtkItemClass, select),
105 _gtk_marshal_VOID__VOID,
107 item_signals[DESELECT] =
108 g_signal_new (I_("deselect"),
109 G_OBJECT_CLASS_TYPE (object_class),
111 G_STRUCT_OFFSET (GtkItemClass, deselect),
113 _gtk_marshal_VOID__VOID,
115 item_signals[TOGGLE] =
116 g_signal_new (I_("toggle"),
117 G_OBJECT_CLASS_TYPE (object_class),
119 G_STRUCT_OFFSET (GtkItemClass, toggle),
121 _gtk_marshal_VOID__VOID,
123 widget_class->activate_signal = item_signals[TOGGLE];
127 gtk_item_init (GtkItem *item)
129 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
133 gtk_item_select (GtkItem *item)
135 g_signal_emit (item, item_signals[SELECT], 0);
139 gtk_item_deselect (GtkItem *item)
141 g_signal_emit (item, item_signals[DESELECT], 0);
145 gtk_item_toggle (GtkItem *item)
147 g_signal_emit (item, item_signals[TOGGLE], 0);
152 gtk_item_realize (GtkWidget *widget)
154 GdkWindowAttr attributes;
155 gint attributes_mask;
157 g_return_if_fail (GTK_IS_ITEM (widget));
159 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
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) |
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);
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);
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);
187 gtk_item_enter (GtkWidget *widget,
188 GdkEventCrossing *event)
190 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
191 g_return_val_if_fail (event != NULL, FALSE);
193 return gtk_widget_event (widget->parent, (GdkEvent*) event);
197 gtk_item_leave (GtkWidget *widget,
198 GdkEventCrossing *event)
200 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
201 g_return_val_if_fail (event != NULL, FALSE);
203 return gtk_widget_event (widget->parent, (GdkEvent*) event);
206 #define __GTK_ITEM_C__
207 #include "gtkaliasdef.c"