* 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 "gtkbuilderprivate.h"
#include "gtkprivate.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
NULL, /* value_table */
};
- static const GInterfaceInfo buildable_info =
+ const GInterfaceInfo buildable_info =
{
(GInterfaceInitFunc) gtk_container_buildable_init,
NULL,
G_TYPE_NONE, 1,
GTK_TYPE_WIDGET);
container_signals[CHECK_RESIZE] =
- g_signal_new (I_("check_resize"),
+ g_signal_new (I_("check-resize"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkContainerClass, check_resize),
GObject *child,
const gchar *type)
{
- g_return_if_fail (GTK_IS_WIDGET (child));
-
- gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+ if (type)
+ {
+ GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
+ }
+ else if (GTK_IS_WIDGET (child) && GTK_WIDGET (child)->parent == NULL)
+ {
+ gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+ }
+ else
+ g_warning ("Cannot add an object of type %s to a container of type %s",
+ g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
}
static void
GtkContainer *container;
GtkWidget *child;
gchar *child_prop_name;
+ gchar *context;
+ gboolean translatable;
} PackingPropertiesData;
static void
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]);
+ {
+ for (i = 0; names[i]; i++)
+ if (strcmp (names[i], "name") == 0)
+ parser_data->child_prop_name = g_strdup (values[i]);
+ else if (strcmp (names[i], "translatable") == 0)
+ {
+ if (!_gtk_builder_boolean_from_string (values[1],
+ &parser_data->translatable,
+ error))
+ return;
+ }
+ else if (strcmp (names[i], "comments") == 0)
+ ; /* for translators */
+ else if (strcmp (names[i], "context") == 0)
+ parser_data->context = g_strdup (values[1]);
+ else
+ g_warning ("Unsupported attribute for GtkContainer Child "
+ "property: %s\n", names[i]);
+ }
else if (strcmp (element_name, "packing") == 0)
return;
else
GError **error)
{
PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
+ gchar* value;
if (!parser_data->child_prop_name)
return;
+
+ if (parser_data->translatable && text_len)
+ {
+ const gchar* domain;
+ domain = gtk_builder_get_translation_domain (parser_data->builder);
+
+ value = _gtk_builder_parser_translate (domain,
+ parser_data->context,
+ text);
+ }
+ else
+ {
+ value = g_strdup (text);
+ }
gtk_container_buildable_set_child_property (parser_data->container,
parser_data->builder,
parser_data->child,
parser_data->child_prop_name,
- text);
+ value);
g_free (parser_data->child_prop_name);
+ g_free (parser_data->context);
+ g_free (value);
parser_data->child_prop_name = NULL;
+ parser_data->context = NULL;
+ parser_data->translatable = FALSE;
}
static const GMarkupParser attributes_parser =
* @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.
**/
* @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.
**/
gtk_container_destroy (GtkObject *object)
{
GtkContainer *container = GTK_CONTAINER (object);
-
+
if (GTK_CONTAINER_RESIZE_PENDING (container))
_gtk_container_dequeue_resize_handler (container);
*/
if (container->has_focus_chain)
gtk_container_unset_focus_chain (container);
-
+
gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
* #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)));
g_return_if_fail (GTK_IS_CONTAINER (container));
g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
- if (GTK_WIDGET_TOPLEVEL (container) &&
+ if (gtk_widget_is_toplevel (GTK_WIDGET (container)) &&
resize_mode == GTK_RESIZE_PARENT)
{
resize_mode = GTK_RESIZE_QUEUE;
if (resize_container)
{
if (GTK_WIDGET_VISIBLE (resize_container) &&
- (GTK_WIDGET_TOPLEVEL (resize_container) || GTK_WIDGET_REALIZED (resize_container)))
+ (gtk_widget_is_toplevel (GTK_WIDGET (resize_container)) || GTK_WIDGET_REALIZED (resize_container)))
{
switch (resize_container->resize_mode)
{
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
+ * @child: (allow-none): a #GtkWidget, or %NULL
+ *
+ * Sets, or unsets if @child 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)
+ GtkWidget *child)
{
g_return_if_fail (GTK_IS_CONTAINER (container));
- if (widget)
- g_return_if_fail (GTK_IS_WIDGET (widget));
+ if (child)
+ g_return_if_fail (GTK_IS_WIDGET (child));
+
+ g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, child);
+}
+
+/**
+ * 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);
- g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, widget);
+ return container->focus_child;
}
/**
* @container: a #GtkContainer
*
* Returns the container's non-internal children. See
- * gtk_container_forall() for details on what constitutes an "internal" child.
+ * gtk_container_forall() for details on what constitutes an "internal" child.
*
- * Return value: a newly-allocated list of the container's non-internal children.
+ * Return value: (element-type GtkWidget) (transfer container): a newly-allocated list of the container's non-internal children.
**/
GList*
gtk_container_get_children (GtkContainer *container)
_gtk_container_child_composite_name (GtkContainer *container,
GtkWidget *child)
{
+ gboolean composite_child;
+
g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
g_return_val_if_fail (child->parent == GTK_WIDGET (container), NULL);
- if (GTK_WIDGET_COMPOSITE_CHILD (child))
+ g_object_get (child, "composite-child", &composite_child, NULL);
+ if (composite_child)
{
static GQuark quark_composite_name = 0;
gchar *name;
{
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;
/**
* gtk_container_get_focus_chain:
* @container: a #GtkContainer
- * @focusable_widgets: location to store the focus chain of the
+ * @focusable_widgets: (element-type GtkWidget) (out) (transfer container): location
+ * to store the focus chain of the
* container, or %NULL. You should free this list
* using g_list_free() when you are done with it, however
* no additional reference count is added to the
* Retrieves the vertical focus adjustment for the container. See
* gtk_container_set_focus_vadjustment().
*
- * Return value: the vertical focus adjustment, or %NULL if
+ * Return value: (transfer none): the vertical focus adjustment, or %NULL if
* none has been set.
**/
GtkAdjustment *
* Retrieves the horizontal focus adjustment for the container. See
* gtk_container_set_focus_hadjustment ().
*
- * Return value: the horizontal focus adjustment, or %NULL if
+ * Return value: (transfer none): the horizontal focus adjustment, or %NULL if
* none has been set.
**/
GtkAdjustment *