/**********************************************************************
 *
 *   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 "settings.h"
#include "settings.cards_order.h"
#include "gtk_gui.h"
#include "card.h"

#include "../../party/party.h"
#include "../../party/rule.h"
#include "../../misc/language.h"

namespace GTK_DOKO {

  /**
   **
   ** Constructor
   **
   ** @param	settings	general settings this object is part of
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  Settings::CardsOrder::CardsOrder(Settings* settings) :
    settings_p(settings), // the settings
  bookmark_p(name(Setting::CARDS_ORDER)), // the bookmark
  alignment(gtk_alignment_new(0.5, 0.5, 0, 0)), // the alignment
  arrow_container(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  arrow_left(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  arrow_right(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  tcolor_container(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  pixmap(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  direction_up(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  direction_down(::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
  sorted(gtk_radio_button_new_with_label(NULL, "")),
  mixed(gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(sorted), "")),
  mix_cards_button(gtk_button_new_with_label(""))
  {
    DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_INIT,
		  "Settings::CardsOrder::CardsOrder()");

    GtkWidget* container(gtk_vbox_new(FALSE, 0));
    GtkWidget* card_container(gtk_hbox_new(TRUE, 0));

    gtk_container_add(GTK_CONTAINER(alignment), container);

    // set the border
    gtk_container_set_border_width(GTK_CONTAINER(container), 10);
    gtk_box_set_spacing(GTK_BOX(container), 40);

    // set the spacing between the cards
    gtk_box_set_spacing(GTK_BOX(card_container), 20);

    // pack the card container in the container
    gtk_container_add(GTK_CONTAINER(container), card_container);

    { // mixed order
      GtkWidget* mix_alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
      GtkWidget* mix_container = gtk_vbox_new(FALSE, 0);
      gtk_container_add(GTK_CONTAINER(mix_container), sorted);
      gtk_container_add(GTK_CONTAINER(mix_container), mixed);
      gtk_container_add(GTK_CONTAINER(mix_alignment), mix_container);
      gtk_container_add(GTK_CONTAINER(container), mix_alignment);
    } // mixed order
    { // button to mix the cards
      GtkWidget* mix_alignment = gtk_alignment_new(0.5, 0.5, 0, 0);
      gtk_container_add(GTK_CONTAINER(mix_alignment), mix_cards_button);
      gtk_container_add(GTK_CONTAINER(container), mix_alignment);
    } // button to mix the cards

    // create the five widgets
    for (unsigned c = 0; c < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); c++) {
      tcolor_container[c] = gtk_vbox_new(FALSE, 0);
      pixmap[c] = gui().cards().card(Card()).widget();
      direction_up[c] = gtk_radio_button_new_with_label(NULL, "");
      direction_down[c] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(direction_up[c]), "");

      // the arrow buttons
      arrow_container[c] = gtk_table_new(1, 2, TRUE);

      arrow_left[c] = gtk_button_new();
      gtk_container_add(GTK_CONTAINER(arrow_left[c]),
			gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_OUT));
      arrow_right[c] = gtk_button_new();
      gtk_container_add(GTK_CONTAINER(arrow_right[c]),
			gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT));

      // pack the widgets in the container

      gtk_container_add(GTK_CONTAINER(card_container), tcolor_container[c]);

      // the buttons
      gtk_table_attach_defaults(GTK_TABLE(arrow_container[c]),
				arrow_left[c],
				0, 1, 0, 1);
      gtk_table_attach_defaults(GTK_TABLE(arrow_container[c]),
				arrow_right[c],
				1, 2, 0, 1);
      gtk_container_add(GTK_CONTAINER(tcolor_container[c]), arrow_container[c]);
      // the pixmap
      gtk_container_add(GTK_CONTAINER(tcolor_container[c]), pixmap[c]);

      // the direction
      gtk_container_add(GTK_CONTAINER(tcolor_container[c]), direction_up[c]);
      gtk_container_add(GTK_CONTAINER(tcolor_container[c]), direction_down[c]);

      // events
      // toggle the direction
      gtk_signal_connect(GTK_OBJECT(direction_up[c]), "clicked",
			 GTK_SIGNAL_FUNC(set_direction_event),
			 this);
      gtk_signal_connect(GTK_OBJECT(direction_down[c]), "clicked",
			 GTK_SIGNAL_FUNC(set_direction_event),
			 this);
      // push the position
      gtk_signal_connect(GTK_OBJECT(arrow_left[c]), "clicked",
			 GTK_SIGNAL_FUNC(pos_to_left_event),
			 this);
      gtk_signal_connect(GTK_OBJECT(arrow_right[c]), "clicked",
			 GTK_SIGNAL_FUNC(pos_to_right_event),
			 this);
    }

    // mix the cards
    gtk_signal_connect(GTK_OBJECT(sorted), "toggled",
		       GTK_SIGNAL_FUNC(sort_cards_event),
		       this);
    gtk_signal_connect(GTK_OBJECT(mixed), "toggled",
		       GTK_SIGNAL_FUNC(mix_cards_event),
		       this);
    gtk_signal_connect(GTK_OBJECT(mix_cards_button), "clicked",
		       GTK_SIGNAL_FUNC(mix_cards_event),
		       this);

    // show all widgets
    gtk_widget_show_all(widget());

    DEBUG_RETURNING(VOID,
		    INFO_GTK_SETTINGS && INFO_GTK_INIT,
		    "Settings::CardsOrder::CardsOrder()");
  } // Settings::CardsOrder::CardsOrder(Settings* settings)

  /**
   **
   ** inits the cards order:
   ** updates the cards and the language
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::init()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_INIT,
		    "Settings::CardsOrder::init()");

      this->update();
      this->cards_update();
      this->language_update();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_INIT,
		      "Settings::CardsOrder::init()");
    } // void Settings::CardsOrder::init()

  /**
   **
   ** update the sensivitity:
   ** nothing to do
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::sensitivity_update()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_INIT,
		    "Settings::CardsOrder::sensitivity_update()");

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_INIT,
		      "Settings::CardsOrder::sensitivity_update()");
    } // void Settings::CardsOrder::sensitivity_update()

  /**
   **
   ** update all values
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::update()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_INIT,
		    "Settings::CardsOrder::update()");

      for (unsigned n = 0; n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); n++) {
	switch (::setting(::Setting::CARDS_ORDER).direction(n)) {
	case ::CardsOrder::UP:
	  gtk_signal_handler_block_by_func(GTK_OBJECT(this->direction_up[n]),
					   GTK_SIGNAL_FUNC(Settings::CardsOrder::set_direction_event),
					   gpointer(this));
	  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->direction_up[n]),
				       TRUE);
	  gtk_signal_handler_unblock_by_func(GTK_OBJECT(this->direction_up[n]),
					     GTK_SIGNAL_FUNC(Settings::CardsOrder::set_direction_event),
					     gpointer(this));
	  break;
	case ::CardsOrder::DOWN:
	  gtk_signal_handler_block_by_func(GTK_OBJECT(this->direction_down[n]),
					   GTK_SIGNAL_FUNC(Settings::CardsOrder::set_direction_event),
					   gpointer(this));
	  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->direction_down[n]),
				       TRUE);
	  gtk_signal_handler_unblock_by_func(GTK_OBJECT(this->direction_down[n]),
					     GTK_SIGNAL_FUNC(Settings::CardsOrder::set_direction_event),
					     gpointer(this));
	  break;
	default:
	  DEBUG_ASSERTION(false,
			  "Settings::CardsOrder::update():"
			  "  unknown direction");
	  break;
	} // switch (::setting(::Setting::CARDS_ORDER).direction(n))
      } // for (n)

      if (::setting(::Setting::CARDS_ORDER).sorted()) {
	gtk_signal_handler_block_by_func(GTK_OBJECT(this->sorted),
					 GTK_SIGNAL_FUNC(Settings::CardsOrder::sort_cards_event),
					 gpointer(this));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->sorted),
				     TRUE);
	gtk_signal_handler_unblock_by_func(GTK_OBJECT(this->sorted),
					   GTK_SIGNAL_FUNC(Settings::CardsOrder::sort_cards_event),
					   gpointer(this));
      } else { // if !(::setting(::Setting::CARDS_ORDER).sorted())
	gtk_signal_handler_block_by_func(GTK_OBJECT(this->mixed),
					 GTK_SIGNAL_FUNC(Settings::CardsOrder::mix_cards_event),
					 gpointer(this));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->mixed),
				     TRUE);
	gtk_signal_handler_unblock_by_func(GTK_OBJECT(this->mixed),
					   GTK_SIGNAL_FUNC(Settings::CardsOrder::mix_cards_event),
					   gpointer(this));
      } // if !(::setting(::Setting::CARDS_ORDER).sorted())

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_INIT,
		      "Settings::CardsOrder::update()");
    } // void Settings::CardsOrder::update()

  /**
   **
   ** redraws the card at position n
   **
   ** @param	n	number of the pixmap to be drawn
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	(re)draws the pixmap
   **
   **/
  void
    Settings::CardsOrder::draw_pixmap(unsigned const n)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		    "Settings::CardsOrder::draw_pixmap(n)");

      // draw the pixmaps

      switch(::setting(Setting::CARDS_ORDER).tcolor(n)) {
      case Card::TRUMP:
	gtk_pixmap_set(GTK_PIXMAP(pixmap[n]),
		       gui().cards().card(Card::CLUB_QUEEN).pixmap(),
		       gui().cards().card(Card::CLUB_QUEEN).mask());
	break;
      case Card::CLUB:
	gtk_pixmap_set(GTK_PIXMAP(pixmap[n]),
		       gui().cards().card(Card(Card::CLUB, Card::ACE)).pixmap(),
		       gui().cards().card(Card(Card::CLUB, Card::ACE)).mask());
	break;
      case Card::SPADE:
	gtk_pixmap_set(GTK_PIXMAP(pixmap[n]),
		       gui().cards().card(Card(Card::SPADE, Card::ACE)).pixmap(),
		       gui().cards().card(Card(Card::SPADE, Card::ACE)).mask());
	break;
      case Card::HEART:
	gtk_pixmap_set(GTK_PIXMAP(pixmap[n]),
		       gui().cards().card(Card(Card::HEART, Card::ACE)).pixmap(),
		       gui().cards().card(Card(Card::HEART, Card::ACE)).mask());
	break;
      case Card::DIAMOND:
	gtk_pixmap_set(GTK_PIXMAP(pixmap[n]),
		       gui().cards().card(Card(Card::DIAMOND, Card::ACE)
					 ).pixmap(),
		       gui().cards().card(Card(Card::DIAMOND, Card::ACE)
					 ).mask());
	break;
      default:

	DEBUG_ASSERTION(false,
			"Settings::CardsOrder::draw_pixmap(n)\n"
			"  TColor not valid");
      } // switch(::setting(Setting::CARDS_ORDER).tcolor(n))

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		      "Settings::CardsOrder::draw_pixmap(n)");
    } // void Settings::CardsOrder::draw_pixmap(unsigned const n)

  /**
   **
   ** -> result
   **
   ** @param	-
   **
   ** @return	the gui
   **
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  GTK_GUI&
    Settings::CardsOrder::gui()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		    "Settings::CardsOrder::gui()");

      DEBUG_RETURNING(settings().gui(),
		      INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		      "Settings::CardsOrder::gui()");
    } // GTK_GUI& Settings::CardsOrder::gui()

  /*****************************************************************************
   *
   * Settings& Settings::CardsOrder::settings()
   *
   * Parameters:	none
   *
   * Result:	the settings
   *
   * Version:	0.3.7
   *
   * Description:	Result
   *
   ****************************************************************************/
  Settings&
    Settings::CardsOrder::settings()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		    "Settings::CardsOrder::settings()");

      DEBUG_ASSERTION((settings_p != NULL),
		      "Settings& Settings::CardsOrder::settings():\n"
		      "  'settings_p' == NULL");

      DEBUG_RETURNING(*settings_p,
		      INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		      "Settings::CardsOrder::settings()");
    } // Settings& Settings::CardsOrder::settings()

  /*****************************************************************************
   *
   * GtkWidget* Settings::CardsOrder::bookmark()
   *
   * Parameters:	none
   *
   * Result:	the bookmark
   *
   * Version:	0.3.6
   *
   * Description:	Result
   *
   ****************************************************************************/
  GtkWidget*
    Settings::CardsOrder::bookmark()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		    "Settings::CardsOrder::window()");

      DEBUG_RETURNING(this->bookmark_p.widget(),
		      INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		      "Settings::CardsOrder::bookmark()");
    } // GtkWidget* Settings::CardsOrder::bookmark()

  /*****************************************************************************
   *
   * GtkWidget* Settings::CardsOrder::widget()
   *
   * Parameters:	none
   *
   * Result:	the widget (container)
   *
   * Version:	0.3.6
   *
   * Description:	Result
   *
   ****************************************************************************/
  GtkWidget*
    Settings::CardsOrder::widget()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		    "Settings::CardsOrder::widget()");

      DEBUG_ASSERTION((alignment != NULL),
		      "Settings::CardsOrder::widget()\n"
		      "  `alignment` == NULL");

      DEBUG_RETURNING(alignment,
		      INFO_GTK_SETTINGS && INFO_GTK_VALUE,
		      "Settings::CardsOrder::widget()");
    } // GtkWidget* Settings::CardsOrder::widget()


  /**
   **
   ** call card_order->set_direction(...) to set the direction of the cards order
   **
   ** @param	button		the clicked button widget
   ** @param	cards_order	pointer to the cardorder settings
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	call cards_order->set_direction()
   **
   **/
  void
    Settings::CardsOrder::set_direction_event(GtkWidget* button,
					      gpointer cards_order)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::set_direction_event()");

      if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) == TRUE) {
	// search the button widget
	unsigned n;
	for (n = 0; n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); n++) {
	  if (((CardsOrder*)cards_order)->direction_up[n] == button) {
	    ((CardsOrder*)cards_order)->set_direction(n, ::CardsOrder::UP);
	    break;
	  }
	  if (((CardsOrder*)cards_order)->direction_down[n] == button) {
	    ((CardsOrder*)cards_order)->set_direction(n, ::CardsOrder::DOWN);
	    break;
	  }
	} // for (n)
	DEBUG_ASSERTION(n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS),
			"Settings::CardsOrder::set_direction_event()\n"
			"  Pressed button not found");
      } // if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) == TRUE)

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::set_direction_event()");
    } // void Settings::CardsOrder::set_direction_event(GtkWidget* button, gpointer cards_order)

  /*****************************************************************************
   *
   * void Settings::CardsOrder::pos_to_left_event(GtkWidget* button,
   *				    gpointer cards_order)
   *
   * Parameters:	button	- the clicked button widget
   *		cards_order - pointer to the cardorder settings
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	call cards_order->pos_to_left()
   *
   ****************************************************************************/
  void
    Settings::CardsOrder::pos_to_left_event(GtkWidget* button,
					    gpointer cards_order)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::pos_to_left_event()");

      // search the button widget
      unsigned n;
      for (n = 0; n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); n++)
	if (((CardsOrder*)cards_order)->arrow_left[n] == button)
	  break;

      DEBUG_ASSERTION(n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS),
		      "Settings::CardsOrder::pos_to_left_event()\n"
		      "  Pressed button not found");

      ((CardsOrder*)cards_order)->pos_to_left(n);
      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::pos_to_left_event()");
    } // void Settings::CardsOrder::pos_to_left_event()

  /*****************************************************************************
   *
   * void Settings::CardsOrder::pos_to_right_event(GtkWidget* button,
   *				    gpointer cards_order)
   *
   * Parameters:	button	- the clicked button widget
   *		cards_order - pointer to the cardorder settings
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	call cards_order->pos_to_left()
   *
   ****************************************************************************/
  void
    Settings::CardsOrder::pos_to_right_event(GtkWidget* button,
					     gpointer cards_order)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::pos_to_right_event()");

      // search the button widget
      unsigned n;
      for (n = 0; n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); n++)
	if (((CardsOrder*)cards_order)->arrow_right[n] == button)
	  break;

      DEBUG_ASSERTION(n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS),
		      "Settings::CardsOrder::pos_to_right_event()\n"
		      "  Pressed button not found");

      ((CardsOrder*)cards_order)->pos_to_left((n + 1) % ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS));
      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::pos_to_right_event()");
    } // void Settings::CardsOrder::pos_to_right_event()

  /**
   **
   ** call cards_order->sort_cards() to sort the cards
   **
   ** @param	cards_order	pointer to the cardorder settings
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::sort_cards_event(GtkWidget* button,
					   gpointer cards_order)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::sort_cards_event()");

      if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) == TRUE)
	((CardsOrder*)cards_order)->sort_cards();
      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::sort_cards_event()");
    } // void Settings::CardsOrder::sort_cards_event(GtkWidget* button, gpointer cards_order)

  /**
   **
   ** call cards_order->mix_cards() to mix the cards
   **
   ** @param	cards_order	pointer to the cardorder settings
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::mix_cards_event(GtkWidget* button,
					  gpointer cards_order)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::mix_cards_event()");

      if ((button == ((CardsOrder*)cards_order)->mix_cards_button)
	  || (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) == TRUE))
	((CardsOrder*)cards_order)->mix_cards();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::mix_cards_event()");
    } // void Settings::CardsOrder::mix_cards_event()


  /**
   **
   ** set the sorting direction of the 'n'th tcolor to 'direction'
   **
   ** @param	n		the number of the clicked button widget
   ** @param	direction	the direction
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::set_direction(unsigned const n,
					::CardsOrder::Direction const direction)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::set_direction(n, direction)");

      // set to sorted
      ::setting(Setting::CARDS_ORDER).sorted_set(true);

      // set the direction
      ::setting(Setting::CARDS_ORDER).direction_set(::setting(Setting::CARDS_ORDER).tcolor(n),
						    direction);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::set_direction(n, direction)");
    } // void Settings::CardsOrder::set_direction(unsigned const n, ::CardsOrder::Direction const direction)

  /*****************************************************************************
   *
   * void Settings::CardsOrder::pos_to_left(unsigned const n)
   *
   * Parameters:	n - the number of the clicked button widget
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	call fonts->open_name_font_selector()
   *
   ****************************************************************************/
  void
    Settings::CardsOrder::pos_to_left(unsigned const n)
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::pos_to_left()");

      DEBUG_ASSERTION((n >= 0) && (n < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS)),
		      "Settings::CardsOrder::pos_to_left(n)"
		      "  'n' not valid (< 0 || >= ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS))");


      // set to sorted
      ::setting(Setting::CARDS_ORDER).sorted_set(true);

      // toggle the direction
      ::setting(Setting::CARDS_ORDER).pos_to_left(n);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::pos_to_left()");
    } // void Settings::CardsOrder::pos_to_left()


  /**
   **
   ** set the sort mode to 'sorted' and mix the cards
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::sort_cards()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::sort_cards()");

      ::setting(Setting::CARDS_ORDER).sorted_set(true);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::sort_cards()");
    } // void Settings::CardsOrder::sort_cards()

  /**
   **
   ** set the sort mode to 'mixed' and mix the cards
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    Settings::CardsOrder::mix_cards()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		    "Settings::CardsOrder::mix_cards()");

      ::setting(Setting::CARDS_ORDER).mix();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_EVENT,
		      "Settings::CardsOrder::mix_cards()");
    } // void Settings::CardsOrder::mix_cards()


  /*****************************************************************************
   *
   * void Settings::CardsOrder::draw_all()
   *
   * Parameters:	-
   *
   * Result:	-
   * 
   * Version:	0.4.2
   *
   * Description:	redraws the cards and the direction buttons
   *
   ****************************************************************************/
  void
    Settings::CardsOrder::draw_all()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		    "Settings::CardsOrder::draw_all()");

      this->cards_update();
      this->language_update();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		      "Settings::CardsOrder::draw_all()");
    } // void Settings::CardsOrder::cards_update()

  /*****************************************************************************
   *
   * void Settings::CardsOrder::cards_update()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.3.6
   *
   * Description:	updates the cards in the 
   *
   ****************************************************************************/
  void
    Settings::CardsOrder::cards_update()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		    "Settings::CardsOrder::cards_update()");

      for (unsigned c = 0; c < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); c++)
	this->draw_pixmap(c);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		      "Settings::CardsOrder::cards_update()");
    } // void Settings::CardsOrder::cards_update()

  /**
   **
   ** updates the language in all elements of the cards order settings
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.5.1
   **
   ** @author	updates the language in the cards order settings
   **
   **/
  void
    Settings::CardsOrder::language_update()
    {
      DEBUG_CALLING(INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		    "Settings::CardsOrder::language_update()");

      this->bookmark_p.language_update();

      for (unsigned c = 0; c < ::party.rule()(Rule::NUMBER_OF_CARD_TCOLORS); c++) {
	gtk_label_set_text(GTK_LABEL(GTK_BIN(direction_up[c])->child),
			   language(name(::CardsOrder::UP)
				   ).c_str());
	gtk_label_set_text(GTK_LABEL(GTK_BIN(direction_down[c])->child),
			   language(name(::CardsOrder::DOWN)
				   ).c_str());
      }

      gtk_label_set_text(GTK_LABEL(GTK_BIN(sorted)->child),
			 language("sorted").c_str());
      gtk_label_set_text(GTK_LABEL(GTK_BIN(mixed)->child),
			 language("mixed").c_str());
      gtk_label_set_text(GTK_LABEL(GTK_BIN(mix_cards_button)->child),
			 (" " + language("mix cards") + " ").c_str());

      DEBUG_RETURNING(VOID,
		      INFO_GTK_SETTINGS && INFO_GTK_UPDATE,
		      "Settings::CardsOrder::language_update()");
    } // void Settings::CardsOrder::language_update()

} // namespace GTK_DOKO

#endif // #ifdef USE_UI_GTK
