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 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.
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.
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.
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/.
27 #include "gtksignal.h"
28 #include "gtkeventbox.h"
31 static void gtk_event_box_class_init (GtkEventBoxClass *klass);
32 static void gtk_event_box_init (GtkEventBox *event_box);
33 static void gtk_event_box_realize (GtkWidget *widget);
34 static void gtk_event_box_size_request (GtkWidget *widget,
35 GtkRequisition *requisition);
36 static void gtk_event_box_size_allocate (GtkWidget *widget,
37 GtkAllocation *allocation);
38 static void gtk_event_box_paint (GtkWidget *widget,
40 static gint gtk_event_box_expose (GtkWidget *widget,
41 GdkEventExpose *event);
44 static GtkBinClass *parent_class = NULL;
47 gtk_event_box_get_type (void)
49 static GtkType event_box_type = 0;
53 static const GtkTypeInfo event_box_info =
57 sizeof (GtkEventBoxClass),
58 (GtkClassInitFunc) gtk_event_box_class_init,
59 (GtkObjectInitFunc) gtk_event_box_init,
60 /* reserved_1 */ NULL,
61 /* reserved_2 */ NULL,
62 (GtkClassInitFunc) NULL,
65 event_box_type = gtk_type_unique (gtk_bin_get_type (), &event_box_info);
68 return event_box_type;
72 gtk_event_box_class_init (GtkEventBoxClass *class)
74 GtkWidgetClass *widget_class;
76 parent_class = g_type_class_peek_parent (class);
78 widget_class = (GtkWidgetClass*) class;
80 widget_class->realize = gtk_event_box_realize;
81 widget_class->size_request = gtk_event_box_size_request;
82 widget_class->size_allocate = gtk_event_box_size_allocate;
83 widget_class->expose_event = gtk_event_box_expose;
87 gtk_event_box_init (GtkEventBox *event_box)
89 GTK_WIDGET_UNSET_FLAGS (event_box, GTK_NO_WINDOW);
93 gtk_event_box_new (void)
95 return GTK_WIDGET (gtk_type_new (gtk_event_box_get_type ()));
99 gtk_event_box_realize (GtkWidget *widget)
101 GdkWindowAttr attributes;
102 gint attributes_mask;
105 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
107 border_width = GTK_CONTAINER (widget)->border_width;
109 attributes.x = widget->allocation.x + border_width;
110 attributes.y = widget->allocation.y + border_width;
111 attributes.width = widget->allocation.width - 2*border_width;
112 attributes.height = widget->allocation.height - 2*border_width;
113 attributes.window_type = GDK_WINDOW_CHILD;
114 attributes.wclass = GDK_INPUT_OUTPUT;
115 attributes.visual = gtk_widget_get_visual (widget);
116 attributes.colormap = gtk_widget_get_colormap (widget);
117 attributes.event_mask = gtk_widget_get_events (widget)
118 | GDK_BUTTON_MOTION_MASK
119 | GDK_BUTTON_PRESS_MASK
120 | GDK_BUTTON_RELEASE_MASK
122 | GDK_ENTER_NOTIFY_MASK
123 | GDK_LEAVE_NOTIFY_MASK;
125 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
127 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
128 gdk_window_set_user_data (widget->window, widget);
130 widget->style = gtk_style_attach (widget->style, widget->window);
131 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
135 gtk_event_box_size_request (GtkWidget *widget,
136 GtkRequisition *requisition)
138 GtkBin *bin = GTK_BIN (widget);
140 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
141 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
143 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
145 GtkRequisition child_requisition;
147 gtk_widget_size_request (bin->child, &child_requisition);
149 requisition->width += child_requisition.width;
150 requisition->height += child_requisition.height;
155 gtk_event_box_size_allocate (GtkWidget *widget,
156 GtkAllocation *allocation)
159 GtkAllocation child_allocation;
161 widget->allocation = *allocation;
162 bin = GTK_BIN (widget);
164 child_allocation.x = 0;
165 child_allocation.y = 0;
166 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
167 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
169 if (GTK_WIDGET_REALIZED (widget))
171 gdk_window_move_resize (widget->window,
172 allocation->x + GTK_CONTAINER (widget)->border_width,
173 allocation->y + GTK_CONTAINER (widget)->border_width,
174 child_allocation.width,
175 child_allocation.height);
180 gtk_widget_size_allocate (bin->child, &child_allocation);
185 gtk_event_box_paint (GtkWidget *widget,
188 gtk_paint_flat_box (widget->style, widget->window,
189 widget->state, GTK_SHADOW_NONE,
190 area, widget, "eventbox",
195 gtk_event_box_expose (GtkWidget *widget,
196 GdkEventExpose *event)
198 if (GTK_WIDGET_DRAWABLE (widget))
200 gtk_event_box_paint (widget, &event->area);
202 (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);