1 /* vim: set ts=4 sts=4 sw=4 et: */
3 * Copyright (C) 2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Davyd Madeley <davyd.madeley@collabora.co.uk>
22 #include "empathy-kludge-label.h"
24 G_DEFINE_TYPE (EmpathyKludgeLabel, empathy_kludge_label, GTK_TYPE_LABEL);
27 empathy_kludge_label_size_allocate (GtkWidget *self,
28 GtkAllocation *allocation)
32 GTK_WIDGET_CLASS (empathy_kludge_label_parent_class)->size_allocate (
35 /* force the width of the PangoLayout to be the width of the allocation */
36 layout = gtk_label_get_layout (GTK_LABEL (self));
37 pango_layout_set_width (layout, allocation->width * PANGO_SCALE);
41 empathy_kludge_label_expose_event (GtkWidget *self,
42 GdkEventExpose *event)
46 GtkAllocation real_allocation;
49 layout = gtk_label_get_layout (GTK_LABEL (self));
50 pango_layout_get_pixel_extents (layout, NULL, &rect);
52 /* this is mind-bendingly evil:
53 * get_layout_location() is going to remove rect.x from the position of the
54 * layout when painting it. This really sucks. We're going to compensate by
55 * adding this value to the allocation.
57 real_allocation = self->allocation;
58 self->allocation.x += rect.x;
60 r = GTK_WIDGET_CLASS (empathy_kludge_label_parent_class)->expose_event (
63 self->allocation = real_allocation;
69 empathy_kludge_label_class_init (EmpathyKludgeLabelClass *klass)
71 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
73 widget_class->size_allocate = empathy_kludge_label_size_allocate;
74 widget_class->expose_event = empathy_kludge_label_expose_event;
78 empathy_kludge_label_init (EmpathyKludgeLabel *self)
83 empathy_kludge_label_new (const char *str)
85 return g_object_new (EMPATHY_TYPE_KLUDGE_LABEL,