/**********************************************************************
 *
 *   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 "icon.h"
#include "gtk_gui.h"
#include "splash.h"

#include "../../utils/file.h"
#include "../../party/party.h"
#include "../../misc/setting.h"
#include "../../misc/language.h"
#include "../../basistypes.h"

namespace GTK_DOKO
{

  // 40 (?) icons to be loaded
#define PROGRESS_STEP_ICON (1.0 / (Icons::NUMBER_OF_TYPES - 1))


#define progress_set_text(text) \
  ( (game_status == GAMESTATUS::PROGRAMSTART) \
    ? this->gui().splash().set_text(text) \
    : (void) 0)
#define progress(progress) \
    ( (game_status == GAMESTATUS::PROGRAMSTART) \
      ? this->gui().splash().progress_add(progress) \
      : (void) 0)


    unsigned const Icons::NUMBER_OF_TYPES = NO_0 + 1; // number of icons

  /*****************************************************************************
   *
   * Icons::Icons(GTK_GUI* gui_a)
   *
   * Parameters:	gui_a - pointer to the gui
   *
   * Result:	none
   * 
   * Version:	0.3.7
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  Icons::Icons(GTK_GUI* gui_a) :
    gui_p(gui_a), // the gui
  icon_p(Icons::NUMBER_OF_TYPES,
	 vector<Pixmap>(ROTATION_NUMBER))
  {
    DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_INIT,
		  "Icons::Icons()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_ICON && INFO_GTK_INIT,
		    "Icons::Icons()");
  } // Icons::Icons(GTK_GUI* gui_a)

  /*****************************************************************************
   *
   * void Icons::init()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.4.4
   *
   * Description:	inits the icons -- loads the icons and the background
   *
   ****************************************************************************/
  void
    Icons::init()
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_INIT,
		    "Icons::init()");

      // loads the pixmaps
      this->load();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_ICON && INFO_GTK_INIT,
		      "Icons::init()");
    } // void Icons::init()

  /*****************************************************************************
   *
   * GTK_GUI& Icons::gui()
   *
   * Parameters:	none
   *
   * Result:	the gui
   *
   * Version:	0.3.7
   *
   * Description:	Result
   *
   ****************************************************************************/
  GTK_GUI&
    Icons::gui()
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::gui()");

      DEBUG_ASSERTION((gui_p != NULL),
		      "GTK_GUI& Icons::gui():\n"
		      "  'gui_p' == NULL");

      DEBUG_RETURNING(*gui_p,
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::gui()");
    } // GTK_GUI& Icons::gui()

  /**
   **
   ** loads the icons
   **
   ** @param	-
   **
   ** @return	whether the icons were loaded
   ** 
   ** @version	0.4.5
   **
   ** @author	Diether Knof
   **
   **/
  bool
    Icons::load()
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_INIT,
		    "Icons::load()");

      vector<string> directory;

      directory.push_back(::setting(Setting::PRIVATE_DATA_DIRECTORY) + "/"
			  + ::setting(Setting::ICONS_DIRECTORY));
      directory.push_back(::setting(Setting::PUBLIC_DATA_DIRECTORY) + "/"
			  + ::setting(Setting::ICONS_DIRECTORY));
      directory.push_back("./" + ::setting(Setting::ICONS_DIRECTORY));
      if (!this->icon(RE)) {
	directory.push_back(::setting_default(Setting::PUBLIC_DATA_DIRECTORY) + "/"
			    + ::setting(Setting::ICONS_DIRECTORY));
	directory.push_back(::setting_default(Setting::PUBLIC_DATA_DIRECTORY) + "/"
			    + ::setting_default(Setting::ICONS_DIRECTORY));
      }

      vector<string>::iterator d;
      for (d = directory.begin(); d != directory.end(); d++)
	if (this->load(*d))
	  break;

      if (d == directory.end()) {
	progress(Icons::NUMBER_OF_TYPES - 1);
	if (!this->icon(RE)) {
	  cerr << "Could not load icons `" << *d << "`.\n"
	    << "Exiting."
	    << endl;
	  exit(1);
	}
      } // if !(d != directory.end())

      DEBUG_RETURNING((d != directory.end()),
		      INFO_GTK_ICON && INFO_GTK_INIT,
		      "Icons::load()");
    } // bool Icons::load()

  /*****************************************************************************
   *
   * bool Icons::load(string const directory)
   *
   * Parameters:	directory - directory with the icons
   *
   * Result:	whether the icons could be loaded
   * 
   * Version:	0.4.2
   *
   * Description:	loads the back of the icons
   *
   ****************************************************************************/
  bool
    Icons::load(string const directory)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_INIT,
		    "Icons::load()");

      progress_set_text(language("Loading the icons"));

      // backup the setting
      string const icons_directory = ::setting(Setting::ICONS_DIRECTORY);

      vector<vector<Pixmap> > icons
	= vector<vector<Pixmap> >(Icons::NUMBER_OF_TYPES,
				  vector<Pixmap>(ROTATION_NUMBER));

      // first test, whether the directory exists
      DIR* dir = opendir(directory.c_str());

      if (dir == NULL)
	DEBUG_RETURNING(false,
			INFO_GTK_ICON && INFO_GTK_INIT,
			"Icons::load()");

      closedir(dir);

      // load the icons
      if (!icon_load_and_rotate(icons[RE],
				directory + "/re")
	  || !icon_load_and_rotate(icons[CONTRA],
				   directory + "/contra")
	  || !icon_load_and_rotate(icons[FIVE_NINES],
				   directory + "/five_nines")
	  || !icon_load_and_rotate(icons[SIX_KINGS],
				   directory + "/six_kings")
	  || !icon_load_and_rotate(icons[GENSCHER],
#ifdef POSTPHONED
				   directory + "/genscher")
#else
				   directory + "/re")
