Blame gtk/gtkbin.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
/*
Packit Service fb6fa5
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit Service fb6fa5
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit Service fb6fa5
 * files for a list of changes.  These files are distributed with
Packit Service fb6fa5
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * SECTION:gtkbin
Packit Service fb6fa5
 * @Short_description: A container with just one child
Packit Service fb6fa5
 * @Title: GtkBin
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The #GtkBin widget is a container with just one child.
Packit Service fb6fa5
 * It is not very useful itself, but it is useful for deriving subclasses,
Packit Service fb6fa5
 * since it provides common code needed for handling a single child widget.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Many GTK+ widgets are subclasses of #GtkBin, including #GtkWindow,
Packit Service fb6fa5
 * #GtkButton, #GtkFrame, #GtkHandleBox or #GtkScrolledWindow.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
#include "gtkbin.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
static void gtk_bin_add         (GtkContainer   *container,
Packit Service fb6fa5
			         GtkWidget      *widget);
Packit Service fb6fa5
static void gtk_bin_remove      (GtkContainer   *container,
Packit Service fb6fa5
			         GtkWidget      *widget);
Packit Service fb6fa5
static void gtk_bin_forall      (GtkContainer   *container,
Packit Service fb6fa5
				 gboolean	include_internals,
Packit Service fb6fa5
				 GtkCallback     callback,
Packit Service fb6fa5
				 gpointer        callback_data);
Packit Service fb6fa5
static GType gtk_bin_child_type (GtkContainer   *container);
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_ABSTRACT_TYPE (GtkBin, gtk_bin, GTK_TYPE_CONTAINER)
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_bin_class_init (GtkBinClass *class)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkContainerClass *container_class;
Packit Service fb6fa5
Packit Service fb6fa5
  container_class = (GtkContainerClass*) class;
Packit Service fb6fa5
Packit Service fb6fa5
  container_class->add = gtk_bin_add;
Packit Service fb6fa5
  container_class->remove = gtk_bin_remove;
Packit Service fb6fa5
  container_class->forall = gtk_bin_forall;
Packit Service fb6fa5
  container_class->child_type = gtk_bin_child_type;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_bin_init (GtkBin *bin)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gtk_widget_set_has_window (GTK_WIDGET (bin), FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  bin->child = NULL;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
static GType
Packit Service fb6fa5
gtk_bin_child_type (GtkContainer *container)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (!GTK_BIN (container)->child)
Packit Service fb6fa5
    return GTK_TYPE_WIDGET;
Packit Service fb6fa5
  else
Packit Service fb6fa5
    return G_TYPE_NONE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_bin_add (GtkContainer *container,
Packit Service fb6fa5
	     GtkWidget    *child)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkBin *bin = GTK_BIN (container);
Packit Service fb6fa5
Packit Service fb6fa5
  if (bin->child != NULL)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_warning ("Attempting to add a widget with type %s to a %s, "
Packit Service fb6fa5
                 "but as a GtkBin subclass a %s can only contain one widget at a time; "
Packit Service fb6fa5
                 "it already contains a widget of type %s",
Packit Service fb6fa5
                 g_type_name (G_OBJECT_TYPE (child)),
Packit Service fb6fa5
                 g_type_name (G_OBJECT_TYPE (bin)),
Packit Service fb6fa5
                 g_type_name (G_OBJECT_TYPE (bin)),
Packit Service fb6fa5
                 g_type_name (G_OBJECT_TYPE (bin->child)));
Packit Service fb6fa5
      return;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_widget_set_parent (child, GTK_WIDGET (bin));
Packit Service fb6fa5
  bin->child = child;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_bin_remove (GtkContainer *container,
Packit Service fb6fa5
		GtkWidget    *child)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkBin *bin = GTK_BIN (container);
Packit Service fb6fa5
  gboolean widget_was_visible;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (bin->child == child);
Packit Service fb6fa5
Packit Service fb6fa5
  widget_was_visible = gtk_widget_get_visible (child);
Packit Service fb6fa5
  
Packit Service fb6fa5
  gtk_widget_unparent (child);
Packit Service fb6fa5
  bin->child = NULL;
Packit Service fb6fa5
  
Packit Service fb6fa5
  /* queue resize regardless of gtk_widget_get_visible (container),
Packit Service fb6fa5
   * since that's what is needed by toplevels, which derive from GtkBin.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  if (widget_was_visible)
Packit Service fb6fa5
    gtk_widget_queue_resize (GTK_WIDGET (container));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_bin_forall (GtkContainer *container,
Packit Service fb6fa5
		gboolean      include_internals,
Packit Service fb6fa5
		GtkCallback   callback,
Packit Service fb6fa5
		gpointer      callback_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkBin *bin = GTK_BIN (container);
Packit Service fb6fa5
Packit Service fb6fa5
  if (bin->child)
Packit Service fb6fa5
    (* callback) (bin->child, callback_data);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_bin_get_child:
Packit Service fb6fa5
 * @bin: a #GtkBin
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Gets the child of the #GtkBin, or %NULL if the bin contains
Packit Service fb6fa5
 * no child widget. The returned widget does not have a reference
Packit Service fb6fa5
 * added, so you do not need to unref it.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: (transfer none): pointer to child of the #GtkBin
Packit Service fb6fa5
 **/
Packit Service fb6fa5
GtkWidget*
Packit Service fb6fa5
gtk_bin_get_child (GtkBin *bin)
Packit Service fb6fa5
{
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_BIN (bin), NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  return bin->child;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_BIN_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"