/* 
 * © 2008-2009 Sun Microsystems, Inc.
 *
 * 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 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _LF_TABVIEW_H_
#define _LF_TABVIEW_H_

#include "lf_view.h"

namespace mforms
{
namespace gtk
{

class TabViewImpl : public ViewImpl
{
  Gtk::Notebook *_nb;
  virtual Gtk::Widget *get_outer() const { return _nb; }
 protected:
  TabViewImpl(::mforms::TabView *self)
    : ViewImpl(self)
  {
    _nb = Gtk::manage(new Gtk::Notebook());
  }

  static bool create(::mforms::TabView *self)
  {
    return new TabViewImpl(self) != 0;
  }

  static void set_active_tab(::mforms::TabView *self, int index)
  {
    TabViewImpl* cb= self->get_data<TabViewImpl>();

    if ( cb)
    {
      cb->_nb->set_current_page(index);
    }
  }

  static int get_active_tab(::mforms::TabView *self)
  {
    TabViewImpl* cb= self->get_data<TabViewImpl>();

    return cb ? cb->_nb->get_current_page() : -1;
  }

  static int add_page(::mforms::TabView *self, ::mforms::View *page, const std::string& caption)
  {
    int page_index_after_insert = -1;
    TabViewImpl* cb= self->get_data<TabViewImpl>();

    if ( cb)
    {
      ViewImpl *widget_wrapper = page->get_data<ViewImpl>();
      if ( widget_wrapper )
      {
        page_index_after_insert = cb->_nb->append_page(*widget_wrapper->get_outer(), (Glib::ustring)caption);
        widget_wrapper->get_outer()->show();
      }
    }
    
    return page_index_after_insert;
  }

 public:
  static void init()
  {
    ::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();

    f->_tabview_impl.create         = &TabViewImpl::create;
    f->_tabview_impl.get_active_tab = &TabViewImpl::get_active_tab;
    f->_tabview_impl.set_active_tab = &TabViewImpl::set_active_tab;
    f->_tabview_impl.add_page       = &TabViewImpl::add_page;
  }
};

};
};

#endif
