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"
29 #include "gtksignal.h"
40 static void gtk_item_class_init (GtkItemClass *klass);
41 static void gtk_item_init (GtkItem *item);
42 static void gtk_item_realize (GtkWidget *widget);
43 static gint gtk_item_enter (GtkWidget *widget,
44 GdkEventCrossing *event);
45 static gint gtk_item_leave (GtkWidget *widget,
46 GdkEventCrossing *event);
49 static guint item_signals[LAST_SIGNAL] = { 0 };
53 gtk_item_get_type (void)
55 static GtkType item_type = 0;
59 static const GtkTypeInfo item_info =
63 sizeof (GtkItemClass),
64 (GtkClassInitFunc) gtk_item_class_init,
65 (GtkObjectInitFunc) gtk_item_init,
66 /* reserved_1 */ NULL,
67 /* reserved_2 */ NULL,
68 (GtkClassInitFunc) NULL,
71 item_type = gtk_type_unique (GTK_TYPE_BIN, &item_info);
78 gtk_item_class_init (GtkItemClass *class)
80 GtkObjectClass *object_class;
81 GtkWidgetClass *widget_class;
83 object_class = (GtkObjectClass*) class;
84 widget_class = (GtkWidgetClass*) class;
87 widget_class->realize = gtk_item_realize;
88 widget_class->enter_notify_event = gtk_item_enter;
89 widget_class->leave_notify_event = gtk_item_leave;
92 class->deselect = NULL;
95 item_signals[SELECT] =
96 gtk_signal_new ("select",
98 GTK_CLASS_TYPE (object_class),
99 GTK_SIGNAL_OFFSET (GtkItemClass, select),
100 _gtk_marshal_VOID__VOID,
102 item_signals[DESELECT] =
103 gtk_signal_new ("deselect",
105 GTK_CLASS_TYPE (object_class),
106 GTK_SIGNAL_OFFSET (GtkItemClass, deselect),
107 _gtk_marshal_VOID__VOID,
109 item_signals[TOGGLE] =
110 gtk_signal_new ("toggle",
112 GTK_CLASS_TYPE (object_class),
113 GTK_SIGNAL_OFFSET (GtkItemClass, toggle),
114 _gtk_marshal_VOID__VOID,
116 widget_class->activate_signal = item_signals[TOGGLE];
120 gtk_item_init (GtkItem *item)
122 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
126 gtk_item_select (GtkItem *item)
128 gtk_signal_emit (GTK_OBJECT (item), item_signals[SELECT]);
132 gtk_item_deselect (GtkItem *item)
134 gtk_signal_emit (GTK_OBJECT (item), item_signals[DESELECT]);
138 gtk_item_toggle (GtkItem *item)
140 gtk_signal_emit (GTK_OBJECT (item), item_signals[TOGGLE]);
145 gtk_item_realize (GtkWidget *widget)
147 GdkWindowAttr attributes;
148 gint attributes_mask;
150 g_return_if_fail (GTK_IS_ITEM (widget));
152 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
154 attributes.x = widget->allocation.x;
155 attributes.y = widget->allocation.y;
156 attributes.width = widget->allocation.width;
157 attributes.height = widget->allocation.height;
158 attributes.window_type = GDK_WINDOW_CHILD;
159 attributes.wclass = GDK_INPUT_OUTPUT;
160 attributes.visual = gtk_widget_get_visual (widget);
161 attributes.colormap = gtk_widget_get_colormap (widget);
162 attributes.event_mask = (gtk_widget_get_events (widget) |
164 GDK_BUTTON_PRESS_MASK |
165 GDK_BUTTON_RELEASE_MASK |
166 GDK_ENTER_NOTIFY_MASK |
167 GDK_LEAVE_NOTIFY_MASK |
168 GDK_POINTER_MOTION_MASK);
170 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
171 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
172 gdk_window_set_user_data (widget->window, widget);
174 widget->style = gtk_style_attach (widget->style, widget->window);
175 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
176 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
180 gtk_item_enter (GtkWidget *widget,
181 GdkEventCrossing *event)
183 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
184 g_return_val_if_fail (event != NULL, FALSE);
186 return gtk_widget_event (widget->parent, (GdkEvent*) event);
190 gtk_item_leave (GtkWidget *widget,
191 GdkEventCrossing *event)
193 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
194 g_return_val_if_fail (event != NULL, FALSE);
196 return gtk_widget_event (widget->parent, (GdkEvent*) event);