/*
 * 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 <glibmm/wrap.h>


namespace Gtk
{

void Box::pack_start(Widget& child, PackOptions options)
{
  // Avoid using our custom code in this case:
  if (options == PackOptions::SHRINK) {
    return pack_start(child);
  }

  const bool expand = (options == PackOptions::EXPAND_PADDING) || (options == PackOptions::EXPAND_WIDGET);
  const bool fill = (options == PackOptions::EXPAND_WIDGET);

  child.property_hexpand() = expand;
  child.property_vexpand() = expand;
  child.property_halign() = fill ? Gtk::Align::FILL : Gtk::Align::START;
  child.property_valign() = fill ? Gtk::Align::FILL : Gtk::Align::START;

  gtk_box_pack_start(gobj(), child.gobj());
}

void Box::pack_end(Widget& child, PackOptions options)
{
  // Avoid using our custom code in this case:
  if (options == PackOptions::SHRINK) {
    return pack_end(child);
  }

  const bool expand = (options == PackOptions::EXPAND_PADDING) || (options == PackOptions::EXPAND_WIDGET);
  const bool fill = (options == PackOptions::EXPAND_WIDGET);

  child.property_hexpand() = expand;
  child.property_vexpand() = expand;
  child.property_halign() = fill ? Gtk::Align::FILL : Gtk::Align::END;
  child.property_valign() = fill ? Gtk::Align::FILL : Gtk::Align::END;

  gtk_box_pack_end(gobj(), child.gobj());
}

} //namespace Gtk
