]> Pileus Git - ~andy/gtk/blob - gtk/gtkitem.c
Replace homegrown "nbsp", "hash" and "percent" entities by standard ISO
[~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 "gtkitem.h"
28 #include "gtkmarshalers.h"
29 #include "gtksignal.h"
30
31
32 enum {
33   SELECT,
34   DESELECT,
35   TOGGLE,
36   LAST_SIGNAL
37 };
38
39
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);
47
48
49 static guint item_signals[LAST_SIGNAL] = { 0 };
50
51
52 GtkType
53 gtk_item_get_type (void)
54 {
55   static GtkType item_type = 0;
56
57   if (!item_type)
58     {
59       static const GtkTypeInfo item_info =
60       {
61         "GtkItem",
62         sizeof (GtkItem),
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,
69       };
70
71       item_type = gtk_type_unique (GTK_TYPE_BIN, &item_info);
72     }
73
74   return item_type;
75 }
76
77 static void
78 gtk_item_class_init (GtkItemClass *class)
79 {
80   GtkObjectClass *object_class;
81   GtkWidgetClass *widget_class;
82
83   object_class = (GtkObjectClass*) class;
84   widget_class = (GtkWidgetClass*) class;
85
86
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;
90
91   class->select = NULL;
92   class->deselect = NULL;
93   class->toggle = NULL;
94
95   item_signals[SELECT] =
96     gtk_signal_new ("select",
97                     GTK_RUN_FIRST,
98                     GTK_CLASS_TYPE (object_class),
99                     GTK_SIGNAL_OFFSET (GtkItemClass, select),
100                     _gtk_marshal_VOID__VOID,
101                     GTK_TYPE_NONE, 0);
102   item_signals[DESELECT] =
103     gtk_signal_new ("deselect",
104                     GTK_RUN_FIRST,
105                     GTK_CLASS_TYPE (object_class),
106                     GTK_SIGNAL_OFFSET (GtkItemClass, deselect),
107                     _gtk_marshal_VOID__VOID,
108                     GTK_TYPE_NONE, 0);
109   item_signals[TOGGLE] =
110     gtk_signal_new ("toggle",
111                     GTK_RUN_FIRST,
112                     GTK_CLASS_TYPE (object_class),
113                     GTK_SIGNAL_OFFSET (GtkItemClass, toggle),
114                     _gtk_marshal_VOID__VOID,
115                     GTK_TYPE_NONE, 0);
116   widget_class->activate_signal = item_signals[TOGGLE];
117 }
118
119 static void
120 gtk_item_init (GtkItem *item)
121 {
122   GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
123 }
124
125 void
126 gtk_item_select (GtkItem *item)
127 {
128   gtk_signal_emit (GTK_OBJECT (item), item_signals[SELECT]);
129 }
130
131 void
132 gtk_item_deselect (GtkItem *item)
133 {
134   gtk_signal_emit (GTK_OBJECT (item), item_signals[DESELECT]);
135 }
136
137 void
138 gtk_item_toggle (GtkItem *item)
139 {
140   gtk_signal_emit (GTK_OBJECT (item), item_signals[TOGGLE]);
141 }
142
143
144 static void
145 gtk_item_realize (GtkWidget *widget)
146 {
147   GdkWindowAttr attributes;
148   gint attributes_mask;
149
150   g_return_if_fail (GTK_IS_ITEM (widget));
151
152   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
153
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) |
163                            GDK_EXPOSURE_MASK |
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);
169
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);
173
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);
177 }
178
179 static gint
180 gtk_item_enter (GtkWidget        *widget,
181                 GdkEventCrossing *event)
182 {
183   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
184   g_return_val_if_fail (event != NULL, FALSE);
185
186   return gtk_widget_event (widget->parent, (GdkEvent*) event);
187 }
188
189 static gint
190 gtk_item_leave (GtkWidget        *widget,
191                 GdkEventCrossing *event)
192 {
193   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
194   g_return_val_if_fail (event != NULL, FALSE);
195
196   return gtk_widget_event (widget->parent, (GdkEvent*) event);
197 }
198