2009-06-29 12:51:10 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:shell-stack
|
|
|
|
* @short_description: Pure "Z-axis" container class
|
|
|
|
*
|
|
|
|
* A #ShellStack draws its children on top of each other,
|
|
|
|
* aligned to the top left. It will be sized in width/height
|
|
|
|
* according to the largest such dimension of its children, and
|
|
|
|
* all children will be allocated that size. This differs
|
|
|
|
* from #ClutterGroup which allocates its children their natural
|
|
|
|
* size, even if that would overflow the size allocated to the stack.
|
|
|
|
*/
|
|
|
|
|
2009-11-24 09:07:40 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-06-29 12:51:10 -04:00
|
|
|
#include "shell-stack.h"
|
|
|
|
|
2015-09-24 14:07:44 -04:00
|
|
|
struct _ShellStack
|
|
|
|
{
|
|
|
|
StWidget parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (ShellStack, shell_stack, ST_TYPE_WIDGET);
|
2011-04-06 12:53:19 -04:00
|
|
|
|
2009-06-29 12:51:10 -04:00
|
|
|
static void
|
|
|
|
shell_stack_allocate (ClutterActor *self,
|
2020-05-09 15:30:26 -04:00
|
|
|
const ClutterActorBox *box)
|
2009-06-29 12:51:10 -04:00
|
|
|
{
|
2011-04-06 12:53:19 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
|
|
|
ClutterActorBox content_box;
|
2012-02-16 13:40:31 -05:00
|
|
|
ClutterActor *child;
|
2009-06-29 12:51:10 -04:00
|
|
|
|
2020-05-09 15:30:26 -04:00
|
|
|
clutter_actor_set_allocation (self, box);
|
2009-08-26 23:15:47 -04:00
|
|
|
|
2011-04-06 12:53:19 -04:00
|
|
|
st_theme_node_get_content_box (theme_node, box, &content_box);
|
2009-06-29 12:51:10 -04:00
|
|
|
|
2012-02-16 13:40:31 -05:00
|
|
|
for (child = clutter_actor_get_first_child (self);
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2009-06-29 12:51:10 -04:00
|
|
|
{
|
2011-04-06 12:53:19 -04:00
|
|
|
ClutterActorBox child_box = content_box;
|
2020-05-09 15:30:26 -04:00
|
|
|
clutter_actor_allocate (child, &child_box);
|
2009-06-29 12:51:10 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_stack_get_preferred_height (ClutterActor *actor,
|
|
|
|
gfloat for_width,
|
|
|
|
gfloat *min_height_p,
|
|
|
|
gfloat *natural_height_p)
|
|
|
|
{
|
2011-04-06 12:53:19 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-06-29 12:51:10 -04:00
|
|
|
gboolean first = TRUE;
|
|
|
|
float min = 0, natural = 0;
|
2012-02-16 13:40:31 -05:00
|
|
|
ClutterActor *child;
|
2009-06-29 12:51:10 -04:00
|
|
|
|
2011-04-06 12:53:19 -04:00
|
|
|
st_theme_node_adjust_for_width (theme_node, &for_width);
|
|
|
|
|
2012-02-16 13:40:31 -05:00
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2009-06-29 12:51:10 -04:00
|
|
|
{
|
|
|
|
float child_min, child_natural;
|
|
|
|
|
|
|
|
clutter_actor_get_preferred_height (child,
|
|
|
|
for_width,
|
|
|
|
&child_min,
|
|
|
|
&child_natural);
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = FALSE;
|
|
|
|
min = child_min;
|
|
|
|
natural = child_natural;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (child_min > min)
|
|
|
|
min = child_min;
|
|
|
|
|
|
|
|
if (child_natural > natural)
|
|
|
|
natural = child_natural;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_height_p)
|
|
|
|
*min_height_p = min;
|
|
|
|
|
|
|
|
if (natural_height_p)
|
|
|
|
*natural_height_p = natural;
|
|
|
|
|
2011-04-06 12:53:19 -04:00
|
|
|
st_theme_node_adjust_preferred_height (theme_node, min_height_p, natural_height_p);
|
2009-06-29 12:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_stack_get_preferred_width (ClutterActor *actor,
|
|
|
|
gfloat for_height,
|
|
|
|
gfloat *min_width_p,
|
|
|
|
gfloat *natural_width_p)
|
|
|
|
{
|
2011-04-06 12:53:19 -04:00
|
|
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (actor));
|
2009-06-29 12:51:10 -04:00
|
|
|
gboolean first = TRUE;
|
|
|
|
float min = 0, natural = 0;
|
2012-02-16 13:40:31 -05:00
|
|
|
ClutterActor *child;
|
2009-06-29 12:51:10 -04:00
|
|
|
|
2011-04-06 12:53:19 -04:00
|
|
|
st_theme_node_adjust_for_height (theme_node, &for_height);
|
|
|
|
|
2012-02-16 13:40:31 -05:00
|
|
|
for (child = clutter_actor_get_first_child (actor);
|
|
|
|
child != NULL;
|
|
|
|
child = clutter_actor_get_next_sibling (child))
|
2009-06-29 12:51:10 -04:00
|
|
|
{
|
|
|
|
float child_min, child_natural;
|
|
|
|
|
|
|
|
clutter_actor_get_preferred_width (child,
|
|
|
|
for_height,
|
|
|
|
&child_min,
|
|
|
|
&child_natural);
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
first = FALSE;
|
|
|
|
min = child_min;
|
|
|
|
natural = child_natural;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (child_min > min)
|
|
|
|
min = child_min;
|
|
|
|
|
|
|
|
if (child_natural > natural)
|
|
|
|
natural = child_natural;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_width_p)
|
|
|
|
*min_width_p = min;
|
|
|
|
|
|
|
|
if (natural_width_p)
|
|
|
|
*natural_width_p = natural;
|
2011-04-06 12:53:19 -04:00
|
|
|
|
|
|
|
st_theme_node_adjust_preferred_width (theme_node, min_width_p, natural_width_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
shell_stack_navigate_focus (StWidget *widget,
|
|
|
|
ClutterActor *from,
|
2018-11-27 07:58:25 -05:00
|
|
|
StDirectionType direction)
|
2011-04-06 12:53:19 -04:00
|
|
|
{
|
|
|
|
ClutterActor *top_actor;
|
|
|
|
|
|
|
|
/* If the stack is itself focusable, then focus into or out of
|
|
|
|
* it, as appropriate.
|
|
|
|
*/
|
|
|
|
if (st_widget_get_can_focus (widget))
|
|
|
|
{
|
|
|
|
if (from && clutter_actor_contains (CLUTTER_ACTOR (widget), from))
|
|
|
|
return FALSE;
|
|
|
|
|
2015-07-22 09:43:12 -04:00
|
|
|
if (clutter_actor_is_mapped (CLUTTER_ACTOR (widget)))
|
2012-09-06 16:12:44 -04:00
|
|
|
{
|
|
|
|
clutter_actor_grab_key_focus (CLUTTER_ACTOR (widget));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-04-06 12:53:19 -04:00
|
|
|
}
|
|
|
|
|
2012-02-16 13:40:31 -05:00
|
|
|
top_actor = clutter_actor_get_last_child (CLUTTER_ACTOR (widget));
|
2020-02-19 11:30:15 -05:00
|
|
|
while (top_actor && !clutter_actor_is_visible (top_actor))
|
|
|
|
top_actor = clutter_actor_get_previous_sibling (top_actor);
|
2011-04-06 12:53:19 -04:00
|
|
|
if (ST_IS_WIDGET (top_actor))
|
|
|
|
return st_widget_navigate_focus (ST_WIDGET (top_actor), from, direction, FALSE);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2009-06-29 12:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_stack_class_init (ShellStackClass *klass)
|
|
|
|
{
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2011-04-06 12:53:19 -04:00
|
|
|
StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
|
2009-06-29 12:51:10 -04:00
|
|
|
|
|
|
|
actor_class->get_preferred_width = shell_stack_get_preferred_width;
|
|
|
|
actor_class->get_preferred_height = shell_stack_get_preferred_height;
|
|
|
|
actor_class->allocate = shell_stack_allocate;
|
2011-04-06 12:53:19 -04:00
|
|
|
|
|
|
|
widget_class->navigate_focus = shell_stack_navigate_focus;
|
2009-06-29 12:51:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_stack_init (ShellStack *actor)
|
|
|
|
{
|
|
|
|
}
|