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_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 };
50 G_DEFINE_ABSTRACT_TYPE (GtkItem, gtk_item, GTK_TYPE_BIN)
53 gtk_item_class_init (GtkItemClass *class)
55 GObjectClass *object_class;
56 GtkWidgetClass *widget_class;
58 object_class = (GObjectClass*) class;
59 widget_class = (GtkWidgetClass*) class;
61 widget_class->realize = gtk_item_realize;
62 widget_class->enter_notify_event = gtk_item_enter;
63 widget_class->leave_notify_event = gtk_item_leave;
66 class->deselect = NULL;
69 item_signals[SELECT] =
70 g_signal_new (I_("select"),
71 G_OBJECT_CLASS_TYPE (object_class),
73 G_STRUCT_OFFSET (GtkItemClass, select),
75 _gtk_marshal_VOID__VOID,
77 item_signals[DESELECT] =
78 g_signal_new (I_("deselect"),
79 G_OBJECT_CLASS_TYPE (object_class),
81 G_STRUCT_OFFSET (GtkItemClass, deselect),
83 _gtk_marshal_VOID__VOID,
85 item_signals[TOGGLE] =
86 g_signal_new (I_("toggle"),
87 G_OBJECT_CLASS_TYPE (object_class),
89 G_STRUCT_OFFSET (GtkItemClass, toggle),
91 _gtk_marshal_VOID__VOID,
93 widget_class->activate_signal = item_signals[TOGGLE];
97 gtk_item_init (GtkItem *item)
99 gtk_widget_set_has_window (GTK_WIDGET (item), TRUE);
103 gtk_item_select (GtkItem *item)
105 g_signal_emit (item, item_signals[SELECT], 0);
109 gtk_item_deselect (GtkItem *item)
111 g_signal_emit (item, item_signals[DESELECT], 0);
115 gtk_item_toggle (GtkItem *item)
117 g_signal_emit (item, item_signals[TOGGLE], 0);
122 gtk_item_realize (GtkWidget *widget)
124 GdkWindowAttr attributes;
125 gint attributes_mask;
127 gtk_widget_set_realized (widget, TRUE);
129 attributes.x = widget->allocation.x;
130 attributes.y = widget->allocation.y;
131 attributes.width = widget->allocation.width;
132 attributes.height = widget->allocation.height;
133 attributes.window_type = GDK_WINDOW_CHILD;
134 attributes.wclass = GDK_INPUT_OUTPUT;
135 attributes.visual = gtk_widget_get_visual (widget);
136 attributes.colormap = gtk_widget_get_colormap (widget);
137 attributes.event_mask = (gtk_widget_get_events (widget) |
139 GDK_BUTTON_PRESS_MASK |
140 GDK_BUTTON_RELEASE_MASK |
141 GDK_ENTER_NOTIFY_MASK |
142 GDK_LEAVE_NOTIFY_MASK |
143 GDK_POINTER_MOTION_MASK);
145 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
146 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
147 gdk_window_set_user_data (widget->window, widget);
149 widget->style = gtk_style_attach (widget->style, widget->window);
150 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
151 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
155 gtk_item_enter (GtkWidget *widget,
156 GdkEventCrossing *event)
158 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
159 g_return_val_if_fail (event != NULL, FALSE);
161 return gtk_widget_event (widget->parent, (GdkEvent*) event);
165 gtk_item_leave (GtkWidget *widget,
166 GdkEventCrossing *event)
168 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
169 g_return_val_if_fail (event != NULL, FALSE);
171 return gtk_widget_event (widget->parent, (GdkEvent*) event);