Ejemplo n.º 1
0
void
gjs_gtk_container_child_set_property (GtkContainer *container,
                                      GtkWidget    *child,
                                      const gchar  *property,
                                      const GValue *value)
{
    GParamSpec *pspec;

    pspec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (container),
                                                     property);
    if (pspec == NULL) {
      g_warning ("%s does not have a property called %s",
                 g_type_name (G_OBJECT_TYPE (container)), property);
      return;
    }

    if ((G_VALUE_TYPE (value) == G_TYPE_POINTER) &&
        (g_value_get_pointer (value) == NULL) &&
        !g_value_type_transformable (G_VALUE_TYPE (value), pspec->value_type)) {
        /* Set an empty value. This will happen when we set a NULL value from JS.
         * Since GJS doesn't know the GParamSpec for this property, it
         * will just put NULL into a G_TYPE_POINTER GValue, which will later
         * fail when trying to transform it to the GParamSpec's GType.
         */
        GValue null_value = G_VALUE_INIT;
        g_value_init (&null_value, pspec->value_type);
        gtk_container_child_set_property (container, child,
                                          property, &null_value);
        g_value_unset (&null_value);
    } else {
        gtk_container_child_set_property (container, child,
                                          property, value);
    }
}
Ejemplo n.º 2
0
static GParamSpec *
find_property (GtkInspectorPropEditor *editor)
{
  if (editor->priv->is_child_property)
    {
      GtkWidget *widget = GTK_WIDGET (editor->priv->object);
      GtkWidget *parent = gtk_widget_get_parent (widget);

      return mark_child_property (gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (parent), editor->priv->name));
    }

  return g_object_class_find_property (G_OBJECT_GET_CLASS (editor->priv->object), editor->priv->name);
}
Ejemplo n.º 3
0
void
container_set_child_property (GtkContainer *aParent,
			      GtkWidget *aChild,
			      const char *aProperty,
			      OOP aValue)
{
  GParamSpec *spec;
  GValue value = {0,};

  g_return_if_fail (GTK_WIDGET (aParent) ==
		    gtk_widget_get_parent (GTK_WIDGET (aChild)));

  spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (aParent),
						  aProperty);

  g_value_init (&value, spec->value_type);
  g_value_fill_from_oop (&value, aValue);
  gtk_container_child_set_property (aParent, aChild, aProperty, &value);
}
Ejemplo n.º 4
0
OOP
container_get_child_property (GtkContainer *aParent,
			      GtkWidget *aChild,
			      const char *aProperty)
{
  GParamSpec *spec;
  GValue result = {0,};

  g_return_val_if_fail (GTK_WIDGET (aParent) ==
		        gtk_widget_get_parent (GTK_WIDGET (aChild)),
			_gtk_vm_proxy->nilOOP);

  spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (aParent),
					          aProperty);

  g_value_init (&result, spec->value_type);
  gtk_container_child_get_property (aParent, aChild, aProperty, &result);
  return (g_value_convert_to_oop (&result));
}
Ejemplo n.º 5
0
static void
append_child_attrs_foreach (gpointer key, gpointer value, gpointer user_data)
{
    if (!value) {
	return;
    }

    GParamSpec *spec;
    GError *error = NULL;
    GValue gval = { 0 };

    GtkWidget *child = GTK_WIDGET (user_data);
    GtkWidget *parent = gtk_widget_get_parent (child);

    spec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (parent), (char *)key);
    if (!spec ||
        G_TYPE_FUNDAMENTAL (G_PARAM_SPEC_VALUE_TYPE (spec)) == G_TYPE_OBJECT) {
        return;
    }
#if 1
    g_print ("found child property %s.%s on %s\n",
             g_type_name (G_TYPE_FROM_INSTANCE (parent)),
             spec->name,
             g_type_name (G_TYPE_FROM_INSTANCE (child)));
