/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   This program is free software; you can redistribute it and/or 
 *   modify it under the terms of the GNU General Public Rules as 
 *   published by the Free Software Foundation; either version 2 of 
 *   the Rules, or (at your option) any later version.
 *
 *   This program 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 General Public Rules for more details. 
 *   You can find this license in the file 'gpl.txt'.
 *
 *   You should have received a copy of the GNU General Public Rules
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *   MA  02111-1307  USA
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 **********************************************************************/

#ifdef USE_UI_GTKMM

#include "card_selector.h"

#include "ui.h"
#include "translations.h"

#include "../../card/card.h"

#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/button.h>
#include <gtkmm/alignment.h>

namespace UI_GTKMM_NS {

  /**
   ** Constructor
   **
   ** @param	parent		parent widget
   ** @param	description	description for the label
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  CardSelector::CardSelector(Base* const parent,
			     Translator::Translation const& description) :
    HBox(false),
    Base(parent),
    label_(),
    button_("")
  { 
    this->set_spacing(10);

    Gtk::Alignment* alignment
      = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER,
				       0, 0));
    alignment->add(this->label());
    this->pack_start(*alignment, true, true);
    this->pack_end(this->button(), false, true);

    this->ui->translations->add(this->label(), description + ": ");
    this->ui->translations->add(this->button(), ::translator(""));
    this->button().set_data("card", new Card());

    this->show_all();
  } // CardSelector::CardSelector(Base* parent, Translator description)

  /**
   ** Destructor
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  CardSelector::~CardSelector()
  {
    delete static_cast<Card*>(this->button().steal_data("card"));
  }


  /**
   ** -> result
   **
   ** @param	-
   **
   ** @return	the label
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  Gtk::Label&
    CardSelector::label()
    {
      return this->label_;
    }

  /**
   ** -> result
   **
   ** @param	-
   **
   ** @return	the button
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  Gtk::Button&
    CardSelector::button()
    {
      return this->button_;
    }

  /**
   ** -> result
   **
   ** @param	-
   **
   ** @return	the selected card
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  Card
    CardSelector::card()
    {
      return *static_cast<Card*>(this->button().get_data("card"));
    }

  /**
   ** sets the selected card
   **
   ** @param	card	new selected card
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.8
   **
   **/
  void
    CardSelector::set_card(Card const& card)
    {
      this->ui->translations->change(this->button(),
				     ::translator(::name(card)));
      delete static_cast<Card*>(this->button().steal_data("card"));
      this->button().set_data("card", new Card(card));
      return ;
    } // void CardSelector::set_card(Card const& card)

} // namespace UI_GTKMM_NS

#endif // #ifdef USE_UI_GTKMM
