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;
47 GtkAllocation allocation;
50 layout = gtk_label_get_layout (GTK_LABEL (self));
51 pango_layout_get_pixel_extents (layout, NULL, &rect);
53 /* this is mind-bendingly evil:
54 * get_layout_location() is going to remove rect.x from the position of the
55 * layout when painting it. This really sucks. We're going to compensate by
56 * adding this value to the allocation.
58 gtk_widget_get_allocation (self, &allocation);
59 real_allocation = allocation;
60 allocation.x += rect.x;
61 gtk_widget_set_allocation (self, &allocation);
63 r = GTK_WIDGET_CLASS (empathy_kludge_label_parent_class)->expose_event (
66 gtk_widget_set_allocation (self, &real_allocation);
72 empathy_kludge_label_class_init (EmpathyKludgeLabelClass *klass)
74 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
76 widget_class->size_allocate = empathy_kludge_label_size_allocate;
77 widget_class->expose_event = empathy_kludge_label_expose_event;
81 empathy_kludge_label_init (EmpathyKludgeLabel *self)
86 empathy_kludge_label_new (const char *str)
88 return g_object_new (EMPATHY_TYPE_KLUDGE_LABEL,