1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
2 /*
3 * Copyright © 2007 Xan Lopez
4 *
5 * This file is part of Epiphany.
6 *
7 * Epiphany is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Epiphany is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include "ephy-embed-container.h"
24 #include "ephy-embed-type-builtins.h"
25
26 G_DEFINE_INTERFACE (EphyEmbedContainer, ephy_embed_container, G_TYPE_OBJECT);
27
28 static void
ephy_embed_container_default_init(EphyEmbedContainerInterface * iface)29 ephy_embed_container_default_init (EphyEmbedContainerInterface *iface)
30 {
31 g_object_interface_install_property (iface,
32 g_param_spec_boolean ("is-popup", NULL, NULL,
33 FALSE,
34 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
35
36 g_object_interface_install_property (iface,
37 g_param_spec_object ("active-child", NULL, NULL,
38 GTK_TYPE_WIDGET /* Can't use an interface type here */,
39 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
40 }
41
42 /**
43 * ephy_embed_container_add_child:
44 * @container: an #EphyEmbedContainer
45 * @child: an #EphyEmbed
46 * @parent: (nullable): the parent #EphyEmbed, or %NULL
47 * @position: the position in @container if @parent is %NULL
48 * @set_active: whether to set @embed as the active child of @container
49 * after insertion
50 *
51 * Inserts @child into @container. The new embed will be inserted after @parent,
52 * or at @position if it's %NULL.
53 *
54 * Return value: @child's new position inside @container.
55 **/
56 gint
ephy_embed_container_add_child(EphyEmbedContainer * container,EphyEmbed * child,EphyEmbed * parent,int position,gboolean set_active)57 ephy_embed_container_add_child (EphyEmbedContainer *container,
58 EphyEmbed *child,
59 EphyEmbed *parent,
60 int position,
61 gboolean set_active)
62 {
63 EphyEmbedContainerInterface *iface;
64
65 g_assert (EPHY_IS_EMBED_CONTAINER (container));
66 g_assert (EPHY_IS_EMBED (child));
67
68 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
69 return iface->add_child (container, child, parent, position, set_active);
70 }
71
72 /**
73 * ephy_embed_container_set_active_child:
74 * @container: an #EphyEmbedContainer
75 * @child: an #EphyEmbed inside @container
76 *
77 * Sets @child as @container's active child.
78 **/
79 void
ephy_embed_container_set_active_child(EphyEmbedContainer * container,EphyEmbed * child)80 ephy_embed_container_set_active_child (EphyEmbedContainer *container,
81 EphyEmbed *child)
82 {
83 EphyEmbedContainerInterface *iface;
84
85 g_assert (EPHY_IS_EMBED_CONTAINER (container));
86 g_assert (EPHY_IS_EMBED (child));
87
88 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
89
90 iface->set_active_child (container, child);
91 }
92
93 /**
94 * ephy_embed_container_remove_child:
95 * @container: an #EphyEmbedContainer
96 * @child: an #EphyEmbed
97 *
98 * Removes @child from @container.
99 **/
100 void
ephy_embed_container_remove_child(EphyEmbedContainer * container,EphyEmbed * child)101 ephy_embed_container_remove_child (EphyEmbedContainer *container,
102 EphyEmbed *child)
103 {
104 EphyEmbedContainerInterface *iface;
105
106 g_assert (EPHY_IS_EMBED_CONTAINER (container));
107 g_assert (EPHY_IS_EMBED (child));
108
109 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
110
111 iface->remove_child (container, child);
112 }
113
114 /**
115 * ephy_embed_container_get_active_child:
116 * @container: an #EphyEmbedContainer
117 *
118 * Returns @container's active #EphyEmbed.
119 *
120 * Return value: (transfer none): @container's active child
121 **/
122 EphyEmbed *
ephy_embed_container_get_active_child(EphyEmbedContainer * container)123 ephy_embed_container_get_active_child (EphyEmbedContainer *container)
124 {
125 EphyEmbedContainerInterface *iface;
126
127 g_assert (EPHY_IS_EMBED_CONTAINER (container));
128
129 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
130 return iface->get_active_child (container);
131 }
132
133 /**
134 * ephy_embed_container_get_children:
135 * @container: a #EphyEmbedContainer
136 *
137 * Returns the list of #EphyEmbed:s in the container.
138 *
139 * Return value: (element-type EphyEmbed) (transfer container):
140 * a newly-allocated list of #EphyEmbed:s
141 */
142 GList *
ephy_embed_container_get_children(EphyEmbedContainer * container)143 ephy_embed_container_get_children (EphyEmbedContainer *container)
144 {
145 EphyEmbedContainerInterface *iface;
146
147 g_assert (EPHY_IS_EMBED_CONTAINER (container));
148
149 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
150 return iface->get_children (container);
151 }
152
153 /**
154 * ephy_embed_container_get_is_popup:
155 * @container: an #EphyEmbedContainer
156 *
157 * Returns whether this embed container is a popup.
158 *
159 * Return value: %TRUE if it is a popup
160 **/
161 gboolean
ephy_embed_container_get_is_popup(EphyEmbedContainer * container)162 ephy_embed_container_get_is_popup (EphyEmbedContainer *container)
163 {
164 EphyEmbedContainerInterface *iface;
165
166 g_assert (EPHY_IS_EMBED_CONTAINER (container));
167
168 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
169 return iface->get_is_popup (container);
170 }
171
172 /**
173 * ephy_embed_container_get_n_children:
174 * @container: a #EphyEmbedContainer
175 *
176 * Returns the number of #EphyEmbed:s in the container.
177 *
178 * Returns: the number of children
179 */
180 guint
ephy_embed_container_get_n_children(EphyEmbedContainer * container)181 ephy_embed_container_get_n_children (EphyEmbedContainer *container)
182 {
183 EphyEmbedContainerInterface *iface;
184
185 g_assert (EPHY_IS_EMBED_CONTAINER (container));
186
187 iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
188 return iface->get_n_children (container);
189 }
190