* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include "gtkcontainer.h"
+#include "gtkbuildable.h"
#include "gtkprivate.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
GtkWidget *child);
+/* GtkBuildable */
+static void gtk_container_buildable_init (GtkBuildableIface *iface);
+static void gtk_container_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type);
+static gboolean gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ GMarkupParser *parser,
+ gpointer *data);
+static void gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ gpointer *data);
+
/* --- variables --- */
static const gchar vadjustment_key[] = "gtk-vadjustment";
static GtkWidgetClass *parent_class = NULL;
extern GParamSpecPool *_gtk_widget_child_property_pool;
extern GObjectNotifyContext *_gtk_widget_child_property_notify_context;
+static GtkBuildableIface *parent_buildable_iface;
/* --- functions --- */
NULL, /* value_table */
};
+ static const GInterfaceInfo buildable_info =
+ {
+ (GInterfaceInitFunc) gtk_container_buildable_init,
+ NULL,
+ NULL
+ };
+
container_type =
g_type_register_static (GTK_TYPE_WIDGET, I_("GtkContainer"),
&container_info, G_TYPE_FLAG_ABSTRACT);
+
+ g_type_add_interface_static (container_type,
+ GTK_TYPE_BUILDABLE,
+ &buildable_info);
+
}
return container_type;
GTK_TYPE_WIDGET);
}
+static void
+gtk_container_buildable_init (GtkBuildableIface *iface)
+{
+ parent_buildable_iface = g_type_interface_peek_parent (iface);
+ iface->add_child = gtk_container_buildable_add_child;
+ iface->custom_tag_start = gtk_container_buildable_custom_tag_start;
+ iface->custom_tag_end = gtk_container_buildable_custom_tag_end;
+}
+
+static void
+gtk_container_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type)
+{
+ g_return_if_fail (GTK_IS_WIDGET (child));
+
+ gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+}
+
+static void
+gtk_container_buildable_set_child_property (GtkContainer *container,
+ GtkBuilder *builder,
+ GtkWidget *child,
+ gchar *name,
+ const gchar *value)
+{
+ GParamSpec *pspec;
+ GValue gvalue = { 0, };
+ GError *error = NULL;
+
+ pspec = gtk_container_class_find_child_property
+ (G_OBJECT_GET_CLASS (container), name);
+ if (!pspec)
+ {
+ g_warning ("%s does not have a property called %s",
+ g_type_name (G_OBJECT_TYPE (container)), name);
+ return;
+ }
+
+ if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
+ {
+ g_warning ("Could not read property %s:%s with value %s of type %s: %s",
+ g_type_name (G_OBJECT_TYPE (container)),
+ name,
+ value,
+ g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
+ error->message);
+ g_error_free (error);
+ return;
+ }
+
+ gtk_container_child_set_property (container, child, name, &gvalue);
+ g_value_unset (&gvalue);
+}
+
+typedef struct {
+ GtkBuilder *builder;
+ GtkContainer *container;
+ GtkWidget *child;
+ gchar *child_prop_name;
+} PackingPropertiesData;
+
+static void
+attributes_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **names,
+ const gchar **values,
+ gpointer user_data,
+ GError **error)
+{
+ PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
+ guint i;
+
+ if (strcmp (element_name, "property") == 0)
+ for (i = 0; names[i]; i++)
+ if (strcmp (names[i], "name") == 0)
+ parser_data->child_prop_name = g_strdup (values[i]);
+ else if (strcmp (element_name, "packing") == 0)
+ return;
+ else
+ g_warning ("Unsupported tag for GtkContainer: %s\n", element_name);
+}
+
+static void
+attributes_text_element (GMarkupParseContext *context,
+ const gchar *text,
+ gsize text_len,
+ gpointer user_data,
+ GError **error)
+{
+ PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
+
+ if (!parser_data->child_prop_name)
+ return;
+
+ gtk_container_buildable_set_child_property (parser_data->container,
+ parser_data->builder,
+ parser_data->child,
+ parser_data->child_prop_name,
+ text);
+
+ g_free (parser_data->child_prop_name);
+ parser_data->child_prop_name = NULL;
+}
+
+static const GMarkupParser attributes_parser =
+ {
+ attributes_start_element,
+ NULL,
+ attributes_text_element,
+ };
+
+static gboolean
+gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ GMarkupParser *parser,
+ gpointer *data)
+{
+ PackingPropertiesData *parser_data;
+
+ if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
+ tagname, parser, data))
+ return TRUE;
+
+ if (child && strcmp (tagname, "packing") == 0)
+ {
+ parser_data = g_slice_new0 (PackingPropertiesData);
+ parser_data->builder = builder;
+ parser_data->container = GTK_CONTAINER (buildable);
+ parser_data->child = GTK_WIDGET (child);
+ parser_data->child_prop_name = NULL;
+
+ *parser = attributes_parser;
+ *data = parser_data;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *tagname,
+ gpointer *data)
+{
+ if (strcmp (tagname, "packing") == 0)
+ {
+ g_slice_free (PackingPropertiesData, (gpointer)data);
+ return;
+
+ }
+
+ if (parent_buildable_iface->custom_tag_end)
+ parent_buildable_iface->custom_tag_end (buildable, builder,
+ child, tagname, data);
+
+}
+
/**
* gtk_container_child_type:
* @container: a #GtkContainer
* @container: a #GtkContainer
* @child: a widget which is a child of @container
* @first_property_name: the name of the first property to get
- * @var_args: a %NULL-terminated list of property names and #GValue*,
- * starting with @first_prop_name.
+ * @var_args: return location for the first property, followed
+ * optionally by more name/return location pairs, followed by %NULL
*
* Gets the values of one or more child properties for @child and @container.
**/
g_return_if_fail (GTK_IS_CONTAINER (container));
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (widget->parent == NULL);
+ g_return_if_fail (widget->parent == container);
g_object_ref (container);
g_object_ref (widget);
* @container: a #GtkContainer
* @child: a widget which is a child of @container
* @first_prop_name: the name of the first property to get
- * @Varargs: a %NULL-terminated list of property names and #GValue*,
- * starting with @first_prop_name
+ * @Varargs: return location for the first property, followed
+ * optionally by more name/return location pairs, followed by %NULL
*
* Gets the values of one or more child properties for @child and @container.
**/
* #GtkWindow; because toplevel windows can't leave space outside,
* they leave the space inside. The border is added on all sides of
* the container. To add space to only one side, one approach is to
- * create a #GtkAlignment widget, call gtk_widget_set_usize() to give
- * it a size, and place it on the side of the container as a spacer.
+ * create a #GtkAlignment widget, call gtk_widget_set_size_request()
+ * to give it a size, and place it on the side of the container as
+ * a spacer.
**/
void
gtk_container_set_border_width (GtkContainer *container,
{
g_warning ("Attempting to add a widget with type %s to a container of "
"type %s, but the widget is already inside a container of type %s, "
- "the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget.",
+ "the GTK+ FAQ at http://library.gnome.org/devel/gtk-faq/stable/ "
+ "explains how to reparent a widget.",
g_type_name (G_OBJECT_TYPE (widget)),
g_type_name (G_OBJECT_TYPE (container)),
g_type_name (G_OBJECT_TYPE (widget->parent)));
GtkCallback callback,
GtkCallbackMarshal marshal,
gpointer callback_data,
- GtkDestroyNotify notify)
+ GDestroyNotify notify)
{
g_return_if_fail (GTK_IS_CONTAINER (container));
notify (callback_data);
}
+/**
+ * gtk_container_set_focus_child:
+ * @container: a #GtkContainer
+ * @widget: a #GtkWidget, or %NULL
+ *
+ * Sets, or unsets if @widget is %NULL, the focused child of @container.
+ *
+ * This function emits the GtkContainer::set_focus_child signal of
+ * @container. Implementations of #GtkContainer can override the
+ * default behaviour by overriding the class closure of this signal.
+ */
void
gtk_container_set_focus_child (GtkContainer *container,
GtkWidget *widget)
g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, widget);
}
+/**
+ * gtk_container_get_focus_child:
+ * @container: a #GtkContainer
+ *
+ * Returns the current focus child widget inside @container.
+ *
+ * Returns: The child widget which has the focus
+ * inside @container, or %NULL if none is set.
+ *
+ * Since: 2.14
+ **/
+GtkWidget *
+gtk_container_get_focus_child (GtkContainer *container)
+{
+ g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
+
+ return container->focus_child;
+}
+
/**
* gtk_container_get_children:
* @container: a #GtkContainer
{
GtkWidget *widget = GTK_WIDGET (container);
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
-
- if (toplevel && GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->focus_widget)
+
+ if (GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->focus_widget)
{
GtkWidget *old_focus = GTK_WINDOW (toplevel)->focus_widget;
*
* Hooks up an adjustment to focus handling in a container, so when a child
* of the container is focused, the adjustment is scrolled to show that
- * widget. This function sets the horizontal alignment. See gt
- * k_scrolled_window_get_hadjustment() for a typical way of obtaining the
- * adjustment and gtk_container_set_focus_vadjustment() for setting
+ * widget. This function sets the horizontal alignment.
+ * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
+ * the adjustment and gtk_container_set_focus_vadjustment() for setting
* the vertical adjustment.
*
* The adjustments have to be in pixel units and in the same coordinate