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