Blame gtk/gtkbin.c

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