/**********************************************************************
 *
 *   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 License as 
 *   published by the Free Software Foundation; either version 2 of 
 *   the License, 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 License for more details. 
 *   You can find this license in the file 'gpl.txt'.
 *
 *   You should have received a copy of the GNU General Public License
 *   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
 *
 *********************************************************************/

#include "constants.h"

#ifdef USE_UI_GTKMM

#include "swines_info.h"
#include "table.h"
#include "ui.h"
#include "icons.h"

#include "../../game/game.h"
#include "../../player/player.h"
#include "../../misc/setting.h"

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

namespace UI_GTKMM_NS {

  // position of the window
  int SwinesInfo::position_x = INT_MAX;
  int SwinesInfo::position_y = INT_MAX;

  /**
   **
   ** Constructor
   **
   ** @param	table	the table
   ** @param	player	the player who has swines
   **
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  SwinesInfo::SwinesInfo(Table* const table, Player const& player) :
    GameinfoDialog(table),
  icon(NULL),
  text(NULL),
  player(&player)
  {
    DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		  "SwinesInfo::SwinesInfo(table, player)");

    DEBUG_RETURNING(VOID,
		    INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		    "SwinesInfo::SwinesInfo(table, player)");
  } // SwinesInfo::SwinesInfo(Table* const table, Player const& player)

  /**
   **
   ** Destruktor
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  SwinesInfo::~SwinesInfo()
  {
    DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		  "SwinesInfo::~SwinesInfo()");

    DEBUG_RETURNING(VOID,
		    INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		    "SwinesInfo::~SwinesInfo()");
  } // SwinesInfo::~SwinesInfo()

  /**
   **
   ** init the dialog
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  void
    SwinesInfo::init()
    {
      DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		    "SwinesInfo::init()");

      this->GameinfoDialog::init();
      this->ui->add_for_translation(*this,
				    ::translator("Swines"));

      this->icon = Gtk::manage(new Gtk::Image(this->ui->icons->swines(this->player->game().trumpcolor())));
      this->text = Gtk::manage(new Gtk::Label("Player has swines."));
      this->ui->add_for_translation(*(this->text),
				    ::translator("%splayer% has swines.",
						 this->player->name()
						));

      Gtk::VBox* vbox = Gtk::manage(new Gtk::VBox(false, 20));
      vbox->set_border_width(20);

      vbox->add(*(this->icon));
      vbox->add(*(this->text));

      this->get_vbox()->add(*vbox);

      this->show_all_children();

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_SWINES_INFO && INFO_GTKMM_INIT,
		      "SwinesInfo::init()");
    } // void SwinesInfo::init()

  /**
   **
   ** show the window
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  void
    SwinesInfo::show_information()
    {
      DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_GAMEPLAY,
		    "SwinesInfo::show_information()");

      this->GameinfoDialog::show_information(::setting(Setting::SHOW_SWINES_WINDOW),
					     ::setting(Setting::CLOSE_SWINES_WINDOW_AUTOMATICALLY),
					     ::setting(Setting::SWINES_WINDOW_CLOSE_DELAY));

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_SWINES_INFO && INFO_GTKMM_GAMEPLAY,
		      "SwinesInfo::show_information()");
    } // void SwinesInfo::show_information()

  /**
   **
   ** the name of 'player' has changed
   **
   ** @param	player	the player whose name has changed
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  void
    SwinesInfo::name_changed(Player const& player)
    {
      DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_UPDATE,
		    "SwinesInfo::name_changed(player)");

      if (player == *(this->player))
	this->ui->change_translation(*(this->text),
				     ::translator("%splayer% has swines.",
						  this->player->name()
						 ));

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_SWINES_INFO && INFO_GTKMM_UPDATE,
		      "SwinesInfo::name_changed(player)");
    } // void SwinesInfo::name_changed(Player const& player)

  /**
   **
   ** update the icons
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  void
    SwinesInfo::icons_update()
    {
      DEBUG_CALLING(INFO_GTKMM_SWINES_INFO && INFO_GTKMM_UPDATE,
		    "SwinesInfo::icons_update()");

      this->icon->set(this->ui->icons->swines(this->player->game().trumpcolor()));

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_SWINES_INFO && INFO_GTKMM_UPDATE,
		      "SwinesInfo::icons_update()");
    } // void SwinesInfo::icons_update()

  /**
   **
   ** save the position of the window
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    SwinesInfo::save_position()
    {
      // Note: 'Gtk::Window::get_position()' does not give the actual position
      this->get_window()->get_root_origin(this->position_x, this->position_y);

      return ;
    } // void SwinesInfo::save_position()

  /**
   **
   ** move the window to the last position
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    SwinesInfo::move_to_last_position()
    {
      if (this->position_x != INT_MAX)
	this->move(this->position_x, this->position_y);

      return ;
    } // void SwinesInfo::move_to_last_position()

} // namespace UI_GTKMM_NS

#endif // #ifdef USE_UI_GTKMM
