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_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 };
51 G_DEFINE_ABSTRACT_TYPE (GtkItem, gtk_item, GTK_TYPE_BIN)
54 gtk_item_class_init (GtkItemClass *class)
56 GObjectClass *object_class;
57 GtkWidgetClass *widget_class;
59 object_class = (GObjectClass*) class;
60 widget_class = (GtkWidgetClass*) class;
62 widget_class->realize = gtk_item_realize;
63 widget_class->enter_notify_event = gtk_item_enter;
64 widget_class->leave_notify_event = gtk_item_leave;
67 class->deselect = NULL;
70 item_signals[SELECT] =
71 g_signal_new (I_("select"),
72 G_OBJECT_CLASS_TYPE (object_class),
74 G_STRUCT_OFFSET (GtkItemClass, select),
76 _gtk_marshal_VOID__VOID,
78 item_signals[DESELECT] =
79 g_signal_new (I_("deselect"),
80 G_OBJECT_CLASS_TYPE (object_class),
82 G_STRUCT_OFFSET (GtkItemClass, deselect),
84 _gtk_marshal_VOID__VOID,
86 item_signals[TOGGLE] =
87 g_signal_new (I_("toggle"),
88 G_OBJECT_CLASS_TYPE (object_class),
90 G_STRUCT_OFFSET (GtkItemClass, toggle),
92 _gtk_marshal_VOID__VOID,
94 widget_class->activate_signal = item_signals[TOGGLE];
98 gtk_item_init (GtkItem *item)
100 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
104 gtk_item_select (GtkItem *item)
106 g_signal_emit (item, item_signals[SELECT], 0);
110 gtk_item_deselect (GtkItem *item)
112 g_signal_emit (item, item_signals[DESELECT], 0);
116 gtk_item_toggle (GtkItem *item)
118 g_signal_emit (item, item_signals[TOGGLE], 0);
123 gtk_item_realize (GtkWidget *widget)
125 GdkWindowAttr attributes;
126 gint attributes_mask;
128 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
130 attributes.x = widget->allocation.x;
131 attributes.y = widget->allocation.y;
132 attributes.width = widget->allocation.width;
133 attributes.height = widget->allocation.height;
134 attributes.window_type = GDK_WINDOW_CHILD;
135 attributes.wclass = GDK_INPUT_OUTPUT;
136 attributes.visual = gtk_widget_get_visual (widget);
137 attributes.colormap = gtk_widget_get_colormap (widget);
138 attributes.event_mask = (gtk_widget_get_events (widget) |
140 GDK_BUTTON_PRESS_MASK |
141 GDK_BUTTON_RELEASE_MASK |
142 GDK_ENTER_NOTIFY_MASK |
143 GDK_LEAVE_NOTIFY_MASK |
144 GDK_POINTER_MOTION_MASK);
146 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
147 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
148 gdk_window_set_user_data (widget->window, widget);
150 widget->style = gtk_style_attach (widget->style, widget->window);
151 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
152 gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
156 gtk_item_enter (GtkWidget *widget,
157 GdkEventCrossing *event)
159 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
160 g_return_val_if_fail (event != NULL, FALSE);
162 return gtk_widget_event (widget->parent, (GdkEvent*) event);
166 gtk_item_leave (GtkWidget *widget,
167 GdkEventCrossing *event)
169 g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
170 g_return_val_if_fail (event != NULL, FALSE);
172 return gtk_widget_event (widget->parent, (GdkEvent*) event);
175 #define __GTK_ITEM_C__
176 #include "gtkaliasdef.c"