]> Pileus Git - ~andy/gtk/blob - gtk/gtkitem.c
Revert name change
[~andy/gtk] / gtk / gtkitem.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28 #include "gtkitem.h"
29 #include "gtkmarshalers.h"
30 #include "gtkintl.h"
31 #include "gtkalias.h"
32
33
34 enum {
35   SELECT,
36   DESELECT,
37   TOGGLE,
38   LAST_SIGNAL
39 };
40
41
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);
47
48
49 static guint item_signals[LAST_SIGNAL] = { 0 };
50
51 G_DEFINE_ABSTRACT_TYPE (GtkItem, gtk_item, GTK_TYPE_BIN)
52
53 static void
54 gtk_item_class_init (GtkItemClass *class)
55 {
56   GObjectClass *object_class;
57   GtkWidgetClass *widget_class;
58
59   object_class = (GObjectClass*) class;
60   widget_class = (GtkWidgetClass*) class;
61
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;
65
66   class->select = NULL;
67   class->deselect = NULL;
68   class->toggle = NULL;
69
70   item_signals[SELECT] =
71     g_signal_new (I_("select"),
72                   G_OBJECT_CLASS_TYPE (object_class),
73                   G_SIGNAL_RUN_FIRST,
74                   G_STRUCT_OFFSET (GtkItemClass, select),
75                   NULL, NULL,
76                   _gtk_marshal_VOID__VOID,
77                   G_TYPE_NONE, 0);
78   item_signals[DESELECT] =
79     g_signal_new (I_("deselect"),
80                   G_OBJECT_CLASS_TYPE (object_class),
81                   G_SIGNAL_RUN_FIRST,
82                   G_STRUCT_OFFSET (GtkItemClass, deselect),
83                   NULL, NULL,
84                   _gtk_marshal_VOID__VOID,
85                   G_TYPE_NONE, 0);
86   item_signals[TOGGLE] =
87     g_signal_new (I_("toggle"),
88                   G_OBJECT_CLASS_TYPE (object_class),
89                   G_SIGNAL_RUN_FIRST,
90                   G_STRUCT_OFFSET (GtkItemClass, toggle),
91                   NULL, NULL,
92                   _gtk_marshal_VOID__VOID,
93                   G_TYPE_NONE, 0);
94   widget_class->activate_signal = item_signals[TOGGLE];
95 }
96
97 static void
98 gtk_item_init (GtkItem *item)
99 {
100   GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
101 }
102
103 void
104 gtk_item_select (GtkItem *item)
105 {
106   g_signal_emit (item, item_signals[SELECT], 0);
107 }
108
109 void
110 gtk_item_deselect (GtkItem *item)
111 {
112   g_signal_emit (item, item_signals[DESELECT], 0);
113 }
114
115 void
116 gtk_item_toggle (GtkItem *item)
117 {
118   g_signal_emit (item, item_signals[TOGGLE], 0);
119 }
120
121
122 static void
123 gtk_item_realize (GtkWidget *widget)
124 {
125   GdkWindowAttr attributes;
126   gint attributes_mask;
127
128   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
129
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) |
139                            GDK_EXPOSURE_MASK |
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);
145
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);
149
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);
153 }
154
155 static gint
156 gtk_item_enter (GtkWidget        *widget,
157                 GdkEventCrossing *event)
158 {
159   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
160   g_return_val_if_fail (event != NULL, FALSE);
161
162   return gtk_widget_event (widget->parent, (GdkEvent*) event);
163 }
164
165 static gint
166 gtk_item_leave (GtkWidget        *widget,
167                 GdkEventCrossing *event)
168 {
169   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
170   g_return_val_if_fail (event != NULL, FALSE);
171
172   return gtk_widget_event (widget->parent, (GdkEvent*) event);
173 }
174
175 #define __GTK_ITEM_C__
176 #include "gtkaliasdef.c"