]> Pileus Git - ~andy/gtk/blob - gtk/gtkeventbox.c
Deprecation cleanup
[~andy/gtk] / gtk / gtkeventbox.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 "gtkeventbox.h"
28
29
30 static void gtk_event_box_class_init               (GtkEventBoxClass *klass);
31 static void gtk_event_box_init                     (GtkEventBox      *event_box);
32 static void gtk_event_box_realize                  (GtkWidget        *widget);
33 static void gtk_event_box_size_request             (GtkWidget        *widget,
34                                                     GtkRequisition   *requisition);
35 static void gtk_event_box_size_allocate            (GtkWidget        *widget,
36                                                     GtkAllocation    *allocation);
37 static void gtk_event_box_paint                    (GtkWidget         *widget,
38                                                     GdkRectangle      *area);
39 static gint gtk_event_box_expose                   (GtkWidget         *widget,
40                                                    GdkEventExpose     *event);
41
42
43 static GtkBinClass *parent_class = NULL;
44
45 GType
46 gtk_event_box_get_type (void)
47 {
48   static GType event_box_type = 0;
49
50   if (!event_box_type)
51     {
52       static const GTypeInfo event_box_info =
53       {
54         sizeof (GtkEventBoxClass),
55         NULL,           /* base_init */
56         NULL,           /* base_finalize */
57         (GClassInitFunc) gtk_event_box_class_init,
58         NULL,           /* class_finalize */
59         NULL,           /* class_data */
60         sizeof (GtkEventBox),
61         0,              /* n_preallocs */
62         (GInstanceInitFunc) gtk_event_box_init,
63       };
64
65       event_box_type = g_type_register_static (GTK_TYPE_BIN, "GtkEventBox",
66                                                &event_box_info, 0);
67     }
68
69   return event_box_type;
70 }
71
72 static void
73 gtk_event_box_class_init (GtkEventBoxClass *class)
74 {
75   GtkWidgetClass *widget_class;
76
77   parent_class = g_type_class_peek_parent (class);
78   
79   widget_class = (GtkWidgetClass*) class;
80
81   widget_class->realize = gtk_event_box_realize;
82   widget_class->size_request = gtk_event_box_size_request;
83   widget_class->size_allocate = gtk_event_box_size_allocate;
84   widget_class->expose_event = gtk_event_box_expose;
85 }
86
87 static void
88 gtk_event_box_init (GtkEventBox *event_box)
89 {
90   GTK_WIDGET_UNSET_FLAGS (event_box, GTK_NO_WINDOW);
91 }
92
93 GtkWidget*
94 gtk_event_box_new (void)
95 {
96   return g_object_new (GTK_TYPE_EVENT_BOX, NULL);
97 }
98
99 static void
100 gtk_event_box_realize (GtkWidget *widget)
101 {
102   GdkWindowAttr attributes;
103   gint attributes_mask;
104   gint border_width;
105
106   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
107
108   border_width = GTK_CONTAINER (widget)->border_width;
109   
110   attributes.x = widget->allocation.x + border_width;
111   attributes.y = widget->allocation.y + border_width;
112   attributes.width = widget->allocation.width - 2*border_width;
113   attributes.height = widget->allocation.height - 2*border_width;
114   attributes.window_type = GDK_WINDOW_CHILD;
115   attributes.wclass = GDK_INPUT_OUTPUT;
116   attributes.visual = gtk_widget_get_visual (widget);
117   attributes.colormap = gtk_widget_get_colormap (widget);
118   attributes.event_mask = gtk_widget_get_events (widget)
119                         | GDK_BUTTON_MOTION_MASK
120                         | GDK_BUTTON_PRESS_MASK
121                         | GDK_BUTTON_RELEASE_MASK
122                         | GDK_EXPOSURE_MASK
123                         | GDK_ENTER_NOTIFY_MASK
124                         | GDK_LEAVE_NOTIFY_MASK;
125
126   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
127
128   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
129   gdk_window_set_user_data (widget->window, widget);
130
131   widget->style = gtk_style_attach (widget->style, widget->window);
132   gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
133 }
134
135 static void
136 gtk_event_box_size_request (GtkWidget      *widget,
137                             GtkRequisition *requisition)
138 {
139   GtkBin *bin = GTK_BIN (widget);
140
141   requisition->width = GTK_CONTAINER (widget)->border_width * 2;
142   requisition->height = GTK_CONTAINER (widget)->border_width * 2;
143
144   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
145     {
146       GtkRequisition child_requisition;
147       
148       gtk_widget_size_request (bin->child, &child_requisition);
149
150       requisition->width += child_requisition.width;
151       requisition->height += child_requisition.height;
152     }
153 }
154
155 static void
156 gtk_event_box_size_allocate (GtkWidget     *widget,
157                             GtkAllocation *allocation)
158 {
159   GtkBin *bin;
160   GtkAllocation child_allocation;
161
162   widget->allocation = *allocation;
163   bin = GTK_BIN (widget);
164
165   child_allocation.x = 0;
166   child_allocation.y = 0;
167   child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
168   child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
169
170   if (GTK_WIDGET_REALIZED (widget))
171     {
172       gdk_window_move_resize (widget->window,
173                               allocation->x + GTK_CONTAINER (widget)->border_width,
174                               allocation->y + GTK_CONTAINER (widget)->border_width,
175                               child_allocation.width,
176                               child_allocation.height);
177     }
178   
179   if (bin->child)
180     {
181       gtk_widget_size_allocate (bin->child, &child_allocation);
182     }
183 }
184
185 static void
186 gtk_event_box_paint (GtkWidget    *widget,
187                      GdkRectangle *area)
188 {
189   if (!GTK_WIDGET_APP_PAINTABLE (widget))
190     gtk_paint_flat_box (widget->style, widget->window,
191                         widget->state, GTK_SHADOW_NONE,
192                         area, widget, "eventbox",
193                         0, 0, -1, -1);
194 }
195
196 static gint
197 gtk_event_box_expose (GtkWidget      *widget,
198                      GdkEventExpose *event)
199 {
200   if (GTK_WIDGET_DRAWABLE (widget))
201     {
202       gtk_event_box_paint (widget, &event->area);
203       
204       (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
205     }
206
207   return FALSE;
208 }
209