source: trunk/third/gtk/gtk/gtkitem.c @ 14482

Revision 14482, 6.4 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14481, which included commits to RCS files with non-trunk default branches.
Line 
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 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.
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 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library 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-1999.  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 "gtksignal.h"
29
30
31enum {
32  SELECT,
33  DESELECT,
34  TOGGLE,
35  LAST_SIGNAL
36};
37
38
39static void gtk_item_class_init (GtkItemClass     *klass);
40static void gtk_item_init       (GtkItem          *item);
41static void gtk_item_map        (GtkWidget        *widget);
42static void gtk_item_unmap      (GtkWidget        *widget);
43static void gtk_item_realize    (GtkWidget        *widget);
44static gint gtk_item_enter      (GtkWidget        *widget,
45                                 GdkEventCrossing *event);
46static gint gtk_item_leave      (GtkWidget        *widget,
47                                 GdkEventCrossing *event);
48
49
50static guint item_signals[LAST_SIGNAL] = { 0 };
51
52
53GtkType
54gtk_item_get_type (void)
55{
56  static GtkType item_type = 0;
57
58  if (!item_type)
59    {
60      static const GtkTypeInfo item_info =
61      {
62        "GtkItem",
63        sizeof (GtkItem),
64        sizeof (GtkItemClass),
65        (GtkClassInitFunc) gtk_item_class_init,
66        (GtkObjectInitFunc) gtk_item_init,
67        /* reserved_1 */ NULL,
68        /* reserved_2 */ NULL,
69        (GtkClassInitFunc) NULL,
70      };
71
72      item_type = gtk_type_unique (GTK_TYPE_BIN, &item_info);
73    }
74
75  return item_type;
76}
77
78static void
79gtk_item_class_init (GtkItemClass *class)
80{
81  GtkObjectClass *object_class;
82  GtkWidgetClass *widget_class;
83
84  object_class = (GtkObjectClass*) class;
85  widget_class = (GtkWidgetClass*) class;
86
87  item_signals[SELECT] =
88    gtk_signal_new ("select",
89                    GTK_RUN_FIRST,
90                    object_class->type,
91                    GTK_SIGNAL_OFFSET (GtkItemClass, select),
92                    gtk_marshal_NONE__NONE,
93                    GTK_TYPE_NONE, 0);
94  item_signals[DESELECT] =
95    gtk_signal_new ("deselect",
96                    GTK_RUN_FIRST,
97                    object_class->type,
98                    GTK_SIGNAL_OFFSET (GtkItemClass, deselect),
99                    gtk_marshal_NONE__NONE,
100                    GTK_TYPE_NONE, 0);
101  item_signals[TOGGLE] =
102    gtk_signal_new ("toggle",
103                    GTK_RUN_FIRST,
104                    object_class->type,
105                    GTK_SIGNAL_OFFSET (GtkItemClass, toggle),
106                    gtk_marshal_NONE__NONE,
107                    GTK_TYPE_NONE, 0);
108
109  gtk_object_class_add_signals (object_class, item_signals, LAST_SIGNAL);
110
111  widget_class->activate_signal = item_signals[TOGGLE];
112  widget_class->map = gtk_item_map;
113  widget_class->unmap = gtk_item_unmap;
114  widget_class->realize = gtk_item_realize;
115  widget_class->enter_notify_event = gtk_item_enter;
116  widget_class->leave_notify_event = gtk_item_leave;
117
118  class->select = NULL;
119  class->deselect = NULL;
120  class->toggle = NULL;
121}
122
123static void
124gtk_item_init (GtkItem *item)
125{
126  GTK_WIDGET_UNSET_FLAGS (item, GTK_NO_WINDOW);
127}
128
129void
130gtk_item_select (GtkItem *item)
131{
132  gtk_signal_emit (GTK_OBJECT (item), item_signals[SELECT]);
133}
134
135void
136gtk_item_deselect (GtkItem *item)
137{
138  gtk_signal_emit (GTK_OBJECT (item), item_signals[DESELECT]);
139}
140
141void
142gtk_item_toggle (GtkItem *item)
143{
144  gtk_signal_emit (GTK_OBJECT (item), item_signals[TOGGLE]);
145}
146
147
148static void
149gtk_item_map (GtkWidget *widget)
150{
151  GtkBin *bin;
152
153  g_return_if_fail (widget != NULL);
154  g_return_if_fail (GTK_IS_ITEM (widget));
155
156  GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
157
158  bin = GTK_BIN (widget);
159
160  if (bin->child &&
161      GTK_WIDGET_VISIBLE (bin->child) &&
162      !GTK_WIDGET_MAPPED (bin->child))
163    gtk_widget_map (bin->child);
164
165  gdk_window_show (widget->window);
166}
167
168static void
169gtk_item_unmap (GtkWidget *widget)
170{
171  g_return_if_fail (widget != NULL);
172  g_return_if_fail (GTK_IS_ITEM (widget));
173
174  GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
175
176  gdk_window_hide (widget->window);
177}
178
179static void
180gtk_item_realize (GtkWidget *widget)
181{
182  GdkWindowAttr attributes;
183  gint attributes_mask;
184
185  g_return_if_fail (widget != NULL);
186  g_return_if_fail (GTK_IS_ITEM (widget));
187
188  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
189
190  attributes.x = widget->allocation.x;
191  attributes.y = widget->allocation.y;
192  attributes.width = widget->allocation.width;
193  attributes.height = widget->allocation.height;
194  attributes.window_type = GDK_WINDOW_CHILD;
195  attributes.wclass = GDK_INPUT_OUTPUT;
196  attributes.visual = gtk_widget_get_visual (widget);
197  attributes.colormap = gtk_widget_get_colormap (widget);
198  attributes.event_mask = (gtk_widget_get_events (widget) |
199                           GDK_EXPOSURE_MASK |
200                           GDK_BUTTON_PRESS_MASK |
201                           GDK_BUTTON_RELEASE_MASK |
202                           GDK_ENTER_NOTIFY_MASK |
203                           GDK_LEAVE_NOTIFY_MASK |
204                           GDK_POINTER_MOTION_MASK);
205
206  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
207  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
208  gdk_window_set_user_data (widget->window, widget);
209
210  widget->style = gtk_style_attach (widget->style, widget->window);
211  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
212   gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
213}
214
215static gint
216gtk_item_enter (GtkWidget        *widget,
217                GdkEventCrossing *event)
218{
219  g_return_val_if_fail (widget != NULL, FALSE);
220  g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
221  g_return_val_if_fail (event != NULL, FALSE);
222
223  return gtk_widget_event (widget->parent, (GdkEvent*) event);
224}
225
226static gint
227gtk_item_leave (GtkWidget        *widget,
228                GdkEventCrossing *event)
229{
230  g_return_val_if_fail (widget != NULL, FALSE);
231  g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
232  g_return_val_if_fail (event != NULL, FALSE);
233
234  return gtk_widget_event (widget->parent, (GdkEvent*) event);
235}
236
Note: See TracBrowser for help on using the repository browser.