1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * arch-tag: Implementation of the "disclosure" widget
5 * Authors: Iain Holmes <iain@ximian.com>
7 * Copyright 2002 Iain Holmes
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
29 #include <gtk/gtkexpander.h>
30 #include <libgnome/gnome-i18n.h>
32 #include "disclosure-widget.h"
34 static void expander_callback (GObject
*object
,
35 GParamSpec
*param_spec
,
38 static GtkExpanderClass
*parent_class
= NULL
;
40 struct CDDBDisclosurePrivate
{
47 finalize (GObject
*object
)
49 CDDBDisclosure
*disclosure
;
51 disclosure
= CDDB_DISCLOSURE (object
);
53 g_free (disclosure
->priv
->hidden
);
54 g_free (disclosure
->priv
->shown
);
56 if (disclosure
->priv
->container
!= NULL
) {
57 g_object_unref (G_OBJECT (disclosure
->priv
->container
));
60 g_free (disclosure
->priv
);
61 disclosure
->priv
= NULL
;
63 G_OBJECT_CLASS (parent_class
)->finalize (object
);
67 class_init (CDDBDisclosureClass
*klass
)
69 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);;
71 parent_class
= g_type_class_peek_parent (klass
);
73 object_class
->finalize
= finalize
;
77 init (CDDBDisclosure
*disclosure
)
79 disclosure
->priv
= g_new0 (CDDBDisclosurePrivate
, 1);
83 cddb_disclosure_get_type (void)
85 static GType type
= 0;
89 sizeof (CDDBDisclosureClass
),
90 NULL
, NULL
, (GClassInitFunc
) class_init
, NULL
, NULL
,
91 sizeof (CDDBDisclosure
), 0, (GInstanceInitFunc
) init
94 type
= g_type_register_static (GTK_TYPE_EXPANDER
, "CDDBDisclosure", &info
, 0);
101 cddb_disclosure_new (const char *shown
,
104 CDDBDisclosure
*disclosure
;
106 disclosure
= g_object_new (cddb_disclosure_get_type (), "use_underline", TRUE
, NULL
);
108 cddb_disclosure_set_labels (disclosure
, shown
, hidden
);
109 g_signal_connect (G_OBJECT (disclosure
), "notify::expanded", G_CALLBACK (expander_callback
), NULL
);
111 return GTK_WIDGET (disclosure
);
115 cddb_disclosure_set_container (CDDBDisclosure
*cddb
, GtkWidget
*widget
)
117 if (widget
!= NULL
) {
118 g_object_ref (widget
);
120 if (cddb
->priv
->container
!= NULL
) {
121 g_object_unref (cddb
->priv
->container
);
123 cddb
->priv
->container
= widget
;
127 cddb_disclosure_set_labels (CDDBDisclosure
*cddb
,
128 const char *label_when_shown
,
129 const char *label_when_hidden
)
133 g_free (cddb
->priv
->shown
);
134 g_free (cddb
->priv
->hidden
);
135 cddb
->priv
->shown
= g_strdup (label_when_shown
);
136 cddb
->priv
->hidden
= g_strdup (label_when_hidden
);
138 /* update the correct label text depending on button state */
139 active
= gtk_expander_get_expanded (GTK_EXPANDER(cddb
));
140 g_object_set (G_OBJECT(cddb
),
141 "label", active
? cddb
->priv
->hidden
: cddb
->priv
->shown
,
146 expander_callback (GObject
*object
,
147 GParamSpec
*param_spec
,
150 CDDBDisclosure
*disclosure
= CDDB_DISCLOSURE (object
);
153 active
= gtk_expander_get_expanded (GTK_EXPANDER (disclosure
));
154 g_object_set (disclosure
,
155 "label", active
? disclosure
->priv
->hidden
: disclosure
->priv
->shown
,