/**********************************************************************
 *
 *   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 "ui.h"
#include "translations.h"
#include "splash_screen.h"
#include "cards.h"
#include "icons.h"
#include "party_settings.h"
#include "players_db.h"
#include "rules.h"
#include "table.h"
#include "hand.h"
#include "icongroup.h"
#include "cardset_license.h"
#include "main_window.h"

#include "../../basistypes.h"
#include "../../party/party.h"
#include "../../misc/setting.h"

#include <gtkmm/label.h>
#include <gtkmm/button.h>
#include <gtkmm/textview.h>

namespace UI_GTKMM_NS {

  /**
   **
   ** updates all language elements
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::language_update()
    {
      this->translations->language_update();

      for (vector<Base*>::iterator p = this->parts.begin();
	   p != this->parts.end();
	   p++)
	(*p)->language_update();

      return ;
    } // void UI_GTKMM::language_update()

  /**
   **
   ** updates all cards
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::cards_update()
    {
      if (this->main_window)
	this->main_window->set_minimal_size();

      if (this->icons)
	this->icons->update_managed();

      if (this->cards)
	this->cards->update_managed();

      if (this->cardset_license)
	this->cardset_license->license_update();

      for (vector<Base*>::iterator p = this->parts.begin();
	   p != this->parts.end();
	   p++)
	(*p)->cards_update();

      if (this->table)
	this->table->mouse_cursor_update();

      return ;
    } // void UI_GTKMM::cards_update()

  /**
   **
   ** updates all cards back
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::cards_back_update()
    {
      for (vector<Base*>::iterator p = this->parts.begin();
	   p != this->parts.end();
	   p++)
	(*p)->cards_back_update();

      if (this->table)
	this->table->mouse_cursor_update();

      return ;
    } // void UI_GTKMM::cards_back_update()

  /**
   **
   ** updates all icons
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::icons_update()
    {
      this->icons->update_managed();

      if (this->table)
	this->table->icons_update();

      return ;
    } // void UI_GTKMM::icons_update()

  /**
   **
   ** redraw all (of the playfield)
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::redraw_all()
    { 
      if (this->table) {
	this->table->draw_all();
	this->table->mouse_cursor_update();
      }

      return ;
    } // void UI_GTKMM::redraw_all()

  /**
   **
   ** update the gametype icon
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.3
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::gametype_update()
    { 
      if (this->table)
	this->table->draw_all();

      return ;
    } // void UI_GTKMM::gametype_udpate()

  /**
   **
   ** update the 'player'
   **
   ** @param	player	the player
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::player_update(Player const& player)
    {
      if (this->party_settings)
	this->party_settings->player_update(player);
      this->name_update(player);

      return ;
    } // void UI_GTKMM::player_update(player)

  /**
   **
   ** update the name of 'player'
   **
   ** @param	player	the player
   **
   ** @return	-
   **
   ** @version	0.5.2
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::name_update(Player const& player)
    {
      if (this->players_db)
	this->players_db->name_changed(player);
      if (this->party_settings)
	this->party_settings->name_update(player);
      if (this->table) {
	this->table->name_changed(player);
	this->table->mouse_cursor_update();
      }

      return ;
    } // void UI_GTKMM::name_update(player)

  /**
   **
   ** update the hand of 'player'
   **
   ** @param	player	the player
   **
   ** @return	-
   **
   ** @version	0.6.0
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::hand_update(Player const& player)
    { 
      if (this->table) {
	this->table->hand(player).draw();
	this->table->mouse_cursor_update();
      }

      return ;
    } // void UI_GTKMM::hand_update(player)

  /**
   **
   ** update the team icon of 'player'
   **
   ** @param	player	the player
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::teaminfo_update(Player const& player)
    { 
      if (this->table) {
	this->table->icongroup(player).draw_team();
	this->table->mouse_cursor_update();
      }

      return ;
    } // void UI_GTKMM::teaminfo_udpate(player)

  /**
   **
   ** update the rule
   **
   ** @param	type		the rule, that has changed
   ** @param	old_value	old value
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::rule_update(int const type, void const* const old_value)
    {
      if (this->party_settings)
	this->party_settings->rules->update(type);

      return ;
    } // void UI_GTKMM::rule_update(int const type, void const* const old_value)

  /**
   **
   ** update the setting
   **
   ** @param	type		the setting, that has changed
   ** @param	old_value	old value
   **
   ** @return	-
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::setting_update(int const type, void const* const old_value)
    {
      switch(type) {
      case Setting::NAME:
	for (unsigned p = 0; p < ::party.playerno(); p++)
	  this->name_update(::party.player(p));
	break;
      case Setting::CARDSET:
	if (this->cards)
	  this->cards->load_all();
	if (this->icons)
	  this->icons->load();

	if (this->cards)
	  this->cards_update();
	break;
      case Setting::CARDS_BACK:
	if (this->cards) {
	  this->cards->load_back();
	  this->cards_update();
	}
	break;
      case Setting::ORIGINAL_CARDS_SIZE:
	if (::setting(Setting::ORIGINAL_CARDS_SIZE) == true)
	  ::setting.set(Setting::CARDS_HEIGHT, this->cards->height_original());
      case Setting::CARDS_HEIGHT:
	if (this->cards)
	  this->cards->update_scaling();
	if (this->icons)
	  this->icons->update_scaling();

	this->cards_update();
	break;
      case Setting::SHOW_SPECIAL_POINTS_IN_TRICKPILES:
      case Setting::SHOW_KNOWN_TEAMS_IN_GAME:
      case Setting::SHOW_SOLOPLAYER_IN_GAME:
	if (this->table)
	  this->table->draw_all();
	break;
      default:
	break;
      } // switch(type)

      for (vector<Base*>::iterator p = this->parts.begin();
	   p != this->parts.end();
	   p++)
	(*p)->setting_update(type);

      return ;
    } // void UI_GTKMM::setting_update(int const type, void const* const old_value)

  /**
   **
   ** the status message has changed
   **
   ** @param	status_message	the status message
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::status_message_changed(Translator::Translation const& status_message)
    {
      if (this->splash_screen)
	this->splash_screen->status_message_changed(status_message);

      return ;
    } // void UI_GTKMM::status_message_changed(Translator::Translation const& status_message)

  /**
   **
   ** the program is busy
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.7
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::set_busy()
    {
      this->UI::set_busy();
      this->table->mouse_cursor_update();
      return ;
    } // void UI_GTKMM::set_busy()

  /**
   **
   ** the program is not busy any more
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.7
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::set_not_busy()
    {
      this->UI::set_not_busy();
      this->table->mouse_cursor_update();
      return ;
    } // void UI_GTKMM::set_not_busy()

  /**
   **
   ** the progress has changed
   **
   ** @param	progress	the progress
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::progress_changed(double const progress)
    {
      if (this->splash_screen)
	this->splash_screen->progress_changed(progress);

      return ;
    } // void UI_GTKMM::progress_changed(double const progress)

  /**
   **
   ** the progress is finished
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    UI_GTKMM::progress_finished()
    {
      return ;
    } // void UI_GTKMM::progress_finished()

} // namespace UI_GTKMM_NS

#endif // #ifdef USE_UI_GTKMM
