]> Pileus Git - ~andy/gtk/blob - gtk/gtkitem.c
Translation updated by Ivar Smolin.
[~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 "gtkalias.h"
31
32
33 enum {
34   SELECT,
35   DESELECT,
36   TOGGLE,
37   LAST_SIGNAL
38 };
39
40
41 static void gtk_item_class_init (GtkItemClass     *klass);
42 static void gtk_item_init       (GtkItem          *item);
43 static void gtk_item_realize    (GtkWidget        *widget);
44 static gint gtk_item_enter      (GtkWidget        *widget,
45                                  GdkEventCrossing *event);
46 static gint gtk_item_leave      (GtkWidget        *widget,
47                                  GdkEventCrossing *event);
48
49
50 static guint item_signals[LAST_SIGNAL] = { 0 };
51
52
53 GType
54 gtk_item_get_type (void)
55 {
56   static GType item_type = 0;
57
58   if (!item_type)
59     {
60       static const GTypeInfo item_info =
61       {
62         sizeof (GtkItemClass),
63         NULL,           /* base_init */
64         NULL,           /* base_finalize */
65         (GClassInitFunc) gtk_item_class_init,
66         NULL,           /* class_finalize */
67         NULL,           /* class_data */
68         sizeof (GtkItem),
69         0,              /* n_preallocs */
70         (GInstanceInitFunc) gtk_item_init,
71         NULL,           /* value_table */
72       };
73
74       item_type = g_type_register_static (GTK_TYPE_BIN, "GtkItem",
75                                           &item_info, G_TYPE_FLAG_ABSTRACT);
76     }
77
78   return item_type;
79 }
80
81 static void
82 gtk_item_class_init (GtkItemClass *class)
83 {
84   GObjectClass *object_class;
85   GtkWidgetClass *widget_class;
86
87   object_class = (GObjectClass*) class;
88   widget_class = (GtkWidgetClass*) class;
89
90   widget_class->realize = gtk_item_realize;
91   widget_class->enter_notify_event = gtk_item_enter;
92   widget_class->leave_notify_event = gtk_item_leave;
93
94   class->select = NULL;
95   class->deselect = NULL;
96   class->toggle = NULL;
97
98   item_signals[SELECT] =
99     g_signal_new ("select",
100                   G_OBJECT_CLASS_TYPE (object_class),
101                   G_SIGNAL_RUN_FIRST,
102                   G_STRUCT_OFFSET (GtkItemClass, select),
103                   NULL, NULL,
104                   _gtk_marshal_VOID__VOID,
105                   G_TYPE_NONE, 0);
106   item_signals[DESELECT] =
107     g_signal_new ("deselect",
108                   G_OBJECT_CLASS_TYPE (object_class),
109                   G_SIGNAL_RUN_FIRST,
110                   G_STRUCT_OFFSET (GtkItemClass, deselect),
111                   NULL, NULL,
112                   _gtk_marshal_VOID__VOID,
113                   G_TYPE_NONE, 0);
114   item_signals[TOGGLE] =
115     g_signal_new ("toggle",
116                   G_OBJECT_CLASS_TYPE (object_class),
117                   G_SIGNAL_RUN_FIRST,
118                   G_STRUCT_OFFSET (GtkItemClass, toggle),
119                   NULL, NULL,
120                   _gtk_marshal_VOID__VOID,
121                   G_TYPE_NONE, 0);
122   widget_class->activate_signal = item_signals[TOGGLE];
123 }
124
125 static void
126 gtk_item_init (GtkItem *item)
127 {
128   GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
129 }
130
131 void
132 gtk_item_select (GtkItem *item)
133 {
134   g_signal_emit (item, item_signals[SELECT], 0);
135 }
136
137 void
138 gtk_item_deselect (GtkItem *item)
139 {
140   g_signal_emit (item, item_signals[DESELECT], 0);
141 }
142
143 void
144 gtk_item_toggle (GtkItem *item)
145 {
146   g_signal_emit (item, item_signals[TOGGLE], 0);
147 }
148
149
150 static void
151 gtk_item_realize (GtkWidget *widget)
152 {
153   GdkWindowAttr attributes;
154   gint attributes_mask;
155
156   g_return_if_fail (GTK_IS_ITEM (widget));
157
158   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
159
160   attributes.x = widget->allocation.x;
161   attributes.y = widget->allocation.y;
162   attributes.width = widget->allocation.width;
163   attributes.height = widget->allocation.height;
164   attributes.window_type = GDK_WINDOW_CHILD;
165   attributes.wclass = GDK_INPUT_OUTPUT;
166   attributes.visual = gtk_widget_get_visual (widget);
167   attributes.colormap = gtk_widget_get_colormap (widget);
168   attributes.event_mask = (gtk_widget_get_events (widget) |
169                            GDK_EXPOSURE_MASK |
170                            GDK_BUTTON_PRESS_MASK |
171                            GDK_BUTTON_RELEASE_MASK |
172                            GDK_ENTER_NOTIFY_MASK |
173                            GDK_LEAVE_NOTIFY_MASK |
174                            GDK_POINTER_MOTION_MASK);
175
176   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
177   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
178   gdk_window_set_user_data (widget->window, widget);
179
180   widget->style = gtk_style_attach (widget->style, widget->window);
181   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
182   gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
183 }
184
185 static gint
186 gtk_item_enter (GtkWidget        *widget,
187                 GdkEventCrossing *event)
188 {
189   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
190   g_return_val_if_fail (event != NULL, FALSE);
191
192   return gtk_widget_event (widget->parent, (GdkEvent*) event);
193 }
194
195 static gint
196 gtk_item_leave (GtkWidget        *widget,
197                 GdkEventCrossing *event)
198 {
199   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
200   g_return_val_if_fail (event != NULL, FALSE);
201
202   return gtk_widget_event (widget->parent, (GdkEvent*) event);
203 }
204
205 #define __GTK_ITEM_C__
206 #include "gtkaliasdef.c"