2009-08-04 20:08:59 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:shell-generic-container
|
|
|
|
* @short_description: A container class with signals for allocation
|
|
|
|
*
|
|
|
|
* #ShellGenericContainer is mainly a workaround for the current
|
|
|
|
* lack of GObject subclassing + vfunc overrides in gjs. We
|
|
|
|
* implement the container interface, but proxy the virtual functions
|
|
|
|
* into signals, which gjs can catch.
|
2010-03-02 20:21:22 +00:00
|
|
|
*
|
|
|
|
* #ShellGenericContainer is an #StWidget, and automatically takes its
|
|
|
|
* borders and padding into account during size request and allocation.
|
2009-08-04 20:08:59 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-24 14:07:40 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
#include "shell-generic-container.h"
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <girepository.h>
|
|
|
|
|
2010-02-03 00:21:30 +00:00
|
|
|
static void shell_generic_container_iface_init (ClutterContainerIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE(ShellGenericContainer,
|
|
|
|
shell_generic_container,
|
2012-02-16 18:14:53 +00:00
|
|
|
ST_TYPE_WIDGET,
|
2010-02-03 00:21:30 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
|
|
|
|
shell_generic_container_iface_init));
|
2009-08-04 20:08:59 +00:00
|
|
|
|
|
|
|
struct _ShellGenericContainerPrivate {
|
2009-11-26 17:13:16 +00:00
|
|
|
GHashTable *skip_paint;
|
2009-08-04 20:08:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Signals */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
GET_PREFERRED_WIDTH,
|
|
|
|
GET_PREFERRED_HEIGHT,
|
|
|
|
ALLOCATE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint shell_generic_container_signals [LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
shell_generic_container_allocation_ref (ShellGenericContainerAllocation *alloc)
|
|
|
|
{
|
|
|
|
alloc->_refcount++;
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_generic_container_allocation_unref (ShellGenericContainerAllocation *alloc)
|
|
|
|
{
|
|
|
|
if (--alloc->_refcount == 0)
|
2010-03-02 19:11:45 +00:00
|
|
|
g_slice_free (ShellGenericContainerAllocation, alloc);
|
2009-08-04 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-02 19:11:45 +00:00
|
|
|
shell_generic_container_allocate (ClutterActor *self,
|
|
|
|
const ClutterActorBox *box,
|
|
|
|
ClutterAllocationFlags flags)
|
2009-08-04 20:08:59 +00:00
|
|
|
{
|
2010-03-02 20:21:22 +00:00
|
|
|
StThemeNode *theme_node;
|
|
|
|
ClutterActorBox content_box;
|
|
|
|
|
2012-02-15 12:11:41 +00:00
|
|
|
clutter_actor_set_allocation (self, box, flags);
|
2010-03-02 20:21:22 +00:00
|
|
|
|
|
|
|
theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
|
|
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
2009-08-04 20:08:59 +00:00
|
|
|
|
|
|
|
g_signal_emit (G_OBJECT (self), shell_generic_container_signals[ALLOCATE], 0,
|
2010-03-02 20:21:22 +00:00
|
|
|
&content_box, flags);
|
2009-08-04 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_generic_container_get_preferred_width (ClutterActor *actor,
|
2010-03-02 19:11:45 +00:00
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
2009-08-04 20:08:59 +00:00
|
|
|
{
|
2010-03-02 19:11:45 +00:00
|
|
|
ShellGenericContainerAllocation *alloc = g_slice_new0 (ShellGenericContainerAllocation);
|
2010-03-02 20:21:22 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
|
|
|
|
|
|
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
2010-03-02 19:11:45 +00:00
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
alloc->_refcount = 1;
|
|
|
|
g_signal_emit (G_OBJECT (actor), shell_generic_container_signals[GET_PREFERRED_WIDTH], 0,
|
|
|
|
for_height, alloc);
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = alloc->min_size;
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = alloc->natural_size;
|
|
|
|
shell_generic_container_allocation_unref (alloc);
|
2010-03-30 14:26:38 +00:00
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
2009-08-04 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_generic_container_get_preferred_height (ClutterActor *actor,
|
2010-03-02 19:11:45 +00:00
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
2009-08-04 20:08:59 +00:00
|
|
|
{
|
2010-03-02 19:11:45 +00:00
|
|
|
ShellGenericContainerAllocation *alloc = g_slice_new0 (ShellGenericContainerAllocation);
|
2010-03-02 20:21:22 +00:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
|
|
|
|
|
|
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
2010-03-02 19:11:45 +00:00
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
alloc->_refcount = 1;
|
|
|
|
g_signal_emit (G_OBJECT (actor), shell_generic_container_signals[GET_PREFERRED_HEIGHT], 0,
|
|
|
|
for_width, alloc);
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = alloc->min_size;
|
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = alloc->natural_size;
|
|
|
|
shell_generic_container_allocation_unref (alloc);
|
2010-03-30 14:26:38 +00:00
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
2009-08-04 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-26 17:13:16 +00:00
|
|
|
static void
|
|
|
|
shell_generic_container_paint (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
ShellGenericContainer *self = (ShellGenericContainer*) actor;
|
2012-02-16 18:40:31 +00:00
|
|
|
ClutterActor *child;
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2012-02-13 21:41:29 +00:00
|
|
|
st_widget_paint_background (ST_WIDGET (actor));
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2012-02-16 18:40:31 +00:00
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2009-11-26 17:13:16 +00:00
|
|
|
{
|
|
|
|
if (g_hash_table_lookup (self->priv->skip_paint, child))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
clutter_actor_paint (child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_generic_container_pick (ClutterActor *actor,
|
|
|
|
const ClutterColor *color)
|
|
|
|
{
|
|
|
|
ShellGenericContainer *self = (ShellGenericContainer*) actor;
|
2012-02-16 18:40:31 +00:00
|
|
|
ClutterActor *child;
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2010-03-02 20:21:22 +00:00
|
|
|
CLUTTER_ACTOR_CLASS (shell_generic_container_parent_class)->pick (actor, color);
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2012-02-16 18:40:31 +00:00
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2009-11-26 17:13:16 +00:00
|
|
|
{
|
|
|
|
if (g_hash_table_lookup (self->priv->skip_paint, child))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
clutter_actor_paint (child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-15 16:11:39 +00:00
|
|
|
static GList *
|
2012-02-14 00:55:30 +00:00
|
|
|
shell_generic_container_get_focus_chain (StWidget *widget)
|
2010-06-15 16:11:39 +00:00
|
|
|
{
|
2012-02-14 00:55:30 +00:00
|
|
|
ShellGenericContainer *self = SHELL_GENERIC_CONTAINER (widget);
|
2012-02-16 18:40:31 +00:00
|
|
|
ClutterActor *child;
|
|
|
|
GList *focus_chain;
|
2010-06-15 16:11:39 +00:00
|
|
|
|
|
|
|
focus_chain = NULL;
|
2012-02-16 18:40:31 +00:00
|
|
|
for (child = clutter_actor_get_first_child (CLUTTER_ACTOR (self));
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2010-06-15 16:11:39 +00:00
|
|
|
{
|
|
|
|
if (CLUTTER_ACTOR_IS_VISIBLE (child) &&
|
|
|
|
!shell_generic_container_get_skip_paint (self, child))
|
|
|
|
focus_chain = g_list_prepend (focus_chain, child);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_reverse (focus_chain);
|
|
|
|
}
|
|
|
|
|
2010-02-22 21:22:38 +00:00
|
|
|
/**
|
|
|
|
* shell_generic_container_get_n_skip_paint:
|
2010-09-15 00:56:34 +00:00
|
|
|
* @self: A #ShellGenericContainer
|
2010-02-22 21:22:38 +00:00
|
|
|
*
|
|
|
|
* Returns: Number of children which will not be painted.
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
shell_generic_container_get_n_skip_paint (ShellGenericContainer *self)
|
|
|
|
{
|
|
|
|
return g_hash_table_size (self->priv->skip_paint);
|
|
|
|
}
|
|
|
|
|
2010-04-29 15:15:22 +00:00
|
|
|
/**
|
|
|
|
* shell_generic_container_get_skip_paint:
|
2010-09-15 00:56:34 +00:00
|
|
|
* @self: A #ShellGenericContainer
|
2010-04-29 15:15:22 +00:00
|
|
|
* @child: Child #ClutterActor
|
|
|
|
*
|
|
|
|
* Gets whether or not @actor is skipped when painting.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE or %FALSE
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
shell_generic_container_get_skip_paint (ShellGenericContainer *self,
|
|
|
|
ClutterActor *child)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (self->priv->skip_paint, child) != NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-26 17:13:16 +00:00
|
|
|
/**
|
|
|
|
* shell_generic_container_set_skip_paint:
|
2010-09-15 00:56:34 +00:00
|
|
|
* @self: A #ShellGenericContainer
|
2009-11-26 17:13:16 +00:00
|
|
|
* @child: Child #ClutterActor
|
2010-04-29 15:15:22 +00:00
|
|
|
* @skip: %TRUE if we should skip painting
|
2009-11-26 17:13:16 +00:00
|
|
|
*
|
|
|
|
* Set whether or not we should skip painting @actor. Workaround for
|
|
|
|
* lack of gjs ability to override _paint vfunc.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
shell_generic_container_set_skip_paint (ShellGenericContainer *self,
|
|
|
|
ClutterActor *child,
|
|
|
|
gboolean skip)
|
|
|
|
{
|
|
|
|
gboolean currently_skipping;
|
|
|
|
|
|
|
|
currently_skipping = g_hash_table_lookup (self->priv->skip_paint, child) != NULL;
|
|
|
|
if (!!skip == currently_skipping)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!skip)
|
2010-02-03 00:21:30 +00:00
|
|
|
g_hash_table_remove (self->priv->skip_paint, child);
|
2009-11-26 17:13:16 +00:00
|
|
|
else
|
2010-02-03 00:21:30 +00:00
|
|
|
g_hash_table_insert (self->priv->skip_paint, child, child);
|
2011-01-13 22:48:51 +00:00
|
|
|
|
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (self));
|
2009-11-26 17:13:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-02-03 00:21:30 +00:00
|
|
|
shell_generic_container_finalize (GObject *object)
|
2009-11-26 17:13:16 +00:00
|
|
|
{
|
|
|
|
ShellGenericContainer *self = (ShellGenericContainer*) object;
|
|
|
|
|
2010-02-03 00:21:30 +00:00
|
|
|
g_hash_table_destroy (self->priv->skip_paint);
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2010-02-03 00:21:30 +00:00
|
|
|
G_OBJECT_CLASS (shell_generic_container_parent_class)->finalize (object);
|
2009-11-26 17:13:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
static void
|
|
|
|
shell_generic_container_class_init (ShellGenericContainerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2012-02-14 00:55:30 +00:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2009-08-04 20:08:59 +00:00
|
|
|
|
2010-02-03 00:21:30 +00:00
|
|
|
gobject_class->finalize = shell_generic_container_finalize;
|
2009-11-26 17:13:16 +00:00
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
actor_class->get_preferred_width = shell_generic_container_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = shell_generic_container_get_preferred_height;
|
|
|
|
actor_class->allocate = shell_generic_container_allocate;
|
2009-11-26 17:13:16 +00:00
|
|
|
actor_class->paint = shell_generic_container_paint;
|
|
|
|
actor_class->pick = shell_generic_container_pick;
|
2009-08-04 20:08:59 +00:00
|
|
|
|
2012-02-14 00:55:30 +00:00
|
|
|
widget_class->get_focus_chain = shell_generic_container_get_focus_chain;
|
2010-06-15 16:11:39 +00:00
|
|
|
|
2011-09-05 17:29:50 +00:00
|
|
|
/**
|
|
|
|
* ShellGenericContainer::get-preferred-width:
|
|
|
|
* @self: the #ShellGenericContainer
|
|
|
|
* @for_height: as in clutter_actor_get_preferred_width()
|
|
|
|
* @alloc: a #ShellGenericContainerAllocation to be filled in
|
|
|
|
*
|
|
|
|
* Emitted when clutter_actor_get_preferred_width() is called
|
|
|
|
* on @self. You should fill in the fields of @alloc with the
|
|
|
|
* your minimum and natural widths. #ShellGenericContainer
|
|
|
|
* will deal with taking its borders and padding into account
|
|
|
|
* for you.
|
|
|
|
*
|
|
|
|
* @alloc's fields are initialized to 0, so unless you have a fixed
|
|
|
|
* width specified (via #ClutterActor:width or CSS), you must
|
|
|
|
* connect to this signal and fill in the values.
|
|
|
|
*/
|
2009-08-04 20:08:59 +00:00
|
|
|
shell_generic_container_signals[GET_PREFERRED_WIDTH] =
|
|
|
|
g_signal_new ("get-preferred-width",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-08-04 20:08:59 +00:00
|
|
|
G_TYPE_NONE, 2, G_TYPE_FLOAT, SHELL_TYPE_GENERIC_CONTAINER_ALLOCATION);
|
|
|
|
|
2011-09-05 17:29:50 +00:00
|
|
|
/**
|
|
|
|
* ShellGenericContainer::get-preferred-height:
|
|
|
|
* @self: the #ShellGenericContainer
|
|
|
|
* @for_width: as in clutter_actor_get_preferred_height()
|
|
|
|
* @alloc: a #ShellGenericContainerAllocation to be filled in
|
|
|
|
*
|
|
|
|
* Emitted when clutter_actor_get_preferred_height() is called
|
|
|
|
* on @self. You should fill in the fields of @alloc with the
|
|
|
|
* your minimum and natural heights. #ShellGenericContainer
|
|
|
|
* will deal with taking its borders and padding into account
|
|
|
|
* for you.
|
|
|
|
*
|
|
|
|
* @alloc's fields are initialized to 0, so unless you have a fixed
|
|
|
|
* height specified (via #ClutterActor:height or CSS), you must
|
|
|
|
* connect to this signal and fill in the values.
|
|
|
|
*/
|
2009-08-04 20:08:59 +00:00
|
|
|
shell_generic_container_signals[GET_PREFERRED_HEIGHT] =
|
|
|
|
g_signal_new ("get-preferred-height",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-08-04 20:08:59 +00:00
|
|
|
G_TYPE_NONE, 2, G_TYPE_FLOAT, SHELL_TYPE_GENERIC_CONTAINER_ALLOCATION);
|
|
|
|
|
2011-09-05 17:29:50 +00:00
|
|
|
/**
|
|
|
|
* ShellGenericContainer::allocate:
|
|
|
|
* @self: the #ShellGenericContainer
|
|
|
|
* @box: @self's content box
|
|
|
|
* @flags: the allocation flags.
|
|
|
|
*
|
|
|
|
* Emitted when @self is allocated, after chaining up to the parent
|
|
|
|
* allocate method.
|
|
|
|
*
|
|
|
|
* Note that @box is @self's content box (qv
|
|
|
|
* st_theme_node_get_content_box()), NOT its allocation.
|
|
|
|
*/
|
2009-08-04 20:08:59 +00:00
|
|
|
shell_generic_container_signals[ALLOCATE] =
|
|
|
|
g_signal_new ("allocate",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
0,
|
2011-10-18 22:19:32 +00:00
|
|
|
NULL, NULL, NULL,
|
2009-08-04 20:08:59 +00:00
|
|
|
G_TYPE_NONE, 2, CLUTTER_TYPE_ACTOR_BOX, CLUTTER_TYPE_ALLOCATION_FLAGS);
|
|
|
|
|
|
|
|
g_type_class_add_private (gobject_class, sizeof (ShellGenericContainerPrivate));
|
|
|
|
}
|
|
|
|
|
2010-02-03 00:21:30 +00:00
|
|
|
static void
|
2010-03-27 04:09:53 +00:00
|
|
|
shell_generic_container_actor_removed (ClutterContainer *container,
|
|
|
|
ClutterActor *actor)
|
2010-02-03 00:21:30 +00:00
|
|
|
{
|
2010-03-02 20:21:22 +00:00
|
|
|
ShellGenericContainerPrivate *priv = SHELL_GENERIC_CONTAINER (container)->priv;
|
2010-02-03 00:21:30 +00:00
|
|
|
|
2010-03-04 22:38:35 +00:00
|
|
|
g_hash_table_remove (priv->skip_paint, actor);
|
2010-03-02 20:21:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_generic_container_iface_init (ClutterContainerIface *iface)
|
|
|
|
{
|
2010-03-27 04:09:53 +00:00
|
|
|
iface->actor_removed = shell_generic_container_actor_removed;
|
2010-02-03 00:21:30 +00:00
|
|
|
}
|
|
|
|
|
2009-08-04 20:08:59 +00:00
|
|
|
static void
|
|
|
|
shell_generic_container_init (ShellGenericContainer *area)
|
|
|
|
{
|
|
|
|
area->priv = G_TYPE_INSTANCE_GET_PRIVATE (area, SHELL_TYPE_GENERIC_CONTAINER,
|
|
|
|
ShellGenericContainerPrivate);
|
2010-02-03 00:21:30 +00:00
|
|
|
area->priv->skip_paint = g_hash_table_new (NULL, NULL);
|
2009-08-04 20:08:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 19:11:45 +00:00
|
|
|
GType
|
|
|
|
shell_generic_container_allocation_get_type (void)
|
2009-08-04 20:08:59 +00:00
|
|
|
{
|
|
|
|
static GType gtype = G_TYPE_INVALID;
|
|
|
|
if (gtype == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
gtype = g_boxed_type_register_static ("ShellGenericContainerAllocation",
|
|
|
|
(GBoxedCopyFunc)shell_generic_container_allocation_ref,
|
|
|
|
(GBoxedFreeFunc)shell_generic_container_allocation_unref);
|
|
|
|
}
|
|
|
|
return gtype;
|
|
|
|
}
|