#endif
    if (gtk_builder_value_from_string (NULL, spec,
				       g_value_get_string ((const GValue *)value),
				       &gval, &error)) {
        gtk_container_child_set_property (GTK_CONTAINER (parent), child,
                                          spec->name, &gval);
        g_value_unset (&gval);
    } else {
        g_print ("Error getting value_from_string: %s\n",
                 error->message);
	g_error_free (error);
    }
}
Ejemplo n.º 6
0
static void
transition_add_properties (AfTransition *transition,
                           va_list       args)
{
  const gchar *property_name;
  GObject *object, *child;

  property_name = va_arg (args, const gchar *);
  object = transition->object;
  child = transition->child;

  while (property_name)
    {
      GParamSpec *pspec;
      GValue to = { 0, };
      GValue func = { 0, };
      gchar *error = NULL;

      if (!child)
        pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
                                              property_name);
      else
        pspec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (object),
                                                         property_name);

      if (G_UNLIKELY (!pspec))
        {
          g_warning ("Property '%s' does not exist on object of class '%s'",
                     property_name, G_OBJECT_TYPE_NAME (object));
          break;
        }

      g_value_init (&to, pspec->value_type);
      G_VALUE_COLLECT (&to, args, 0, &error);

      if (error)
        {
          g_warning (error);
          g_free (error);
          break;
        }

      g_value_init (&func, G_TYPE_POINTER);
      G_VALUE_COLLECT (&func, args, 0, &error);

      if (error)
        {
          g_warning (error);
          g_free (error);
          break;
        }

      transition_add_property (transition, pspec, &to, 
		               (AfTypeTransformationFunc)g_value_get_pointer (&func));

      g_value_unset (&to);
      g_value_unset (&func);

      property_name = va_arg (args, const gchar *);
    }
}
Ejemplo n.º 7
0
PpgAnimation*
g_object_animatev (gpointer          object,
                   PpgAnimationMode  mode,
                   guint             duration_msec,
                   guint             frame_rate,
                   const gchar      *first_property,
                   va_list           args)
{
	PpgAnimation *animation;
	GObjectClass *klass;
	GObjectClass *pklass;
	const gchar *name;
	GParamSpec *pspec;
	GtkWidget *parent;
	GValue value = { 0 };
	gchar *error = NULL;
	GType type;
	GType ptype;

	g_return_val_if_fail(first_property != NULL, NULL);
	g_return_val_if_fail(mode < PPG_ANIMATION_LAST, NULL);

	name = first_property;
	type = G_TYPE_FROM_INSTANCE(object);
	klass = G_OBJECT_GET_CLASS(object);
	animation = g_object_new(PPG_TYPE_ANIMATION,
	                         "duration", duration_msec,
	                         "frame-rate", frame_rate ? frame_rate : 60,
	                         "mode", mode,
	                         "target", object,
	                         NULL);

	do {
		/*
		 * First check for the property on the object. If that does not exist
		 * then check if the object has a parent and look at its child
		 * properties (if its a GtkWidget).
		 */
		if (!(pspec = g_object_class_find_property(klass, name))) {
			if (!g_type_is_a(type, GTK_TYPE_WIDGET)) {
				g_critical("Failed to find property %s in %s",
				           name, g_type_name(type));
				goto failure;
			}
			if (!(parent = gtk_widget_get_parent(object))) {
				g_critical("Failed to find property %s in %s",
				           name, g_type_name(type));
				goto failure;
			}
			pklass = G_OBJECT_GET_CLASS(parent);
			ptype = G_TYPE_FROM_INSTANCE(parent);
			if (!(pspec = gtk_container_class_find_child_property(pklass, name))) {
				g_critical("Failed to find property %s in %s or parent %s",
				           name, g_type_name(type), g_type_name(ptype));
				goto failure;
			}
		}

		g_value_init(&value, pspec->value_type);
		G_VALUE_COLLECT(&value, args, 0, &error);
		if (error != NULL) {
			g_critical("Failed to retrieve va_list value: %s", error);
			g_free(error);
			goto failure;
		}

		ppg_animation_add_property(animation, pspec, &value);
		g_value_unset(&value);
	} while ((name = va_arg(args, const gchar *)));

	ppg_animation_start(animation);

	return animation;

failure:
	g_object_ref_sink(animation);
	g_object_unref(animation);
	return NULL;
}