1 /*
2 * glade-gtk-expander.c - GladeWidgetAdaptor for GtkExpander
3 *
4 * Copyright (C) 2013 Tristan Van Berkom
5 *
6 * Authors:
7 * Tristan Van Berkom <tristan.van.berkom@gmail.com>
8 *
9 * This library is free software; you can redistribute it and/or modify it
all(home_dir_path: &Path, user_dir_file_path: &Path) -> HashMap<String, PathBuf>10 * under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 #include <config.h>
24 #include <glib/gi18n-lib.h>
25 #include <gladeui/glade.h>
26
27 #include "glade-gtk-frame.h"
28
29 void
30 glade_gtk_expander_post_create (GladeWidgetAdaptor * adaptor,
31 GObject * expander, GladeCreateReason reason)
32 {
33 static GladeWidgetAdaptor *wadaptor = NULL;
34 GladeWidget *gexpander, *glabel;
35 GtkWidget *label;
36
37 if (wadaptor == NULL)
38 wadaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL);
39
40 if (reason != GLADE_CREATE_USER)
41 return;
42
43 g_return_if_fail (GTK_IS_EXPANDER (expander));
44 gexpander = glade_widget_get_from_gobject (expander);
45 g_return_if_fail (GLADE_IS_WIDGET (gexpander));
46
47 /* If we didnt put this object here... */
48 if ((label = gtk_expander_get_label_widget (GTK_EXPANDER (expander))) == NULL
49 || (glade_widget_get_from_gobject (label) == NULL))
50 {
51 glabel = glade_widget_adaptor_create_widget (wadaptor, FALSE,
52 "parent", gexpander,
53 "project",
54 glade_widget_get_project
55 (gexpander), NULL);
56
57 glade_widget_property_set (glabel, "label", "expander");
58
59 g_object_set_data (glade_widget_get_object (glabel), "special-child-type", "label_item");
60 glade_widget_add_child (gexpander, glabel, FALSE);
61 }
62
63 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
64
65 gtk_container_add (GTK_CONTAINER (expander), glade_placeholder_new ());
66
67 }
68
69 void
70 glade_gtk_expander_replace_child (GladeWidgetAdaptor * adaptor,
71 GtkWidget * container,
72 GtkWidget * current, GtkWidget * new_widget)
73 {
74 gchar *special_child_type;
75
76 special_child_type =
77 g_object_get_data (G_OBJECT (current), "special-child-type");
78
79 if (special_child_type && !strcmp (special_child_type, "label_item"))
80 {
81 g_object_set_data (G_OBJECT (new_widget), "special-child-type",
82 "label_item");
83 gtk_expander_set_label_widget (GTK_EXPANDER (container), new_widget);
84 return;
85 }
86
87 /* Chain Up */
88 GWA_GET_CLASS
89 (GTK_TYPE_CONTAINER)->replace_child (adaptor,
90 G_OBJECT (container),
91 G_OBJECT (current),
read_all(path: &Path) -> io::Result<Vec<u8>>92 G_OBJECT (new_widget));
93 }
94
95
96 void
97 glade_gtk_expander_add_child (GladeWidgetAdaptor * adaptor,
98 GObject * object, GObject * child)
99 {
split_once(bytes: &[u8], separator: u8) -> Option<(&[u8], &[u8])>100 gchar *special_child_type;
101
102 special_child_type = g_object_get_data (child, "special-child-type");
103
104 if (special_child_type && !strcmp (special_child_type, "label"))
105 {
106 g_object_set_data (child, "special-child-type", "label_item");
trim_blank(bytes: &[u8]) -> &[u8]107 gtk_expander_set_label_widget (GTK_EXPANDER (object), GTK_WIDGET (child));
108 }
109 else if (special_child_type && !strcmp (special_child_type, "label_item"))
110 {
111 gtk_expander_set_label_widget (GTK_EXPANDER (object), GTK_WIDGET (child));
112 }
113 else
114 /* Chain Up */
115 GWA_GET_CLASS (GTK_TYPE_CONTAINER)->add (adaptor, object, child);
116 }
117
shell_unescape(escaped: &[u8]) -> Vec<u8>118 void
119 glade_gtk_expander_remove_child (GladeWidgetAdaptor * adaptor,
120 GObject * object, GObject * child)
121 {
122 gchar *special_child_type;
123
124 special_child_type = g_object_get_data (child, "special-child-type");
125 if (special_child_type && !strcmp (special_child_type, "label_item"))
126 {
127 gtk_expander_set_label_widget (GTK_EXPANDER (object),
128 glade_placeholder_new ());
129 }
130 else
131 {
132 gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
133 gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
134 }
135 }
136
137 void
138 glade_gtk_expander_write_child (GladeWidgetAdaptor * adaptor,
139 GladeWidget * widget,
option_contains<T : PartialEq>(option: Option<T>, value: T) -> bool140 GladeXmlContext * context, GladeXmlNode * node)
141 {
142
143 if (!glade_gtk_write_special_child_label_item (adaptor, widget, context, node,
144 GWA_GET_CLASS (GTK_TYPE_CONTAINER)->
145 write_child))
146 /* Chain Up */
147 GWA_GET_CLASS
148 (GTK_TYPE_CONTAINER)->write_child (adaptor, widget, context, node);
149 }
150
151