Debian Codegraph @

geanygendoc/src/ggd-widget-frame.c

raw
1 /*
2 *
3 * GeanyGenDoc, a Geany plugin to ease generation of source code documentation
4 * Copyright (C) 2010-2011 Colomban Wendling <[email protected]>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 /*
22 * A GtkFrame subclass that reproduce Glade's frames.
23 */
24
25 #include <gtk/gtk.h>
26
27 #include "ggd-widget-frame.h"
28
29
30 struct _GgdFramePrivate
31 {
32 PangoAttrList *label_attr_list;
33 GtkWidget *alignment;
34 };
35
36
37 G_DEFINE_TYPE (GgdFrame, ggd_frame, GTK_TYPE_FRAME)
38
39
40 static void
41 ggd_frame_add (GtkContainer *container,
42 GtkWidget *child)
43 {
44 GgdFrame *self = GGD_FRAME (container);
45
46 /* chain additions to the alignment if we aren't adding it */
47 if (child == self->priv->alignment) {
48 GTK_CONTAINER_CLASS (ggd_frame_parent_class)->add (container, child);
49 } else {
50 container = GTK_CONTAINER (self->priv->alignment);
51 GTK_CONTAINER_GET_CLASS (container)->add (container, child);
52 }
53 }
54
55 static void
56 ggd_frame_finalize (GObject *object)
57 {
58 GgdFrame *self = GGD_FRAME (object);
59
60 pango_attr_list_unref (self->priv->label_attr_list);
61
62 G_OBJECT_CLASS (ggd_frame_parent_class)->finalize (object);
63 }
64
65 static void
66 ggd_frame_class_init (GgdFrameClass *klass)
67 {
68 GObjectClass *object_class = G_OBJECT_CLASS (klass);
69 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
70
71 object_class->finalize = ggd_frame_finalize;
72 container_class->add = ggd_frame_add;
73
74 g_type_class_add_private (klass, sizeof (GgdFramePrivate));
75 }
76
77 static void
78 ggd_frame_label_notify (GObject *object,
79 GParamSpec *pspec,
80 gpointer data)
81 {
82 GgdFrame *self = GGD_FRAME (object);
83 GtkWidget *label;
84
85 label = gtk_frame_get_label_widget (GTK_FRAME (self));
86 if (label) {
87 gtk_label_set_attributes (GTK_LABEL (label), self->priv->label_attr_list);
88 }
89 }
90
91 static void
92 ggd_frame_init (GgdFrame *self)
93 {
94 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
95 GGD_TYPE_FRAME,
96 GgdFramePrivate);
97
98 /* set-up the frame attributes */
99 gtk_frame_set_shadow_type (GTK_FRAME (self), GTK_SHADOW_NONE);
100 /* set-up fake child */
101 self->priv->alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
102 gtk_alignment_set_padding (GTK_ALIGNMENT(self->priv->alignment), 0, 0, 12, 0);
103 gtk_container_add (GTK_CONTAINER (self), self->priv->alignment);
104 gtk_widget_show (self->priv->alignment);
105 /* set-up the label's attributes */
106 self->priv->label_attr_list = pango_attr_list_new ();
107 pango_attr_list_insert (self->priv->label_attr_list,
108 pango_attr_weight_new (PANGO_WEIGHT_BOLD));
109
110 g_signal_connect (self, "notify::label",
111 G_CALLBACK (ggd_frame_label_notify), NULL);
112 }
113
114
115 GtkWidget *
116 ggd_frame_new (const gchar *label)
117 {
118 return g_object_new (GGD_TYPE_FRAME, "label", label, NULL);
119 }