Use gtk_container_handle_border_width() in GtkEventBox

This commit is contained in:
Matthias Clasen 2010-10-14 22:34:39 -04:00
parent bda1f35585
commit aaf0f0f5c3

View File

@ -75,6 +75,7 @@ gtk_event_box_class_init (GtkEventBoxClass *class)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (class); GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
gobject_class->set_property = gtk_event_box_set_property; gobject_class->set_property = gtk_event_box_set_property;
gobject_class->get_property = gtk_event_box_get_property; gobject_class->get_property = gtk_event_box_get_property;
@ -87,6 +88,8 @@ gtk_event_box_class_init (GtkEventBoxClass *class)
widget_class->size_allocate = gtk_event_box_size_allocate; widget_class->size_allocate = gtk_event_box_size_allocate;
widget_class->draw = gtk_event_box_draw; widget_class->draw = gtk_event_box_draw;
gtk_container_class_handle_border_width (container_class);
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_VISIBLE_WINDOW, PROP_VISIBLE_WINDOW,
g_param_spec_boolean ("visible-window", g_param_spec_boolean ("visible-window",
@ -372,7 +375,6 @@ gtk_event_box_realize (GtkWidget *widget)
GdkWindow *window; GdkWindow *window;
GdkWindowAttr attributes; GdkWindowAttr attributes;
gint attributes_mask; gint attributes_mask;
gint border_width;
GtkEventBoxPrivate *priv; GtkEventBoxPrivate *priv;
gboolean visible_window; gboolean visible_window;
@ -380,12 +382,10 @@ gtk_event_box_realize (GtkWidget *widget)
gtk_widget_set_realized (widget, TRUE); gtk_widget_set_realized (widget, TRUE);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); attributes.x = allocation.x;
attributes.y = allocation.y;
attributes.x = allocation.x + border_width; attributes.width = allocation.width;
attributes.y = allocation.y + border_width; attributes.height = allocation.height;
attributes.width = allocation.width - 2*border_width;
attributes.height = allocation.height - 2*border_width;
attributes.window_type = GDK_WINDOW_CHILD; attributes.window_type = GDK_WINDOW_CHILD;
attributes.event_mask = gtk_widget_get_events (widget) attributes.event_mask = gtk_widget_get_events (widget)
| GDK_BUTTON_MOTION_MASK | GDK_BUTTON_MOTION_MASK
@ -489,12 +489,10 @@ gtk_event_box_size_request (GtkWidget *widget,
GtkRequisition *requisition) GtkRequisition *requisition)
{ {
GtkBin *bin = GTK_BIN (widget); GtkBin *bin = GTK_BIN (widget);
guint border_width;
GtkWidget *child; GtkWidget *child;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); requisition->width = 0;
requisition->width = border_width * 2; requisition->height = 0;
requisition->height = border_width * 2;
child = gtk_bin_get_child (bin); child = gtk_bin_get_child (bin);
if (child && gtk_widget_get_visible (child)) if (child && gtk_widget_get_visible (child))
@ -515,27 +513,24 @@ gtk_event_box_size_allocate (GtkWidget *widget,
GtkBin *bin; GtkBin *bin;
GtkAllocation child_allocation; GtkAllocation child_allocation;
GtkEventBoxPrivate *priv; GtkEventBoxPrivate *priv;
guint border_width;
GtkWidget *child; GtkWidget *child;
bin = GTK_BIN (widget); bin = GTK_BIN (widget);
gtk_widget_set_allocation (widget, allocation); gtk_widget_set_allocation (widget, allocation);
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
if (!gtk_widget_get_has_window (widget)) if (!gtk_widget_get_has_window (widget))
{ {
child_allocation.x = allocation->x + border_width; child_allocation.x = allocation->x;
child_allocation.y = allocation->y + border_width; child_allocation.y = allocation->y;
} }
else else
{ {
child_allocation.x = 0; child_allocation.x = 0;
child_allocation.y = 0; child_allocation.y = 0;
} }
child_allocation.width = MAX (allocation->width - border_width * 2, 0); child_allocation.width = allocation->width;
child_allocation.height = MAX (allocation->height - border_width * 2, 0); child_allocation.height = allocation->height;
if (gtk_widget_get_realized (widget)) if (gtk_widget_get_realized (widget))
{ {
@ -550,8 +545,8 @@ gtk_event_box_size_allocate (GtkWidget *widget,
if (gtk_widget_get_has_window (widget)) if (gtk_widget_get_has_window (widget))
gdk_window_move_resize (gtk_widget_get_window (widget), gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x + border_width, allocation->x,
allocation->y + border_width, allocation->y,
child_allocation.width, child_allocation.width,
child_allocation.height); child_allocation.height);
} }