#endif
	  || !icon_load_and_rotate(icons[MARRIAGE],
				   directory + "/marriage")
	  || !icon_load_and_rotate(icons[MARRIAGE_FOREIGN],
				   directory + "/marriage.foreign")
	  || !icon_load_and_rotate(icons[MARRIAGE_TRUMP],
				   directory + "/marriage.trump")
	  || !icon_load_and_rotate(icons[MARRIAGE_COLOR],
				   directory + "/marriage.color")
	  || !icon_load_and_rotate(icons[MARRIAGE_CLUB],
				   directory + "/marriage.club")
	  || !icon_load_and_rotate(icons[MARRIAGE_SPADE],
				   directory + "/marriage.spade")
	  || !icon_load_and_rotate(icons[MARRIAGE_HEART],
				   directory + "/marriage.heart")
	  || !icon_load_and_rotate(icons[POVERTY],
				   directory + "/poverty")
	  || !icon_load_and_rotate(icons[POVERTY_TRUMPS_0],
				   directory + "/poverty.0")
	  || !icon_load_and_rotate(icons[POVERTY_TRUMPS_1],
				   directory + "/poverty.1")
	  || !icon_load_and_rotate(icons[POVERTY_TRUMPS_2],
				   directory + "/poverty.2")
	  || !icon_load_and_rotate(icons[POVERTY_TRUMPS_3],
				   directory + "/poverty.3")
	  || !icon_load_and_rotate(icons[FOX_HIGHEST_TRUMP],
				   directory + "/fox_highest_trump")
	  || !icon_load_and_rotate(icons[SWINES_CLUB],
				   directory + "/swines.club")
	  || !icon_load_and_rotate(icons[SWINES_SPADE],
				   directory + "/swines.spade")
	  || !icon_load_and_rotate(icons[SWINES_HEART],
				   directory + "/swines.heart")
	  || !icon_load_and_rotate(icons[SWINES_DIAMOND],
				   directory + "/swines.diamond")
	  || !icon_load_and_rotate(icons[HYPERSWINES_CLUB],
				   directory + "/hyperswines.club")
	  || !icon_load_and_rotate(icons[HYPERSWINES_SPADE],
				   directory + "/hyperswines.spade")
	  || !icon_load_and_rotate(icons[HYPERSWINES_HEART],
				   directory + "/hyperswines.heart")
	  || !icon_load_and_rotate(icons[HYPERSWINES_DIAMOND],
				   directory + "/hyperswines.diamond")
	  || !icon_load_and_rotate(icons[SWINES_HYPERSWINES_CLUB],
				   directory + "/swines-hyperswines.club")
	  || !icon_load_and_rotate(icons[SWINES_HYPERSWINES_SPADE],
				   directory + "/swines-hyperswines.spade")
	  || !icon_load_and_rotate(icons[SWINES_HYPERSWINES_HEART],
				   directory + "/swines-hyperswines.heart")
	  || !icon_load_and_rotate(icons[SWINES_HYPERSWINES_DIAMOND],
				   directory + "/swines-hyperswines.diamond")
	  || !icon_load_and_rotate(icons[SOLO_CLUB],
				   directory + "/solo.club")
	  || !icon_load_and_rotate(icons[SOLO_SPADE],
				   directory + "/solo.spade")
	  || !icon_load_and_rotate(icons[SOLO_HEART],
				   directory + "/solo.heart")
	  || !icon_load_and_rotate(icons[SOLO_DIAMOND],
				   directory + "/solo.diamond")
	  || !icon_load_and_rotate(icons[SOLO_JACK],
				   directory + "/solo.jack")
	  || !icon_load_and_rotate(icons[SOLO_QUEEN],
				   directory + "/solo.queen")
	  || !icon_load_and_rotate(icons[SOLO_KING],
				   directory + "/solo.king")
	  || !icon_load_and_rotate(icons[SOLO_QUEEN_JACK],
				   directory + "/solo.queen-jack")
	  || !icon_load_and_rotate(icons[SOLO_KING_JACK],
				   directory + "/solo.king-jack")
	  || !icon_load_and_rotate(icons[SOLO_KING_QUEEN],
				   directory + "/solo.king-queen")
	  || !icon_load_and_rotate(icons[SOLO_KOEHLER],
				   directory + "/solo.koehler")
	  || !icon_load_and_rotate(icons[SOLO_MEATLESS],
				   directory + "/solo.meatless")
	  || !icon_load_and_rotate(icons[NO_120],
				   directory + "/no_120")
	  || !icon_load_and_rotate(icons[NO_90],
				   directory + "/no_90")
	  || !icon_load_and_rotate(icons[NO_60],
				   directory + "/no_60")
	  || !icon_load_and_rotate(icons[NO_30],
				   directory + "/no_30")
	  || !icon_load_and_rotate(icons[NO_0],
				   directory + "/no_0")) {
				     DEBUG_RETURNING(false,
						     INFO_GTK_CARD && INFO_GTK_INIT,
						     "Icons::load()");
				   } // if (one card could not be loaded)

				   // validate, that the settings did not change
				   if (icons_directory != ::setting(Setting::ICONS_DIRECTORY))
				     DEBUG_RETURNING(false,
						     INFO_GTK_ICON && INFO_GTK_INIT,
						     "Icons::load()");

				   this->icon_p = icons;

				   DEBUG_RETURNING(true,
						   INFO_GTK_ICON && INFO_GTK_INIT,
						   "Icons::load()");
    } // bool Icons::load(string const& directory)

  /**
   **
   ** loads the pixmap from the file and rotates it;
   ** tests, whether the size is correct;
   ** updates the progressbar
   **
   ** @param	card		vector, in which the icons are to be written
   ** @param	filename	name of the file with the graphic
   **
   ** @return	whether the icons could be loaded
   ** 
   ** @version	0.5.1
   ** 
   ** @autor	Diether Knof
   **
   **/
  bool
    Icons::icon_load_and_rotate(vector<Pixmap>& icon, string const& filename)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_INIT,
		    "Icons::icon_load_and_rotate()");

      // load the icon
      Pixmap::load_and_rotate(icon, filename);
      this->gui().update();

      if (!icon[0]) {
	cerr << "Could not load icon `" << filename << "`.\n"
	  << endl;
	DEBUG_RETURNING(false,
			INFO_GTK_ICON && INFO_GTK_INIT,
			"Icons::icon_load_and_rotate()");
      }

      // update the progess
      progress(PROGRESS_STEP_ICON);

      DEBUG_RETURNING(true,
		      INFO_GTK_ICON && INFO_GTK_INIT,
		      "Icons::icon_load_and_rotate()");
    } // bool Icons::icon_load_and_rotate(icon, filename)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const Type& type,
   * 		       Player const& player)
   *
   * Parameters:	type     - the type of the icon
   *		player - player
   *
   * Result:	the (Pixmap) icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const Type type, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(type, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const Type& type)
   *
   * Parameters:	type     - the type of the icon
   *
   * Result:	the (Pixmap) icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const Type type)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(type)

  /*****************************************************************************
   *
   * Pixmap const& Icons::icon(const Type& type,
   * 			     Player const& player) const
   *
   * Parameters:	type     - the type of the icon
   *		player - player
   *
   * Result:	the (Pixmap) icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap const&
    Icons::icon(const Type type, Player const& player) const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(type, player)

  /*****************************************************************************
   *
   * Pixmap const& Icons::icon(const Type& type) const
   *
   * Parameters:	type     - the type of the icon
   *
   * Result:	the (Pixmap) icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap const&
    Icons::icon(const Type type) const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(type)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const GAMETYPE::GameType& gametype,
   * 		       Player const& player)
   *
   * Parameters:	gametype - the gametype
   *		player - player
   *
   * Result:	the (Pixmap) gametype icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const GAMETYPE::GameType gametype, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(gametype) {
      case GAMETYPE::NORMAL:
	type = RE;
	break;
      case GAMETYPE::FIVE_NINES:
	type = FIVE_NINES;
	break;
      case GAMETYPE::SIX_KINGS:
	type = SIX_KINGS;
	break;
      case GAMETYPE::POVERTY:
	if (::game_status == GAMESTATUS::GAME_POVERTY_SHIFT) {
	  type = POVERTY;
	} else { // if !(::game_status == GAMESTATUS::GAME_POVERTY_SHIFT)
	  switch (::party.game().poverty_cardno()) {
	  case 0:
	    type = POVERTY_TRUMPS_0;
	    break;
	  case 1:
	    type = POVERTY_TRUMPS_1;
	    break;
	  case 2:
	    type = POVERTY_TRUMPS_2;
	    break;
	  case 3:
	    type = POVERTY_TRUMPS_3;
	    break;
	  case UINT_MAX:
	    type = POVERTY;
	    break;
	  default:
	    DEBUG_ASSERTION(false,
			    "Icons::icon(gametype, player):\n"
			    "  gametype: poverty\n"
			    "  number of poverty cards invalid: "
			    << ::party.game().poverty_cardno());
	    type = POVERTY;
	    break;
	  } // switch (::party.game().poverty_cardno())
	} // if !(::game_status == GAMESTATUS::GAME_POVERTY_SHIFT)
	break;
      case GAMETYPE::FOX_HIGHEST_TRUMP:
	type = FOX_HIGHEST_TRUMP;
	break;
      case GAMETYPE::GENSCHER:
	type = GENSCHER;
	break;
      case GAMETYPE::MARRIAGE:
      case GAMETYPE::MARRIAGE_SILENT:
      case GAMETYPE::MARRIAGE_SOLO:
	type = MARRIAGE;
	break;
      case GAMETYPE::SOLO_DIAMOND:
	type = SOLO_DIAMOND;
	break;
      case GAMETYPE::SOLO_JACK:
	type = SOLO_JACK;
	break;
      case GAMETYPE::SOLO_QUEEN:
	type = SOLO_QUEEN;
	break;
      case GAMETYPE::SOLO_KING:
	type = SOLO_KING;
	break;
      case GAMETYPE::SOLO_QUEEN_JACK:
	type = SOLO_QUEEN_JACK;
	break;
      case GAMETYPE::SOLO_KING_JACK:
	type = SOLO_KING_JACK;
	break;
      case GAMETYPE::SOLO_KING_QUEEN:
	type = SOLO_KING_QUEEN;
	break;
      case GAMETYPE::SOLO_KOEHLER:
	type = SOLO_KOEHLER;
	break;
      case GAMETYPE::SOLO_CLUB:
	type = SOLO_CLUB;
	break;
      case GAMETYPE::SOLO_HEART:
	type = SOLO_HEART;
	break;
      case GAMETYPE::SOLO_SPADE:
	type = SOLO_SPADE;
	break;
      case GAMETYPE::SOLO_MEATLESS:
	type = SOLO_MEATLESS;
	break;
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(gametype, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const GAMETYPE::GameType& gametype)
   *
   * Parameters:	gametype - the gametype
   *
   * Result:	the (Pixmap) gametype icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const GAMETYPE::GameType gametype)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(gametype) {
      case GAMETYPE::NORMAL:
	type = RE;
	break;
      case GAMETYPE::FIVE_NINES:
	type = FIVE_NINES;
	break;
      case GAMETYPE::SIX_KINGS:
	type = SIX_KINGS;
	break;
      case GAMETYPE::POVERTY:
	if (::game_status == GAMESTATUS::GAME_POVERTY_SHIFT) {
	  type = POVERTY;
	} else { // if !(::game_status == GAMESTATUS::GAME_POVERTY_SHIFT)
	  switch (::party.game().poverty_cardno()) {
	  case 0:
	    type = POVERTY_TRUMPS_0;
	    break;
	  case 1:
	    type = POVERTY_TRUMPS_1;
	    break;
	  case 2:
	    type = POVERTY_TRUMPS_2;
	    break;
	  case 3:
	    type = POVERTY_TRUMPS_3;
	    break;
	  case UINT_MAX:
	    type = POVERTY;
	    break;
	  default:
	    DEBUG_ASSERTION(false,
			    "Icons::icon(gametype):\n"
			    "  gametype: poverty\n"
			    "  number of poverty cards invalid: "
			    << ::party.game().poverty_cardno());
	    type = POVERTY;
	    break;
	  } // switch (::party.game().poverty_cardno())
	} // if !(::game_status == GAMESTATUS::GAME_POVERTY_SHIFT)
	break;
      case GAMETYPE::FOX_HIGHEST_TRUMP:
	type = FOX_HIGHEST_TRUMP;
	break;
      case GAMETYPE::GENSCHER:
	type = GENSCHER;
	break;
      case GAMETYPE::MARRIAGE:
      case GAMETYPE::MARRIAGE_SOLO:
      case GAMETYPE::MARRIAGE_SILENT:
	type = MARRIAGE;
	break;
      case GAMETYPE::SOLO_DIAMOND:
	type = SOLO_DIAMOND;
	break;
      case GAMETYPE::SOLO_JACK:
	type = SOLO_JACK;
	break;
      case GAMETYPE::SOLO_QUEEN:
	type = SOLO_QUEEN;
	break;
      case GAMETYPE::SOLO_KING:
	type = SOLO_KING;
	break;
      case GAMETYPE::SOLO_QUEEN_JACK:
	type = SOLO_QUEEN_JACK;
	break;
      case GAMETYPE::SOLO_KING_JACK:
	type = SOLO_KING_JACK;
	break;
      case GAMETYPE::SOLO_KING_QUEEN:
	type = SOLO_KING_QUEEN;
	break;
      case GAMETYPE::SOLO_KOEHLER:
	type = SOLO_KOEHLER;
	break;
      case GAMETYPE::SOLO_CLUB:
	type = SOLO_CLUB;
	break;
      case GAMETYPE::SOLO_HEART:
	type = SOLO_HEART;
	break;
      case GAMETYPE::SOLO_SPADE:
	type = SOLO_SPADE;
	break;
      case GAMETYPE::SOLO_MEATLESS:
	type = SOLO_MEATLESS;
	break;
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(gametype)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const MARRIAGE_SELECTOR::MarriageSelector marriage_selector,
   * 		       Player const& player)
   *
   * Parameters:	marriage_selector - the marriage selector
   *		player - player
   *
   * Result:	the (Pixmap) marriage selector icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const MARRIAGE_SELECTOR::MarriageSelector marriage_selector,
		Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(marriage_selector) {
      case MARRIAGE_SELECTOR::TEAM_SET:
	type = Icons::MARRIAGE;
	break;
      case MARRIAGE_SELECTOR::FIRST_FOREIGN:
	type = Icons::MARRIAGE_FOREIGN;
	break;
      case MARRIAGE_SELECTOR::FIRST_TRUMP:
	type = Icons::MARRIAGE_TRUMP;
	break;
      case MARRIAGE_SELECTOR::FIRST_COLOR:
	type = Icons::MARRIAGE_COLOR;
	break;
      case MARRIAGE_SELECTOR::FIRST_CLUB:
	type = Icons::MARRIAGE_CLUB;
	break;
      case MARRIAGE_SELECTOR::FIRST_SPADE:
	type = Icons::MARRIAGE_SPADE;
	break;
      case MARRIAGE_SELECTOR::FIRST_HEART:
	type = Icons::MARRIAGE_HEART;
	break;
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(marriage_selector, player)
  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const MARRIAGE_SELECTOR::MarriageSelector marriage_selector)
   *
   * Parameters:	marriage_selector - the marriage selector
   *
   * Result:	the (Pixmap) marriage selector icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const MARRIAGE_SELECTOR::MarriageSelector marriage_selector)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(marriage_selector) {
      case MARRIAGE_SELECTOR::TEAM_SET:
	type = Icons::MARRIAGE;
	break;
      case MARRIAGE_SELECTOR::FIRST_FOREIGN:
	type = Icons::MARRIAGE_FOREIGN;
	break;
      case MARRIAGE_SELECTOR::FIRST_TRUMP:
	type = Icons::MARRIAGE_TRUMP;
	break;
      case MARRIAGE_SELECTOR::FIRST_COLOR:
	type = Icons::MARRIAGE_COLOR;
	break;
      case MARRIAGE_SELECTOR::FIRST_CLUB:
	type = Icons::MARRIAGE_CLUB;
	break;
      case MARRIAGE_SELECTOR::FIRST_SPADE:
	type = Icons::MARRIAGE_SPADE;
	break;
      case MARRIAGE_SELECTOR::FIRST_HEART:
	type = Icons::MARRIAGE_HEART;
	break;
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(marriage_selector)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const TEAM::Team& team,
   * 		       Player const& player)
   *
   * Parameters:	team - the team
   *		player - player
   *
   * Result:	the (Pixmap) team icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const TEAM::Team team, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(team) {
      case TEAM::RE:
	type = RE;
	break;
      case TEAM::CONTRA:
	type = CONTRA;
	break;
      default:
	type = NONE;
	break;
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(team, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(const TEAM::Team& team)
   *
   * Parameters:	team - the team
   *		player - player
   *
   * Result:	the (Pixmap) team icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(const TEAM::Team team)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(team) {
      case TEAM::RE:
	type = RE;
	break;
      case TEAM::CONTRA:
	type = CONTRA;
	break;
      default:
	type = NONE;
	break;
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::icon(team)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(Announcement const& announcement,
   * 		       Player const& player)
   *
   * Parameters:	announcement	- the announcement
   *		player	- player
   *
   * Result:	the (Pixmap) announcement icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	-> result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(Announcement const& announcement, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon(announcement)");

      Icons::Type type = NONE;

      switch(announcement) {
      case ANNOUNCEMENT::NOANNOUNCEMENT:
	DEBUG_ASSERTION(false,
			"Icons::icon(announcement):\n"
			"  invalid announcement 'NOANNOUNCEMENT'");
	break;
      case ANNOUNCEMENT::REPLY:
      case ANNOUNCEMENT::NO120:
	type = NO_120;
	break;
      case ANNOUNCEMENT::NO90:
	type = NO_90;
	break;
      case ANNOUNCEMENT::NO60:
	type = NO_60;
	break;
      case ANNOUNCEMENT::NO30:
	type = NO_30;
	break;
      case ANNOUNCEMENT::NO0:
	type = NO_0;
	break;
      } // switch(announcement)

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon(announcement)");
    } // Pixmap& Icons::icon(team, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::icon(Announcement const& announcement)
   *
   * Parameters:	announcement	- the announcement
   *
   * Result:	the (Pixmap) announcement icon
   * 
   * Version:	0.4.4
   *
   * Description:	-> result
   *
   ****************************************************************************/
  Pixmap&
    Icons::icon(Announcement const& announcement)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon(announcement)");

      Icons::Type type = NONE;

      switch(announcement) {
      case ANNOUNCEMENT::NOANNOUNCEMENT:
	DEBUG_ASSERTION(false,
			"Icons::icon(announcement):\n"
			"  invalid announcement 'NOANNOUNCEMENT'");
	break;
      case ANNOUNCEMENT::REPLY:
      case ANNOUNCEMENT::NO120:
	type = NO_120;
	break;
      case ANNOUNCEMENT::NO90:
	type = NO_90;
	break;
      case ANNOUNCEMENT::NO60:
	type = NO_60;
	break;
      case ANNOUNCEMENT::NO30:
	type = NO_30;
	break;
      case ANNOUNCEMENT::NO0:
	type = NO_0;
	break;
      } // switch(announcement)

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon(announcement)");
    } // Pixmap& Icons::icon(team)

  /*****************************************************************************
   *
   * Pixmap& Icons::swines(const Card::Color color,
   * 		       Player const& player)
   *
   * Parameters:	color - the color of the swines
   *		player - player
   *
   * Result:	the (Pixmap) swines icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::swines(const Card::Color color, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::SWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::SWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::SWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::SWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::swines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::swines(color, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::swines(const Card::Color color)
   *
   * Parameters:	color - the color of the swines
   *
   * Result:	the (Pixmap) swines icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::swines(const Card::Color color)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::SWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::SWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::SWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::SWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::swines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::swines(color)

  /*****************************************************************************
   *
   * Pixmap& Icons::hyperswines(const Card::Color color,
   * 		       Player const& player)
   *
   * Parameters:	color - the color of the hyperswines
   *		player - player
   *
   * Result:	the (Pixmap) hyperswines icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::hyperswines(const Card::Color color, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::HYPERSWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::HYPERSWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::HYPERSWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::HYPERSWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::hyperswines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::hyperswines(color, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::hyperswines(const Card::Color color)
   *
   * Parameters:	color - the color of the hyperswines
   *
   * Result:	the (Pixmap) hyperswines icon
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::hyperswines(const Card::Color color)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::HYPERSWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::HYPERSWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::HYPERSWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::HYPERSWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::hyperswines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::hyperswines(color)

  /*****************************************************************************
   *
   * Pixmap& Icons::swines_hyperswines(const Card::Color color,
   *				     Player const& player)
   *
   * Parameters:	color - the color of the swines-hyperswines
   *		player - player
   *
   * Result:	the (Pixmap) swines-hyperswines icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::swines_hyperswines(const Card::Color color, Player const& player)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::SWINES_HYPERSWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::SWINES_HYPERSWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::SWINES_HYPERSWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::SWINES_HYPERSWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::swines_hyperswines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][player.no()],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::swines_hyperswines(color, player)

  /*****************************************************************************
   *
   * Pixmap& Icons::swines_hyperswines(const Card::Color color)
   *
   * Parameters:	color - the color of the swines-hyperswines
   *
   * Result:	the (Pixmap) swines-hyperswines icon of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  Pixmap&
    Icons::swines_hyperswines(const Card::Color color)
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::icon()");

      Icons::Type type = NONE;

      switch(color) {
      case Card::CLUB:
	type = Icons::SWINES_HYPERSWINES_CLUB;
	break;
      case Card::SPADE:
	type = Icons::SWINES_HYPERSWINES_SPADE;
	break;
      case Card::HEART:
	type = Icons::SWINES_HYPERSWINES_HEART;
	break;
      case Card::DIAMOND:
	type = Icons::SWINES_HYPERSWINES_DIAMOND;
	break;
      default:
	DEBUG_ASSERTION(false,
			"Icons::swines_hyperswines(color)\n"
			"  Color is not valid\n");
      }

      DEBUG_RETURNING(icon_p[type][0],
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::icon()");
    } // Pixmap& Icons::swines_hyperswines(color)

  /*****************************************************************************
   *
   * unsigned Icons::width_max(Player const& player) const
   *
   * Parameters:	player - player
   *
   * Result:	the maximal width of the icons of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  unsigned
    Icons::width_max(Player const& player) const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::width_max()");

      unsigned width = 0;
      for(unsigned t = 0; t < NUMBER_OF_TYPES; t++)
	width = max(width, icon(Type(t), player).width());

      DEBUG_RETURNING(width,
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::width_max()");
    } // unsigned Icons::width_max()

  /*****************************************************************************
   *
   * unsigned Icons::width_max() const
   *
   * Parameters:	-
   *
   * Result:	the maximal width of the icons
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  unsigned
    Icons::width_max() const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::width_max()");

      unsigned width = 0;
      for(unsigned t = 0; t < NUMBER_OF_TYPES; t++)
	width = max(width, icon(Type(t)).width());

      DEBUG_RETURNING(width,
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::width_max()");
    } // unsigned Icons::width_max()

  /*****************************************************************************
   *
   * unsigned Icons::height_max(Player const& player) const
   *
   * Parameters:	player - player
   *
   * Result:	the maximal height of the icons of the given player
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  unsigned
    Icons::height_max(Player const& player) const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::height_max()");

      unsigned height = 0;
      for(unsigned t = 0; t < NUMBER_OF_TYPES; t++)
	height = max(height, icon(Type(t), player).height());

      DEBUG_RETURNING(height,
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::height_max()");
    } // unsigned Icons::height_max(player)

  /*****************************************************************************
   *
   * unsigned Icons::height_max() const
   *
   * Parameters:	-
   *
   * Result:	the maximal height of the icons
   * 
   * Version:	0.4.4
   *
   * Description:	result
   *
   ****************************************************************************/
  unsigned
    Icons::height_max() const
    {
      DEBUG_CALLING(INFO_GTK_ICON && INFO_GTK_VALUE,
		    "Icons::height_max()");

      unsigned height = 0;
      for(unsigned t = 0; t < NUMBER_OF_TYPES; t++)
	height = max(height, icon(Type(t)).height());

      DEBUG_RETURNING(height,
		      INFO_GTK_ICON && INFO_GTK_VALUE,
		      "Icons::height_max()");
    } // unsigned Icons::height_max()

} // namespace GTK_DOKO
#endif // #ifdef USE_UI_GTK
