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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "gtksignal.h"
30 static void gtk_item_class_init (GtkItemClass *klass);
31 static void gtk_item_init (GtkItem *item);
32 static void gtk_item_map (GtkWidget *widget);
33 static void gtk_item_unmap (GtkWidget *widget);
34 static void gtk_item_realize (GtkWidget *widget);
37 static gint item_signals[LAST_SIGNAL] = { 0 };
43 static guint item_type = 0;
47 GtkTypeInfo item_info =
51 sizeof (GtkItemClass),
52 (GtkClassInitFunc) gtk_item_class_init,
53 (GtkObjectInitFunc) gtk_item_init,
57 item_type = gtk_type_unique (gtk_bin_get_type (), &item_info);
64 gtk_item_class_init (GtkItemClass *class)
66 GtkObjectClass *object_class;
67 GtkWidgetClass *widget_class;
69 object_class = (GtkObjectClass*) class;
70 widget_class = (GtkWidgetClass*) class;
72 item_signals[SELECT] =
73 gtk_signal_new ("select",
76 GTK_SIGNAL_OFFSET (GtkItemClass, select),
77 gtk_signal_default_marshaller,
79 item_signals[DESELECT] =
80 gtk_signal_new ("deselect",
83 GTK_SIGNAL_OFFSET (GtkItemClass, deselect),
84 gtk_signal_default_marshaller,
86 item_signals[TOGGLE] =
87 gtk_signal_new ("toggle",
90 GTK_SIGNAL_OFFSET (GtkItemClass, toggle),
91 gtk_signal_default_marshaller,
94 gtk_object_class_add_signals (object_class, item_signals, LAST_SIGNAL);
96 widget_class->activate_signal = item_signals[TOGGLE];
97 widget_class->map = gtk_item_map;
98 widget_class->unmap = gtk_item_unmap;
99 widget_class->realize = gtk_item_realize;
101 class->select = NULL;
102 class->deselect = NULL;
103 class->toggle = NULL;
107 gtk_item_init (GtkItem *item)
109 GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
113 gtk_item_select (GtkItem *item)
115 gtk_signal_emit (GTK_OBJECT (item), item_signals[SELECT]);
119 gtk_item_deselect (GtkItem *item)
121 gtk_signal_emit (GTK_OBJECT (item), item_signals[DESELECT]);
125 gtk_item_toggle (GtkItem *item)
127 gtk_signal_emit (GTK_OBJECT (item), item_signals[TOGGLE]);
132 gtk_item_map (GtkWidget *widget)
136 g_return_if_fail (widget != NULL);
137 g_return_if_fail (GTK_IS_ITEM (widget));
139 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
140 gdk_window_show (widget->window);
142 bin = GTK_BIN (widget);
145 GTK_WIDGET_VISIBLE (bin->child) &&
146 !GTK_WIDGET_MAPPED (bin->child))
147 gtk_widget_map (bin->child);
151 gtk_item_unmap (GtkWidget *widget)
153 g_return_if_fail (widget != NULL);
154 g_return_if_fail (GTK_IS_ITEM (widget));
156 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
157 gdk_window_hide (widget->window);
161 gtk_item_realize (GtkWidget *widget)
163 GdkWindowAttr attributes;
164 gint attributes_mask;
166 g_return_if_fail (widget != NULL);
167 g_return_if_fail (GTK_IS_ITEM (widget));
169 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
171 attributes.x = widget->allocation.x;
172 attributes.y = widget->allocation.y;
173 attributes.width = widget->allocation.width;
174 attributes.height = widget->allocation.height;
175 attributes.window_type = GDK_WINDOW_CHILD;
176 attributes.wclass = GDK_INPUT_OUTPUT;
177 attributes.visual = gtk_widget_get_visual (widget);
178 attributes.colormap = gtk_widget_get_colormap (widget);
179 attributes.event_mask = (GDK_EXPOSURE_MASK |
180 GDK_BUTTON_PRESS_MASK |
181 GDK_BUTTON_RELEASE_MASK |
182 GDK_ENTER_NOTIFY_MASK |
183 GDK_LEAVE_NOTIFY_MASK);
185 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
186 widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
187 gdk_window_set_user_data (widget->window, widget);
189 widget->style = gtk_style_attach (widget->style, widget->window);
190 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);