]> Pileus Git - ~andy/gtk/blob - gtk/gtkitem.c
image: replace gdk_draw_pixbuf() call with Cairo equivalent
[~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
32
33 enum {
34   SELECT,
35   DESELECT,
36   TOGGLE,
37   LAST_SIGNAL
38 };
39
40
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 G_DEFINE_ABSTRACT_TYPE (GtkItem, gtk_item, GTK_TYPE_BIN)
51
52 static void
53 gtk_item_class_init (GtkItemClass *class)
54 {
55   GObjectClass *object_class;
56   GtkWidgetClass *widget_class;
57
58   object_class = (GObjectClass*) class;
59   widget_class = (GtkWidgetClass*) class;
60
61   widget_class->realize = gtk_item_realize;
62   widget_class->enter_notify_event = gtk_item_enter;
63   widget_class->leave_notify_event = gtk_item_leave;
64
65   class->select = NULL;
66   class->deselect = NULL;
67   class->toggle = NULL;
68
69   item_signals[SELECT] =
70     g_signal_new (I_("select"),
71                   G_OBJECT_CLASS_TYPE (object_class),
72                   G_SIGNAL_RUN_FIRST,
73                   G_STRUCT_OFFSET (GtkItemClass, select),
74                   NULL, NULL,
75                   _gtk_marshal_VOID__VOID,
76                   G_TYPE_NONE, 0);
77   item_signals[DESELECT] =
78     g_signal_new (I_("deselect"),
79                   G_OBJECT_CLASS_TYPE (object_class),
80                   G_SIGNAL_RUN_FIRST,
81                   G_STRUCT_OFFSET (GtkItemClass, deselect),
82                   NULL, NULL,
83                   _gtk_marshal_VOID__VOID,
84                   G_TYPE_NONE, 0);
85   item_signals[TOGGLE] =
86     g_signal_new (I_("toggle"),
87                   G_OBJECT_CLASS_TYPE (object_class),
88                   G_SIGNAL_RUN_FIRST,
89                   G_STRUCT_OFFSET (GtkItemClass, toggle),
90                   NULL, NULL,
91                   _gtk_marshal_VOID__VOID,
92                   G_TYPE_NONE, 0);
93   widget_class->activate_signal = item_signals[TOGGLE];
94 }
95
96 static void
97 gtk_item_init (GtkItem *item)
98 {
99   gtk_widget_set_has_window (GTK_WIDGET (item), TRUE);
100 }
101
102 void
103 gtk_item_select (GtkItem *item)
104 {
105   g_signal_emit (item, item_signals[SELECT], 0);
106 }
107
108 void
109 gtk_item_deselect (GtkItem *item)
110 {
111   g_signal_emit (item, item_signals[DESELECT], 0);
112 }
113
114 void
115 gtk_item_toggle (GtkItem *item)
116 {
117   g_signal_emit (item, item_signals[TOGGLE], 0);
118 }
119
120
121 static void
122 gtk_item_realize (GtkWidget *widget)
123 {
124   GdkWindowAttr attributes;
125   gint attributes_mask;
126
127   gtk_widget_set_realized (widget, TRUE);
128
129   attributes.x = widget->allocation.x;
130   attributes.y = widget->allocation.y;
131   attributes.width = widget->allocation.width;
132   attributes.height = widget->allocation.height;
133   attributes.window_type = GDK_WINDOW_CHILD;
134   attributes.wclass = GDK_INPUT_OUTPUT;
135   attributes.visual = gtk_widget_get_visual (widget);
136   attributes.colormap = gtk_widget_get_colormap (widget);
137   attributes.event_mask = (gtk_widget_get_events (widget) |
138                            GDK_EXPOSURE_MASK |
139                            GDK_BUTTON_PRESS_MASK |
140                            GDK_BUTTON_RELEASE_MASK |
141                            GDK_ENTER_NOTIFY_MASK |
142                            GDK_LEAVE_NOTIFY_MASK |
143                            GDK_POINTER_MOTION_MASK);
144
145   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
146   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
147   gdk_window_set_user_data (widget->window, widget);
148
149   widget->style = gtk_style_attach (widget->style, widget->window);
150   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
151   gdk_window_set_back_pixmap (widget->window, NULL, TRUE);
152 }
153
154 static gint
155 gtk_item_enter (GtkWidget        *widget,
156                 GdkEventCrossing *event)
157 {
158   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
159   g_return_val_if_fail (event != NULL, FALSE);
160
161   return gtk_widget_event (widget->parent, (GdkEvent*) event);
162 }
163
164 static gint
165 gtk_item_leave (GtkWidget        *widget,
166                 GdkEventCrossing *event)
167 {
168   g_return_val_if_fail (GTK_IS_ITEM (widget), FALSE);
169   g_return_val_if_fail (event != NULL, FALSE);
170
171   return gtk_widget_event (widget->parent, (GdkEvent*) event);
172 }