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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
/* gtk-clutter-window.c: GtkWindow which provides a hidden ClutterStage
*
* Copyright (C) 2009 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not see <http://www.fsf.org/licensing>.
*
* Authors:
* Danielle Madeley <danielle.madeley@collabora.co.uk>
*/
/**
* SECTION:gtk-clutter-window
* @Title: GtkClutterWindow
* @short_description: a GtkWindow that embeds its contents onto a stage
*
* #GtkClutterWindow is a #GtkWindow sub-class that embeds a Clutter stage.
*
* #GtkClutterWindow behaves exactly like a #GtkWindow, except that its
* child is automatically embedded inside a #GtkClutterActor and it is
* thus part of the embedded #ClutterStage.
*
* Clutter actors can be added to the same stage by calling
* gtk_clutter_window_get_stage().
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gtk-clutter-window.h"
#include "gtk-clutter-actor.h"
#include "gtk-clutter-embed.h"
#include "gtk-clutter-util.h"
#include <glib-object.h>
G_DEFINE_TYPE (GtkClutterWindow, gtk_clutter_window, GTK_TYPE_WINDOW);
#define GTK_CLUTTER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_CLUTTER_TYPE_WINDOW, GtkClutterWindowPrivate))
struct _GtkClutterWindowPrivate
{
GtkWidget *embed;
ClutterActor *actor;
};
static void
gtk_clutter_window_finalize (GObject *self)
{
G_OBJECT_CLASS (gtk_clutter_window_parent_class)->finalize (self);
}
static void
gtk_clutter_window_size_request (GtkWidget *self,
GtkRequisition *requisition)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
g_return_if_fail (GTK_CLUTTER_IS_WINDOW (self));
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
/* find out what the preferred size of the bin contents are, since we
* can't ask Clutter for some reason (it always returns the allocated
* size -- why?). This means things like any scaling applied to the actor
* won't make the window change size (feature?) */
gtk_widget_get_preferred_size (gtk_bin_get_child (GTK_BIN (bin)),
requisition,
NULL);
}
static void
gtk_clutter_window_add (GtkContainer *self,
GtkWidget *widget)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
g_return_if_fail (GTK_CLUTTER_IS_WINDOW (self));
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->add (GTK_CONTAINER (bin), widget);
}
static void
gtk_clutter_window_remove (GtkContainer *self,
GtkWidget *widget)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
g_return_if_fail (GTK_CLUTTER_IS_WINDOW (self));
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->remove (GTK_CONTAINER (bin), widget);
}
static void
gtk_clutter_window_forall (GtkContainer *self,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
g_return_if_fail (GTK_CLUTTER_IS_WINDOW (self));
priv = GTK_CLUTTER_WINDOW (self)->priv;
/* this is particularly dodgy -- if we have asked to include_internals
* let's only return the internals, on the assumption that when events
* are sent to those internals, the child container will be iterated;
* otherwise, we don't want anyone to know about the container, so we
* return the contents of the bin */
if (include_internals)
{
GTK_CONTAINER_CLASS (gtk_clutter_window_parent_class)->forall (self,
include_internals, callback, callback_data);
}
else
{
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->forall (GTK_CONTAINER (bin),
include_internals, callback, callback_data);
}
}
static void
gtk_clutter_window_set_focus_child (GtkContainer *self,
GtkWidget *widget)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
g_return_if_fail (GTK_CLUTTER_IS_WINDOW (self));
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->set_focus_child (GTK_CONTAINER (bin), widget);
}
static GType
gtk_clutter_window_child_type (GtkContainer *self)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
return GTK_CONTAINER_GET_CLASS (bin)->child_type (GTK_CONTAINER (bin));
}
static char *
gtk_clutter_window_composite_name (GtkContainer *self,
GtkWidget *widget)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
return GTK_CONTAINER_GET_CLASS (bin)->composite_name (GTK_CONTAINER (bin),
widget);
}
static void
gtk_clutter_window_set_child_property (GtkContainer *self,
GtkWidget *widget,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->set_child_property (GTK_CONTAINER (bin),
widget,
property_id,
value, pspec);
}
static void
gtk_clutter_window_get_child_property (GtkContainer *self,
GtkWidget *widget,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkClutterWindowPrivate *priv;
GtkWidget *bin;
priv = GTK_CLUTTER_WINDOW (self)->priv;
bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->actor));
GTK_CONTAINER_GET_CLASS (bin)->get_child_property (GTK_CONTAINER (bin),
widget,
property_id,
value, pspec);
}
static void
gtk_clutter_window_class_init (GtkClutterWindowClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
g_type_class_add_private (klass, sizeof (GtkClutterWindowPrivate));
gobject_class->finalize = gtk_clutter_window_finalize;
widget_class->size_request = gtk_clutter_window_size_request;
/* connect all of the container methods up to our bin */
container_class->add = gtk_clutter_window_add;
container_class->remove = gtk_clutter_window_remove;
container_class->forall = gtk_clutter_window_forall;
container_class->set_focus_child = gtk_clutter_window_set_focus_child;
container_class->child_type = gtk_clutter_window_child_type;
container_class->composite_name = gtk_clutter_window_composite_name;
container_class->set_child_property = gtk_clutter_window_set_child_property;
container_class->get_child_property = gtk_clutter_window_get_child_property;
}
static void
gtk_clutter_window_init (GtkClutterWindow *self)
{
GtkClutterWindowPrivate *priv;
ClutterActor *stage;
self->priv = priv = GTK_CLUTTER_WINDOW_GET_PRIVATE (self);
gtk_widget_push_composite_child ();
priv->embed = gtk_clutter_embed_new ();
gtk_widget_set_composite_name (priv->embed, "GtkClutterEmbed");
GTK_CONTAINER_CLASS (gtk_clutter_window_parent_class)->add (GTK_CONTAINER (self), priv->embed);
gtk_widget_show (priv->embed);
gtk_widget_pop_composite_child ();
stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->embed));
priv->actor = gtk_clutter_actor_new ();
clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->actor);
clutter_actor_set_name (priv->actor, "GtkClutterActor");
clutter_actor_add_constraint_with_name (priv->actor, "content-x",
clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, 0.0));
clutter_actor_add_constraint_with_name (priv->actor, "content-y",
clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, 0.0));
}
/**
* gtk_clutter_window_new:
*
* Creates a new #GtkClutterWindow widget.
*
* This window provides a hidden #ClutterStage on which the child
* #GtkWidget<!-- -->s are placed. This allows other #ClutterActor<!-- -->s
* to also be placed on the stage.
*
* Return value: the newly created #GtkClutterWindow
*/
GtkWidget *
gtk_clutter_window_new (void)
{
return g_object_new (GTK_CLUTTER_TYPE_WINDOW, NULL);
}
/**
* gtk_clutter_window_get_stage:
* @window: the #GtkClutterWindow
*
* Retrieves the #ClutterStage that this window is embedding
*
* Use this function if you wish to add other actors to the #ClutterStage.
*
* Return value: (transfer none): the window's #ClutterStage
*/
ClutterActor *
gtk_clutter_window_get_stage (GtkClutterWindow *window)
{
GtkClutterWindowPrivate *priv;
g_return_val_if_fail (GTK_CLUTTER_IS_WINDOW (window), NULL);
priv = window->priv;
return gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->embed));
}
|