]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-kludge-label.c
Updated Polish translation
[empathy.git] / libempathy-gtk / empathy-kludge-label.c
1 /* vim: set ts=4 sts=4 sw=4 et: */
2 /*
3  * Copyright (C) 2009 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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
18  *
19  * Authors: Davyd Madeley <davyd.madeley@collabora.co.uk>
20  */
21
22 #include "empathy-kludge-label.h"
23
24 G_DEFINE_TYPE (EmpathyKludgeLabel, empathy_kludge_label, GTK_TYPE_LABEL);
25
26 static void
27 empathy_kludge_label_size_allocate (GtkWidget     *self,
28                                     GtkAllocation *allocation)
29 {
30     PangoLayout *layout;
31
32     GTK_WIDGET_CLASS (empathy_kludge_label_parent_class)->size_allocate (
33             self, allocation);
34
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);
38 }
39
40 static gboolean
41 empathy_kludge_label_expose_event (GtkWidget      *self,
42                                    GdkEventExpose *event)
43 {
44     PangoLayout *layout;
45     PangoRectangle rect;
46     GtkAllocation real_allocation;
47     GtkAllocation allocation;
48     gboolean r;
49
50     layout = gtk_label_get_layout (GTK_LABEL (self));
51     pango_layout_get_pixel_extents (layout, NULL, &rect);
52
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.
57      */
58     gtk_widget_get_allocation (self, &allocation);
59     real_allocation = allocation;
60     allocation.x += rect.x;
61     gtk_widget_set_allocation (self, &allocation);
62
63     r = GTK_WIDGET_CLASS (empathy_kludge_label_parent_class)->expose_event (
64             self, event);
65
66     gtk_widget_set_allocation (self, &real_allocation);
67
68     return r;
69 }
70
71 static void
72 empathy_kludge_label_class_init (EmpathyKludgeLabelClass *klass)
73 {
74     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
75
76     widget_class->size_allocate = empathy_kludge_label_size_allocate;
77     widget_class->expose_event = empathy_kludge_label_expose_event;
78 }
79
80 static void
81 empathy_kludge_label_init (EmpathyKludgeLabel *self)
82 {
83 }
84
85 GtkWidget *
86 empathy_kludge_label_new (const char *str)
87 {
88     return g_object_new (EMPATHY_TYPE_KLUDGE_LABEL,
89             "label", str,
90             "xalign", 0.,
91             NULL);
92 }