/**********************************************************************
 *
 *   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 "marriage_info.h"
#include "table.h"
#include "ui.h"
#include "icons.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 MarriageInfo::position_x = INT_MAX;
  int MarriageInfo::position_y = INT_MAX;

  /**
   **
   ** Constructor
   **
   ** @param	table		the table
   ** @param	bridegroom	the player with the marriage
   ** @param	bride		the partner
   **
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.6.1
   **
   **/
  MarriageInfo::MarriageInfo(Table* const table,
			     Player const& bridegroom,
			     Player const& bride) :
    GameinfoDialog(table),
  icon(NULL),
  text(NULL),
  bridegroom(&bridegroom),
  bride(&bride)
  {
    DEBUG_CALLING(INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_INIT,
		  "MarriageInfo::MarriageInfo(table, bridegroom, bride)");

    DEBUG_RETURNING(VOID,
		    INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_INIT,
		    "MarriageInfo::MarriageInfo(table, bridegroom, bride)");
  } // MarriageInfo::MarriageInfo(Table* const table, Player const& bridegroom, Player const& bride)

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

    DEBUG_RETURNING(VOID,
		    INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_INIT,
		    "MarriageInfo::~MarriageInfo()");
  } // MarriageInfo::~MarriageInfo()

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

      this->GameinfoDialog::init();

      this->ui->add_for_translation(*this,
				    ::translator("Marriage"));

      this->icon = Gtk::manage(new Gtk::Image(this->ui->icons->icon(this->bridegroom->game().marriage_selector())));
      this->text = Gtk::manage(new Gtk::Label("Player marriages bride."));
      if (*(this->bridegroom) == *(this->bride))
	this->ui->add_for_translation(*(this->text),
				      ::translator("%splayer% has found no bride.",
						   this->bridegroom->name()
						  ));
      else
	this->ui->add_for_translation(*(this->text),
				      ::translator("%splayer% marries %sbride%.",
						   this->bridegroom->name().c_str(),
						   this->bride->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_MARRIAGE_INFO && INFO_GTKMM_INIT,
		      "MarriageInfo::init()");
    } // void MarriageInfo::init()

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

      this->GameinfoDialog::show_information(::setting(Setting::SHOW_MARRIAGE_WINDOW),
					     ::setting(Setting::CLOSE_MARRIAGE_WINDOW_AUTOMATICALLY),
					     ::setting(Setting::MARRIAGE_WINDOW_CLOSE_DELAY));

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_GAMEPLAY,
		      "MarriageInfo::show_information()");
    } // void MarriageInfo::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
    MarriageInfo::name_changed(Player const& player)
    {
      DEBUG_CALLING(INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_UPDATE,
		    "MarriageInfo::name_changed(player)");

      if ((player == *(this->bridegroom))
	  || (player == *(this->bride))) {
	if (*(this->bridegroom) == *(this->bride))
	  this->ui->change_translation(*(this->text),
				       ::translator("%splayer% has found no bride.",
						    this->bridegroom->name()
						   ));
	else
	  this->ui->change_translation(*(this->text),
				       ::translator("%splayer% marries %sbride%.",
						    this->bridegroom->name().c_str(),
						    this->bride->name()
						   ));
      }

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

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

      this->icon->set(this->ui->icons->icon(this->bridegroom->game().marriage_selector()));

      DEBUG_RETURNING(VOID,
		      INFO_GTKMM_MARRIAGE_INFO && INFO_GTKMM_UPDATE,
		      "MarriageInfo::icons_update()");
    } // void MarriageInfo::icons_update()

  /**
   **
   ** save the position of the window
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    MarriageInfo::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 MarriageInfo::save_position()

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

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

} // namespace UI_GTKMM_NS

#endif // #ifdef USE_UI_GTKMM
