summaryrefslogtreecommitdiff
path: root/embed/ephy-embed-container.c
blob: edb86445ffd2634757b809030a470e6b3c77bbbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
/*
 *  Copyright © 2007 Xan Lopez
 *
 *  This file is part of Epiphany.
 *
 *  Epiphany is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Epiphany is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "ephy-embed-container.h"
#include "ephy-embed-type-builtins.h"

G_DEFINE_INTERFACE (EphyEmbedContainer, ephy_embed_container, G_TYPE_OBJECT);

static void
ephy_embed_container_default_init (EphyEmbedContainerInterface *iface)
{
  g_object_interface_install_property (iface,
                                       g_param_spec_boolean ("is-popup", NULL, NULL,
                                                             FALSE,
                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));

  g_object_interface_install_property (iface,
                                       g_param_spec_object ("active-child", NULL, NULL,
                                                            GTK_TYPE_WIDGET /* Can't use an interface type here */,
                                                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}

/**
 * ephy_embed_container_add_child:
 * @container: an #EphyEmbedContainer
 * @child: an #EphyEmbed
 * @parent: (nullable): the parent #EphyEmbed, or %NULL
 * @position: the position in @container if @parent is %NULL
 * @set_active: whether to set @embed as the active child of @container
 * after insertion
 *
 * Inserts @child into @container. The new embed will be inserted after @parent,
 * or at @position if it's %NULL.
 *
 * Return value: @child's new position inside @container.
 **/
gint
ephy_embed_container_add_child (EphyEmbedContainer *container,
                                EphyEmbed          *child,
                                EphyEmbed          *parent,
                                int                 position,
                                gboolean            set_active)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));
  g_assert (EPHY_IS_EMBED (child));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
  return iface->add_child (container, child, parent, position, set_active);
}

/**
 * ephy_embed_container_set_active_child:
 * @container: an #EphyEmbedContainer
 * @child: an #EphyEmbed inside @container
 *
 * Sets @child as @container's active child.
 **/
void
ephy_embed_container_set_active_child (EphyEmbedContainer *container,
                                       EphyEmbed          *child)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));
  g_assert (EPHY_IS_EMBED (child));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);

  iface->set_active_child (container, child);
}

/**
 * ephy_embed_container_remove_child:
 * @container: an #EphyEmbedContainer
 * @child: an #EphyEmbed
 *
 * Removes @child from @container.
 **/
void
ephy_embed_container_remove_child (EphyEmbedContainer *container,
                                   EphyEmbed          *child)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));
  g_assert (EPHY_IS_EMBED (child));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);

  iface->remove_child (container, child);
}

/**
 * ephy_embed_container_get_active_child:
 * @container: an #EphyEmbedContainer
 *
 * Returns @container's active #EphyEmbed.
 *
 * Return value: (transfer none): @container's active child
 **/
EphyEmbed *
ephy_embed_container_get_active_child (EphyEmbedContainer *container)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
  return iface->get_active_child (container);
}

/**
 * ephy_embed_container_get_children:
 * @container: a #EphyEmbedContainer
 *
 * Returns the list of #EphyEmbed:s in the container.
 *
 * Return value: (element-type EphyEmbed) (transfer container):
 *               a newly-allocated list of #EphyEmbed:s
 */
GList *
ephy_embed_container_get_children (EphyEmbedContainer *container)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
  return iface->get_children (container);
}

/**
 * ephy_embed_container_get_is_popup:
 * @container: an #EphyEmbedContainer
 *
 * Returns whether this embed container is a popup.
 *
 * Return value: %TRUE if it is a popup
 **/
gboolean
ephy_embed_container_get_is_popup (EphyEmbedContainer *container)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
  return iface->get_is_popup (container);
}

/**
 * ephy_embed_container_get_n_children:
 * @container: a #EphyEmbedContainer
 *
 * Returns the number of #EphyEmbed:s in the container.
 *
 * Returns: the number of children
 */
guint
ephy_embed_container_get_n_children (EphyEmbedContainer *container)
{
  EphyEmbedContainerInterface *iface;

  g_assert (EPHY_IS_EMBED_CONTAINER (container));

  iface = EPHY_EMBED_CONTAINER_GET_IFACE (container);
  return iface->get_n_children (container);
}