/**********************************************************************
 *
 *   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_GTK

#include "reservation.h"
#include "gtk_gui.h"
#include "main_window.h"
#include "playfield.h"

#include "../ui.h"

#include "../../party/party.h"
#include "../../game/game.h"
#include "../../card/hand.h"
#include "../../misc/language.h"

namespace GTK_DOKO {

  /*****************************************************************************
   *
   * Reservation::Reservation(Playfield* playfield_a)
   *
   * Parameters:	playfield_a - pointer to the playfield
   *
   * Result:	none
   * 
   * Version:	0.4.2
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  Reservation::Reservation(Playfield* playfield_a) :
    PlayfieldDialog(playfield_a, "Reservation"), // the base class
  notebook(gtk_notebook_new()),
  bookmark_default("reservation default"),
  bookmark_solo("solo"),
  game_type_p(),
  marriage_selector_p(),
  swines("swines"),
  hyperswines("hyperswines")
  {
    DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_INIT,
		  "Reservation::Reservation()");

    unsigned i;

    // the button
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(window())->action_area),
		      this->button_close);

    // the gametype
    this->game_type_p.push_back(new XGtkRadioButton(name(GAMETYPE::FIRST)));
    for (i = GAMETYPE::FIRST + 1; i <= GAMETYPE::LAST; i++)
      this->game_type_p.push_back(new XGtkRadioButton(this->button(GAMETYPE::FIRST),
						      name(GameType(i))));

    // the gametype
    this->marriage_selector_p.push_back(new XGtkRadioButton(name(MARRIAGE_SELECTOR::FIRST)));
    for (i = MARRIAGE_SELECTOR::FIRST + 1; i <= MARRIAGE_SELECTOR::LAST; i++)
      this->marriage_selector_p.push_back(new XGtkRadioButton(this->button(MARRIAGE_SELECTOR::FIRST),
							      name(MarriageSelector(i))));

    GtkWidget* alignment;

    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window())->vbox), this->notebook,
		       TRUE, TRUE, 10);

    GtkWidget* default_container = gtk_hbutton_box_new();

    GtkWidget* swines_container = gtk_vbutton_box_new();
    GtkWidget* marriage_container = gtk_vbutton_box_new();
    GtkWidget* normal_container = gtk_vbutton_box_new();
    GtkWidget* solo_container = gtk_table_new(4, 3, TRUE);

    gtk_container_add(GTK_CONTAINER(default_container), swines_container);
    gtk_container_add(GTK_CONTAINER(default_container), normal_container);
    gtk_container_add(GTK_CONTAINER(default_container), marriage_container);

    alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_container_add(GTK_CONTAINER(alignment), default_container);
    gtk_notebook_append_page(GTK_NOTEBOOK(this->notebook),
			     alignment,
			     this->bookmark_default.label());

    alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
    gtk_container_add(GTK_CONTAINER(alignment), solo_container);
    gtk_notebook_append_page(GTK_NOTEBOOK(this->notebook),
			     alignment,
			     this->bookmark_solo.label());

    { // the swines
      gtk_container_add(GTK_CONTAINER(swines_container),
			this->swines.widget());
      gtk_container_add(GTK_CONTAINER(swines_container),
			this->hyperswines.widget());
    } // the swines

    { // the marriage selectors
      for (i = MARRIAGE_SELECTOR::FIRST; i <= MARRIAGE_SELECTOR::LAST; i++)
	gtk_container_add(GTK_CONTAINER(marriage_container),
			  this->button(MarriageSelector(i)).widget());
    } // the marriage selectors

    { // the gametypes
      { // normal games
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::NORMAL).widget());
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::FIVE_NINES).widget());
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::SIX_KINGS).widget());
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::FOX_HIGHEST_TRUMP).widget());
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::POVERTY).widget());
	gtk_container_add(GTK_CONTAINER(normal_container),
			  this->button(GAMETYPE::MARRIAGE).widget());
      } // normal games

      { // solo games
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_CLUB).widget(),
				  0, 1, 0, 1);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_SPADE).widget(),
				  0, 1, 1, 2);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_HEART).widget(),
				  0, 1, 2, 3);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_DIAMOND).widget(),
				  0, 1, 3, 4);

	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_MEATLESS).widget(),
				  1, 2, 0, 1);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_JACK).widget(),
				  1, 2, 1, 2);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_QUEEN).widget(),
				  1, 2, 2, 3);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_KING).widget(),
				  1, 2, 3, 4);

	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_QUEEN_JACK).widget(),
				  2, 3, 0, 1);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_KING_JACK).widget(),
				  2, 3, 1, 2);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_KING_QUEEN).widget(),
				  2, 3, 2, 3);
	gtk_table_attach_defaults(GTK_TABLE(solo_container),
				  this->button(GAMETYPE::SOLO_KOEHLER).widget(),
				  2, 3, 3, 4);

	gtk_container_set_border_width(GTK_CONTAINER(solo_container), 20);
      } // solo games
    } // the gametypes

    gtk_widget_realize(this->window());

#ifndef RELEASE
#ifdef DKNOF
    { // test, whether all game-type-buttons are packed in a container
      unsigned i;
      for (i = GAMETYPE::FIRST; i <= GAMETYPE::LAST; i++) {
	if ((this->button(GameType(i)).widget()->parent == NULL)
	    && (GameType(i) != GAMETYPE::MARRIAGE_SOLO)
	    && (GameType(i) != GAMETYPE::GENSCHER))
	  cerr << "GTK_DOKO::GameTypes::GameTypes():\n"
	    << "  GameType '" << GameType(i) << "' not packed\n";
      }
    } // test, whether all game-type-buttons are packed in a container
#endif
#endif

    DEBUG_RETURNING(VOID,
		    INFO_GTK_RESERVATION && INFO_GTK_INIT,
		    "Reservation::Reservation()");
  } // Reservation::Reservation(Playfield* playfield_a)

  /*****************************************************************************
   *
   * void Reservation::init()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.4.2
   *
   * Description:	inits the reservation windows
   *
   ****************************************************************************/
  void
    Reservation::init()
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_INIT,
		    "Reservation::init()");

      this->PlayfieldDialog::init();

      for (unsigned i = GAMETYPE::FIRST; i <= GAMETYPE::LAST; i++)
	gtk_signal_connect(GTK_OBJECT(this->button(GameType(i)).widget()),
			   "toggled",
			   GTK_SIGNAL_FUNC(Reservation::change_game_type_event),
			   (gpointer)(new GameType(GameType(i))));

      gtk_signal_connect(GTK_OBJECT(this->button(GAMETYPE::MARRIAGE).widget()),
			 "toggled",
			 GTK_SIGNAL_FUNC(Reservation::marriage_toggle_event),
			 (gpointer)(this));

      gtk_window_set_transient_for(GTK_WINDOW(this->window()),
				   GTK_WINDOW(gui().main_window().window()));
      { // center the window
	int x, y, width, height, wwidth, wheight;

	gdk_window_get_geometry(gui().main_window().window()->window,
				&x, &y, &width, &height, NULL);
	gdk_window_get_size(this->window()->window, &wwidth, &wheight);
	gdk_window_move(this->window()->window,
			x + width / 2 - wwidth / 2, y + height / 2 - wheight / 2);
      } // center the window

      language_update();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_INIT,
		      "Reservation::init()");
    } // void Reservation::init()

  /*****************************************************************************
   *
   * void Reservation::sensitivity_update(Player const& player)
   *
   * Parameters:	player - player of the reservation
   *
   * Result:	none
   * 
   * Version:	0.4.2
   *
   * Description:	updates the sensitivity
   *
   ****************************************************************************/
  void
    Reservation::sensitivity_update(Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_INIT,
		    "Reservation::sensitivity_update()");

      unsigned i;

      ::Reservation const reservation = player.reservation_get_default();

      for (i = GAMETYPE::FIRST; i <= GAMETYPE::LAST; i++)
	if (::party.game().rule()(GameType(i)))
	  gtk_widget_show(this->button(GameType(i)).widget());
	else
	  gtk_widget_hide(this->button(GameType(i)).widget());

      for (i = MARRIAGE_SELECTOR::FIRST; i <= MARRIAGE_SELECTOR::LAST; i++) {
	if (::party.game().rule()(MarriageSelector(i)))
	  gtk_widget_show(this->button(MarriageSelector(i)).widget());
	else
	  gtk_widget_hide(this->button(MarriageSelector(i)).widget());

	if (reservation.marriage_selector == MarriageSelector(i))
	  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(MarriageSelector(i)).widget()), TRUE);
      } // for (i \in MARRIAGE_SELECTOR)


      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::NORMAL).widget()),
				   TRUE);

      if (::party.rule()(Rule::SWINES))
	gtk_widget_show(this->swines.widget());
      else
	gtk_widget_hide(this->swines.widget());
      gtk_widget_set_sensitive(this->swines.widget(),
			       (player.hand().numberoftrumpaces()
				== ::party.game().rule()(Rule::NUMBER_OF_SAME_CARDS)));


      if (::party.rule()(Rule::HYPERSWINES))
	gtk_widget_show(this->hyperswines.widget());
      else
	gtk_widget_hide(this->hyperswines.widget());
      gtk_widget_set_sensitive(this->hyperswines.widget(),
			       (player.hand().numberoftrumpnines()
				== ::party.game().rule()(Rule::NUMBER_OF_SAME_CARDS)));


      gtk_widget_set_sensitive(this->button(GAMETYPE::FIVE_NINES).widget(),
			       (player.hand().numberofnines()
				>= Rule::MIN_NUMBER_OF_THROWING_NINES));
      gtk_widget_set_sensitive(this->button(GAMETYPE::SIX_KINGS).widget(),
			       (player.hand().numberofkings()
				>= Rule::MIN_NUMBER_OF_THROWING_KINGS));
      { // look, whether there is a card that is higher than the fox
	unsigned c;
	for (c = 0; c < player.hand().cardsnumber(); c++)
	  if (Card(Card::DIAMOND, Card::ACE).less(player.hand().card(c),
						  player.game()))
	    break;
	gtk_widget_set_sensitive(this->button(GAMETYPE::FOX_HIGHEST_TRUMP).widget(),
				 (c == player.hand().cardsnumber()));
      } // look, whether there is a card that is higher than the fox
      gtk_widget_set_sensitive(this->button(GAMETYPE::POVERTY).widget(),
			       (player.hand().numberoftrumps()
				<= Rule::MAX_NUMBER_OF_POVERTY_TRUMPS));
      gtk_widget_set_sensitive(this->button(GAMETYPE::MARRIAGE).widget(),
			       (player.hand().numberofclubqueens() == 2));

      this->marriage_toggle();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_INIT,
		      "Reservation::sensitivity_update()");
    } // void Reservation::sensitivity_update(Player const& player)

  /*****************************************************************************
   *
   * ::Reservation Reservation::get(Player const& player)
   *
   * Parameters:	player - the player, whose reservation is returned
   *
   * Result:	the reservation of the player
   *
   * Version:	0.4.2
   *
   * Description:	Result
   *
   ****************************************************************************/
  ::Reservation
    Reservation::get(Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_GAMEPLAY,
		    "Reservation::get()");

      // save the gametype
      GameType const game_type = player.game().type();

      ::Reservation reservation;

      this->sensitivity_update(player);
      this->language_update();
      this->preset(player);

      gtk_notebook_set_page(GTK_NOTEBOOK(this->notebook), 0);
      this->PlayfieldDialog::show();

      while ( (game_status == GAMESTATUS::GAME_RESERVATION)
	      && GTK_WIDGET_VISIBLE(window()) )
	gtk_main();

      if ( GTK_WIDGET_VISIBLE(this->window()) )
	gtk_widget_hide(this->window());

      // set the resevation
      this->set(player, reservation);

      // reset the gametype
      const_cast<Game&>(player.game()).type_set(game_type);

      // put the main window in the foreground
      gtk_widget_show(this->gui().main_window().window());

      DEBUG_RETURNING(reservation,
		      INFO_GTK_RESERVATION && INFO_GTK_GAMEPLAY,
		      "Reservation::get()");
    } // GtkWidget* Reservation::get()

  /*****************************************************************************
   *
   * void Reservation::preset(Player const& player)
   *
   * Parameters:	player - the player of the reservation
   *
   * Result:	none
   * 
   * Version:	0.4.2
   *
   * Description:	presets the reservation
   *
   ****************************************************************************/
  void
    Reservation::preset(Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_UPDATE,
		    "Reservation::preset()");

      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->swines.widget()),
				   player.game().rule()(Rule::SWINES)
				   && (player.hand().numberoftrumpaces()
				       == ::party.game().rule()(Rule::NUMBER_OF_SAME_CARDS)));
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->hyperswines.widget()),
				   player.game().rule()(Rule::HYPERSWINES)
				   && (player.hand().numberoftrumpnines()
				       == ::party.game().rule()(Rule::NUMBER_OF_SAME_CARDS)));


      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::MARRIAGE).widget()),
				   (player.hand().numberofclubqueens() == 2));
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::POVERTY).widget()),
				   player.game().rule()(Rule::POVERTY)
				   && (player.hand().numberoftrumps()
				       <= Rule::MAX_NUMBER_OF_POVERTY_TRUMPS));
      { // look, whether there is a card that is higher than the fox
	unsigned c;
	for (c = 0; c < player.hand().cardsnumber(); c++)
	  if (Card(Card::DIAMOND, Card::ACE).less(player.hand().card(c),
						  player.game()))
	    break;
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::FOX_HIGHEST_TRUMP).widget()),
				     player.game().rule()(Rule::THROW_WHEN_FOX_HIGHEST_TRUMP)
				     && (c == player.hand().cardsnumber()));
      } // look, whether there is a card that is higher than the fox
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::SIX_KINGS).widget()),
				   player.game().rule()(Rule::THROW_WITH_SIX_KINGS)
				   &&(player.hand().numberofkings()
				      >= Rule::MIN_NUMBER_OF_THROWING_KINGS));
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::FIVE_NINES).widget()),
				   player.game().rule()(Rule::THROW_WITH_FIVE_NINES)
				   &&(player.hand().numberofnines()
				      >= Rule::MIN_NUMBER_OF_THROWING_NINES));

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_UPDATE,
		      "Reservation::preset()");
    } // void Reservation::preset()

  /*****************************************************************************
   *
   * static void Reservation::change_game_type_event(GtkWidget* button,
   *						   gpointer game_type)
   *
   * Parameters:	button - button, that has changed
   * 		game_type - the new game type
   *
   * Result:	none
   *
   * Version:	0.4.2
   *
   * Description:	sorts the hands
   *
   ****************************************************************************/
  void
    Reservation::change_game_type_event(GtkWidget* button, gpointer game_type)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		    "Reservation::change_game_type_event()");

      if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) {
	// resorting the hands
	::party.game().type_set(*((GameType*)game_type));
	::party.game().players_hands_sort();
	::ui->redraw_all();
      }

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		      "Reservation::change_game_type_event()");
    } // static void Reservation::change_game_type_event(GtkWidget* button, gpointer game_type)

  /*****************************************************************************
   *
   * static void Reservation::marriage_toggle_event(GtkWidget* button,
   *						   gpointer reservation)
   *
   * Parameters:	button - button, that has changed
   * 		reservation - the reservation
   *
   * Result:	none
   *
   * Version:	0.4.2
   *
   * Description:	calls reservation->marriage_toggle()
   *
   ****************************************************************************/
  void
    Reservation::marriage_toggle_event(GtkWidget* button, gpointer reservation)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		    "Reservation::marriage_toggle_event()");

      ((Reservation*)(reservation))->marriage_toggle();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		      "Reservation::marriage_toggle_event()");
    } // static void Reservation::marriage_toggle_event(GtkWidget* button, gpointer reservation)

  /*****************************************************************************
   *
   * void Reservation::marriage_toggle()
   *
   * Parameters:	-
   *
   * Result:	-
   *
   * Version:	0.4.2
   *
   * Description:	sets the sensitivity of the marriage selector buttons
   *
   ****************************************************************************/
  void
    Reservation::marriage_toggle()
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		    "Reservation::marriage_toggle()");

      for (unsigned i = MARRIAGE_SELECTOR::FIRST;
	   i <= MARRIAGE_SELECTOR::LAST;
	   i++)
	gtk_widget_set_sensitive(this->button(MarriageSelector(i)).widget(),
				 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->button(GAMETYPE::MARRIAGE).button()))
				);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_EVENT,
		      "Reservation::marriage_toggle()");
    } // void Reservation::marriage_toggle()

  /*****************************************************************************
   *
   * ::Reservation Reservation::set(Player const& player,
   *				  Reservation& reservation)
   *
   * Parameters:	player - the player, whose reservation is returned
   *		reservation - the reservation to be changed
   *
   * Result:	the reservation of the player
   *
   * Version:	0.4.2
   *
   * Description:	set the reservation
   *
   ****************************************************************************/
  ::Reservation&
    Reservation::set(Player const& player, ::Reservation& reservation)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_GAMEPLAY,
		    "Reservation::set()");

      unsigned i;

      // set the game type
      reservation.game_type = GAMETYPE::NORMAL;
      for (i = GAMETYPE::FIRST + 1; i <= GAMETYPE::LAST; i++)
	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->button(GameType(i)).button()))
	    == TRUE)
	  reservation.game_type = GameType(i);


      if (reservation.game_type == GAMETYPE::MARRIAGE) {
	// set the marriage selector
	for (unsigned i = MARRIAGE_SELECTOR::FIRST;
	     i <= MARRIAGE_SELECTOR::LAST;
	     i++) {    
	  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->button(MarriageSelector(i)).button()))
	      == TRUE)
	    reservation.marriage_selector = MarriageSelector(i);
	} // for (MARRIAGE_SELECTOR::FIRST <= i <= MARRIAGE_SELECTOR::LAST)
      } // if (reservation.game_type() == GAMETYPE::MARRIAGE)

      // set swines and hyperswines
      reservation.swines = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->swines.button()))
			    == TRUE);
      reservation.hyperswines = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->hyperswines.button()))
				 == TRUE);

      DEBUG_RETURNING(reservation,
		      INFO_GTK_RESERVATION && INFO_GTK_GAMEPLAY,
		      "Reservation::set()");
    } // Reservation Reservation::set(Player const& player, Reservation& reservation)

  /*****************************************************************************
   *
   * XGtkRadioButton& Reservation::button(GameType const& type)
   *
   * Parameters:	type	- the gametype
   *
   * Result:	the button of the rule
   *
   * Version:	0.4.2
   *
   * Description:	->Result
   *
   ****************************************************************************/
  XGtkRadioButton&
    Reservation::button(GameType const& type)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_VALUE,
		    "Reservation::button(GameType)");

      DEBUG_ASSERTION((unsigned(type) < this->game_type_p.size()),
		      "Reservation::button(GameType):\n"
		      "  button 'type' not set yet");

      DEBUG_RETURNING(*(this->game_type_p[type]),
		      INFO_GTK_RESERVATION && INFO_GTK_VALUE,
		      "Reservation::button(GameType)");
    } // XGtkRadioButton& Reservation::button(GameType const& type)

  /*****************************************************************************
   *
   * XGtkRadioButton& Reservation::button(MarriageSelector const& type)
   *
   * Parameters:	type	- the rule
   *
   * Result:	the button of the rule
   *
   * Version:	0.4.2
   *
   * Description:	->Result
   *
   ****************************************************************************/
  XGtkRadioButton&
    Reservation::button(MarriageSelector const& type)
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_VALUE,
		    "Reservation::button(MarriageSelector)");

      DEBUG_ASSERTION((unsigned(type) < this->marriage_selector_p.size()),
		      "Reservation::button(GameType):\n"
		      "  button 'type' not set yet");

      DEBUG_RETURNING(*(this->marriage_selector_p[type]),
		      INFO_GTK_RESERVATION && INFO_GTK_VALUE,
		      "Reservation::button(MarriageSelector)");
    } // XGtkRadioButton& Reservation::button(MarriageSelector const& type)

  /*****************************************************************************
   *
   * void Reservation::language_update()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.4.2
   *
   * Description:	updates the language in the reservation window
   *
   ****************************************************************************/
  void
    Reservation::language_update()
    {
      DEBUG_CALLING(INFO_GTK_RESERVATION && INFO_GTK_UPDATE,
		    "Reservation::language_update()");

      unsigned i;

      this->PlayfieldDialog::language_update();

      if ((game_status != GAMESTATUS::GAME_RESERVATION)
	  || (::party.game().humanno() <= 1))
	this->title_set(::language("Reservation"));
      else
	this->title_set(::language("reservation announce")
			+ " (" + ::party.game().player_current().name() + ")"
		       );

      gtk_label_set_text(GTK_LABEL(GTK_BIN(button_close)->child),
			 language("reservation announce").c_str());

      this->bookmark_default.language_update();
      this->bookmark_solo.language_update();

      this->swines.language_update();
      this->hyperswines.language_update();

      for (i = GAMETYPE::FIRST; i <= GAMETYPE::LAST; i++)
	this->button(GameType(i)).language_update();

      for (i = MARRIAGE_SELECTOR::FIRST; i <= MARRIAGE_SELECTOR::LAST; i++)
	this->button(MarriageSelector(i)).language_update();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_RESERVATION && INFO_GTK_UPDATE,
		      "Reservation::language_update()");
    } // void Reservation::language_update()

}
#endif
