/* 
 * © 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.
 */
/**
 * Implementation of the mforms tabview control for Windows.
 */

#include "stdafx.h"
#include "wf_tabview.h"

using namespace MySQL::Forms;

//--------------------------------------------------------------------------------------------------

TabViewImpl::TabViewImpl(::mforms::TabView *self)
  : ViewImpl(self)
{
}

//--------------------------------------------------------------------------------------------------

bool TabViewImpl::create(::mforms::TabView *self)
{
  TabViewImpl ^cb= gcnew TabViewImpl(self);

  if (cb != nullptr)
  {
    ViewImpl::create<TabControl>(self, cb);
    return true;
  }
  return false;
}

//--------------------------------------------------------------------------------------------------

void TabViewImpl::set_active_tab(::mforms::TabView *self, int index)
{
  TabViewImpl^ cb= (TabViewImpl^)ObjectImpl::FromUnmanaged(self);

  if (cb != nullptr)
  {
    cb->get_control<TabControl>()->SelectedIndex= index;
  }
}

//--------------------------------------------------------------------------------------------------

int TabViewImpl::get_active_tab(::mforms::TabView *self)
{
  TabViewImpl^ cb= (TabViewImpl^)ObjectImpl::FromUnmanaged(self);

  if (cb != nullptr)
  {
    return cb->get_control<TabControl>()->SelectedIndex;
  }
  return -1;
}

//--------------------------------------------------------------------------------------------------

int TabViewImpl::add_page(::mforms::TabView *self, ::mforms::View *page, const std::string& caption)
{
  TabViewImpl^ cb= (TabViewImpl^)ObjectImpl::FromUnmanaged(self);

  if (cb != nullptr)
  {
    ViewImpl^ view= (ViewImpl^)ObjectImpl::FromUnmanaged(page);
    page->set_resize_mode(::mforms::ResizeNone);
    TabPage^ tabPage= gcnew TabPage();

    Control^ control= view->get_control<Control>();
    control->Dock = DockStyle::Fill;
    control->BackColor= Color::Transparent;
    tabPage->Controls->Add(control);
    tabPage->Text= CppStringToNative(caption);

    cb->get_control<TabControl>()->TabPages->Add(tabPage);

    return cb->get_control<TabControl>()->TabPages->Count - 1;
  }
  return -1;
}

//--------------------------------------------------------------------------------------------------

