<commit_before>/**
 * SECTION:clutter-box
 * @short_description: A Generic layout container
 *
 * #ClutterBox is a FIXME
 *
 * #ClutterBox is available since Clutter 1.2
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "clutter-box.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-marshal.h"
#include "clutter-private.h"

#define CLUTTER_BOX_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BOX, ClutterBoxPrivate))

struct _ClutterBoxPrivate
{
  ClutterLayoutManager *manager;

  GList *children;

  guint changed_id;
};

enum
{
  PROP_0,

  PROP_LAYOUT_MANAGER
};

static void clutter_container_iface_init (ClutterContainerIface *iface);

G_DEFINE_TYPE_WITH_CODE (ClutterBox, clutter_box, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
                                                clutter_container_iface_init));

static gint
sort_by_depth (gconstpointer a,
               gconstpointer b)
{
  gfloat depth_a = clutter_actor_get_depth ((ClutterActor *) a);
  gfloat depth_b = clutter_actor_get_depth ((ClutterActor *) b);

  if (depth_a < depth_b)
    return -1;

  if (depth_a > depth_b)
    return 1;

  return 0;
}

static void
clutter_box_real_add (ClutterContainer *container,
                      ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_insert_sorted (priv->children,
                                         actor,
                                         sort_by_depth);

  clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));
  clutter_actor_queue_relayout (actor);

  g_signal_emit_by_name (container, "actor-added", actor);

  g_object_unref (actor);
}

static void
clutter_box_real_remove (ClutterContainer *container,
                         ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_remove (priv->children, actor);
  clutter_actor_unparent (actor);

  clutter_actor_queue_relayout (CLUTTER_ACTOR (container));

  g_signal_emit_by_name (container, "actor-removed", actor);

  g_object_unref (actor);
}

static void
clutter_box_real_foreach (ClutterContainer *container,
                          ClutterCallback   callback,
                          gpointer          user_data)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;
  GList *l;

  for (l = priv->children; l != NULL; l = l->next)
    (* callback) (l->data, user_data);
}

static void
clutter_box_real_raise (ClutterContainer *container,
                        ClutterActor     *actor,
                        ClutterActor     *sibling)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;<commit_msg>[layout] Bind the layout ChildMeta inside Box<commit_after>/**
 * SECTION:clutter-box
 * @short_description: A Generic layout container
 *
 * #ClutterBox is a FIXME
 *
 * #ClutterBox is available since Clutter 1.2
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "clutter-box.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-marshal.h"
#include "clutter-private.h"

#define CLUTTER_BOX_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BOX, ClutterBoxPrivate))

struct _ClutterBoxPrivate
{
  ClutterLayoutManager *manager;

  GList *children;

  guint changed_id;
};

enum
{
  PROP_0,

  PROP_LAYOUT_MANAGER
};

static void clutter_container_iface_init (ClutterContainerIface *iface);

G_DEFINE_TYPE_WITH_CODE (ClutterBox, clutter_box, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
                                                clutter_container_iface_init));

static gint
sort_by_depth (gconstpointer a,
               gconstpointer b)
{
  gfloat depth_a = clutter_actor_get_depth ((ClutterActor *) a);
  gfloat depth_b = clutter_actor_get_depth ((ClutterActor *) b);

  if (depth_a < depth_b)
    return -1;

  if (depth_a > depth_b)
    return 1;

  return 0;
}

static void
clutter_box_real_add (ClutterContainer *container,
                      ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_insert_sorted (priv->children,
                                         actor,
                                         sort_by_depth);

  clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));

  clutter_layout_manager_add_child_meta (priv->manager,
                                         container,
                                         actor);

  clutter_actor_queue_relayout (actor);

  g_signal_emit_by_name (container, "actor-added", actor);

  g_object_unref (actor);
}

static void
clutter_box_real_remove (ClutterContainer *container,
                         ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_remove (priv->children, actor);
  clutter_actor_unparent (actor);

  clutter_layout_manager_remove_child_meta (priv->manager,
                                            container,
                                            actor);

  clutter_actor_queue_relayout (CLUTTER_ACTOR (container));

  g_signal_emit_by_name (container, "actor-removed", actor);

  g_object_unref (actor);
}

static void
clutter_box_real_foreach (ClutterContainer *container,
                          ClutterCallback   callback,
                          gpointer          user_data)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;
  GList *l;

  for (l = priv->children; l != NULL; l = l->next)
    (* callback) (l->data, user_data);
}

static void
clutter_box_real_raise (ClutterContainer *container,
                        ClutterActor     *actor,
                        ClutterActor     *sibling)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;
{'fraction_non_alphanumeric': 0.09015025041736227, 'fraction_numerical': 0.002003338898163606, 'mean_word_length': 2.749061326658323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4853345', 'n_tokens_mistral': 1928, 'n_tokens_neox': 1878, 'n_words': 385}