1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include "gtksignal.h"
19 #include "gtkeventbox.h"
22 static void gtk_event_box_class_init (GtkEventBoxClass *klass);
23 static void gtk_event_box_init (GtkEventBox *event_box);
24 static void gtk_event_box_realize (GtkWidget *widget);
25 static void gtk_event_box_size_request (GtkWidget *widget,
26 GtkRequisition *requisition);
27 static void gtk_event_box_size_allocate (GtkWidget *widget,
28 GtkAllocation *allocation);
29 static void gtk_event_box_draw (GtkWidget *widget,
31 static gint gtk_event_box_expose (GtkWidget *widget,
32 GdkEventExpose *event);
36 gtk_event_box_get_type ()
38 static guint event_box_type = 0;
42 GtkTypeInfo event_box_info =
46 sizeof (GtkEventBoxClass),
47 (GtkClassInitFunc) gtk_event_box_class_init,
48 (GtkObjectInitFunc) gtk_event_box_init,
52 event_box_type = gtk_type_unique (gtk_bin_get_type (), &event_box_info);
55 return event_box_type;
59 gtk_event_box_class_init (GtkEventBoxClass *class)
61 GtkWidgetClass *widget_class;
63 widget_class = (GtkWidgetClass*) class;
65 widget_class->realize = gtk_event_box_realize;
66 widget_class->size_request = gtk_event_box_size_request;
67 widget_class->size_allocate = gtk_event_box_size_allocate;
68 widget_class->draw = gtk_event_box_draw;
69 widget_class->expose_event = gtk_event_box_expose;
73 gtk_event_box_init (GtkEventBox *event_box)
75 GTK_WIDGET_UNSET_FLAGS (event_box, GTK_NO_WINDOW);
76 GTK_WIDGET_SET_FLAGS (event_box, GTK_BASIC);
82 return GTK_WIDGET ( gtk_type_new (gtk_event_box_get_type ()));
86 gtk_event_box_realize (GtkWidget *widget)
88 GdkWindowAttr attributes;
91 g_return_if_fail (widget != NULL);
92 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
94 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
96 attributes.x = widget->allocation.x;
97 attributes.y = widget->allocation.y;
98 attributes.width = widget->allocation.width;
99 attributes.height = widget->allocation.height;
100 attributes.window_type = GDK_WINDOW_CHILD;
101 attributes.wclass = GDK_INPUT_OUTPUT;
102 attributes.visual = gtk_widget_get_visual (widget);
103 attributes.colormap = gtk_widget_get_colormap (widget);
104 attributes.event_mask = gtk_widget_get_events (widget)
105 | GDK_BUTTON_MOTION_MASK
106 | GDK_BUTTON_PRESS_MASK
107 | GDK_BUTTON_RELEASE_MASK
109 | GDK_ENTER_NOTIFY_MASK
110 | GDK_LEAVE_NOTIFY_MASK;
112 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
114 widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
115 gdk_window_set_user_data (widget->window, widget);
117 widget->style = gtk_style_attach (widget->style, widget->window);
118 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
122 gtk_event_box_size_request (GtkWidget *widget,
123 GtkRequisition *requisition)
127 g_return_if_fail (widget != NULL);
128 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
129 g_return_if_fail (requisition != NULL);
131 bin = GTK_BIN (widget);
133 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
134 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
136 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
138 gtk_widget_size_request (bin->child, &bin->child->requisition);
140 requisition->width += bin->child->requisition.width;
141 requisition->height += bin->child->requisition.height;
146 gtk_event_box_size_allocate (GtkWidget *widget,
147 GtkAllocation *allocation)
150 GtkAllocation child_allocation;
152 g_return_if_fail (widget != NULL);
153 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
154 g_return_if_fail (allocation != NULL);
156 widget->allocation = *allocation;
157 bin = GTK_BIN (widget);
159 child_allocation.x = 0;
160 child_allocation.y = 0;
161 child_allocation.width = allocation->width - GTK_CONTAINER (widget)->border_width * 2;
162 child_allocation.height = allocation->height - GTK_CONTAINER (widget)->border_width * 2;
164 if (GTK_WIDGET_REALIZED (widget))
166 gdk_window_move_resize (widget->window,
167 allocation->x + GTK_CONTAINER (widget)->border_width,
168 allocation->y + GTK_CONTAINER (widget)->border_width,
169 child_allocation.width,
170 child_allocation.height);
173 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
175 gtk_widget_size_allocate (bin->child, &child_allocation);
180 gtk_event_box_draw (GtkWidget *widget,
184 GdkRectangle child_area;
186 g_return_if_fail (widget != NULL);
187 g_return_if_fail (GTK_IS_EVENT_BOX (widget));
188 g_return_if_fail (area != NULL);
190 if (GTK_WIDGET_DRAWABLE (widget))
192 bin = GTK_BIN (widget);
196 if (gtk_widget_intersect (bin->child, area, &child_area))
197 gtk_widget_draw (bin->child, &child_area);
203 gtk_event_box_expose (GtkWidget *widget,
204 GdkEventExpose *event)
207 GdkEventExpose child_event;
209 g_return_val_if_fail (widget != NULL, FALSE);
210 g_return_val_if_fail (GTK_IS_EVENT_BOX (widget), FALSE);
211 g_return_val_if_fail (event != NULL, FALSE);
213 if (GTK_WIDGET_DRAWABLE (widget))
215 bin = GTK_BIN (widget);
217 child_event = *event;
219 GTK_WIDGET_NO_WINDOW (bin->child) &&
220 gtk_widget_intersect (bin->child, &event->area, &child_event.area))
221 gtk_widget_event (bin->child, (GdkEvent*) &child_event);