/*
 * Copyright 1998-2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <gtk/gtk.h>
#include <gtkmm/adjustment.h>
#include <gtkmm/label.h>
#include <gtkmm/box.h>
#include <gtkmm/image.h>

namespace Gtk
{


void
Bin::remove()
{
  GtkWidget* child = gtk_bin_get_child(gobj());
  if(child)
  {
    Gtk::Widget* cppChild = Glib::wrap(child);

    //If this is a managed widget, then do an extra ref so that it will not be
    //destroyed when it is removed, and restore the floating state of the ref.
    //This should leave it in the same state as when it was instantiated,
    //before being added to the first container.
    if(cppChild->is_managed_())
    {
      cppChild->reference();
      g_object_force_floating(static_cast<Glib::Object*>(cppChild)->gobj());
    }

    gtk_container_remove(Container::gobj(), cppChild->gobj());
  }
}

void
Bin::add_label(const Glib::ustring& str, bool mnemonic /* = false */,
	             double x_align /* = 0.5 */, double y_align /* = 0.5 */)
{
  Label* label = manage(new Label(str, x_align, y_align, mnemonic));
  add(*label);

  //This might not always be appropriate:
  //because maybe the mnemonic widget should be another child widget.
  //if(mnemonic)
    //label->set_mnemonic_widget(*this);

  label->show();
}

void
Bin::add_label(const Glib::ustring& str, bool mnemonic,
	       Align x_align, Align y_align /* = ALIGN_CENTER */)
{
  add_label(str, mnemonic,
	    _gtkmm_align_float_from_enum(x_align),
	    _gtkmm_align_float_from_enum(y_align));
}

void
Bin::add_pixlabel(const std::string& pixfile,
		  const Glib::ustring& str,
		  double x_align /* = 0.5 */, double y_align /* = 0.5 */)
{
  //Create Image and Label widgets:
  Image* pmap = manage(new Image(pixfile));
  Label* label = manage(new Label(str));
  label->set_alignment (x_align, y_align);

  //Put them in a Box:
  Box* hbox = manage(new Box(ORIENTATION_HORIZONTAL, 5));
  hbox->pack_start(*pmap, PACK_SHRINK);
  hbox->pack_start(*label);
  hbox->show_all();

  //And put that Box in this:
  add(*hbox);
}


} //namespace Gtk
