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

#ifdef USE_UI_GTKMM

#ifndef UI_GTKMM_HEADER
#define UI_GTKMM_HEADER

#include "../ui.h"
#include "base.h"
#include "thrower.h"

#include "../../misc/translator.h"


namespace Gtk {
  class Main;
  class Label;
  class StockButton;
  class Button;
  class Window;
  class TextView;
  class Object;
  class Widget;
} // namespace Gtk
#include <glibmm/refptr.h>
#include <gdkmm/pixbuf.h>

namespace UI_GTKMM_NS {
  class UI_GTKMM_Wrap;
  class Translations;
  class Cards;
  class Icons;
  class SplashScreen;
  class MainWindow;
  class PartySettings;
  class PlayersDB;
  class GameInfo;
  class Chatter;
  class About;
  class ChangeLog;
  class License;
  class CardsetLicense;
  class Table;
  class Preferences;
  class BugReport;
  class BugReportReplay;

  /**
   **
   ** @brief	the UI, created with gtkmm
   **
   ** @author	Diether Knof
   **
   ** @todo	replay game
   ** @todo	help
   ** @todo	messages (status line)
   ** @todo	drag'n drop (cardset, cards back, background)
   ** @todo	game log window
   **
   **/
  class UI_GTKMM : public UI, public Base {
    friend class Base;
    public:
    UI_GTKMM();

    ~UI_GTKMM();


    // initialize the ui
    void init(int& argc, char**& argv);

    // updates the UI
    void update();
    // sleeps 'sleep_usec' thousands of seconds
    // (< 0 for infinity)
    void sleep(unsigned const sleep_usec);

    // quit the main loop
    void main_quit();
    // stop sleeping (for timeout events)
    static bool stop_sleeping();

    // a key press
    bool key_press(GdkEventKey const* const key);

    // start new party
    void start_new_party();
    // end the party
    void end_party();
    // quit the program
    void quit_program();

    // updates the language
    void language_update();


    // the parts of a party
    void party_open(Party& party);
    void party_get_settings();
    void party_start();
    void party_start_round(unsigned const round);
    void party_finish();
    void party_close();

    // the parts of a game
    void game_open(Game& game);
    void game_cards_distributed();
    void game_redistribute();
    ::Reservation reservation_get(Player const& player);
    void game_start();
    void game_finish();
    void game_close();

    // the parts of a trick
    void trick_open(::Trick const& trick);
    void trick_full();
    void trick_move_in_pile();
    void trick_close();
    // get a card
    HandCard card_get(Player const& player);
    // the card is played
    void card_played(HandCard const& card);
    // an announcement is made
    void announcement_made(Announcement const& announcement,
			   Player const& player);
    // the player has swines
    void swines_announced(Player const& player);
    // the player has hyperswines
    void hyperswines_announced(Player const& player);

    // 'player' has a poverty and shifts
    void poverty_shifting(Player const& player);
    // 'player' shifts 'cardno' cards
    void poverty_shift(Player const& player, unsigned const cardno);
    // ask 'player' whether to accept the poverty
    void poverty_ask(Player const& player, unsigned const cardno);
    // the player 'player' has denied the poverty trumps
    void poverty_take_denied(Player const& player);
    // all players have denied to take the cards
    void poverty_take_denied_by_all();
    // the player 'player' has accepted the poverty trumps
    // and has returned 'cardno' cards with 'trumpno' trumps
    void poverty_take_accepted(Player const& player,
			       unsigned const cardno,
			       unsigned const trumpno);
    // 'player' shifts cards
    HandCards poverty_shift(Player& player);
    // returns whether 'player' accepts the poverty
    bool poverty_take_accept(Player& player,
			     unsigned const cardno);
    // the player changes the cards of the poverty
    HandCards poverty_cards_change(Player& player,
					  HandCards const& cards);
    // the poverty player 'player' gets 'cards'
    void poverty_cards_get_back(Player& player,
				HandCards const& cards);

    void marriage(Player const& bridegroom, Player const& bride);
    Player const* genscher_partner();
    void genscher(Player const& genscher, Player const& partner);

    // redrawing
    void redraw_all();
    void gametype_update();
    void player_update(Player const& player);
    void name_update(Player const& player);
    void hand_update(Player const& player);
    void teaminfo_update(Player const& player);

    void cards_update();
    void cards_back_update();
    void icons_update();

    // change of the rules
    void rule_update(int const type, void const* const old_value);
    // changes of the settings
    void setting_update(int const type, void const* const old_value);

    // load the help page
    void help_load(string const& page);


    // whether the ui is busy
    void set_busy();
    void set_not_busy();

    // 'player' has chatted 'message'
    void chat(string const& player, string const& message);

    // the status message has changed
    void status_message_changed(Translator::Translation const& status_message);
    // the progress has changed
    void progress_changed(double const progress_max);
    // the progress is finished
    void progress_finished();


    // information for the user
    void information(Translator::Translation const& message);
    // an error has occured
    void error(string const& message);


    // generate an error
    void generate_error(string const error_message);


    public: // the gtkmm part
    Thrower thrower;

    Gtk::Main* kit;
    Glib::RefPtr<Gdk::Colormap> colormap;

    Glib::RefPtr<Gdk::Pixbuf> logo;

    Translations* translations;

    Cards* cards;
    Icons* icons;

    SplashScreen* splash_screen;

    MainWindow* main_window;

    Table* table;

    PartySettings* party_settings;

    PlayersDB* players_db;

    GameInfo* game_info;

    License* license;
    CardsetLicense* cardset_license;
    ChangeLog* changelog;
    Chatter* chatter;
    About* about;

    Preferences* preferences;

    BugReport* bug_report;
    BugReportReplay* bug_report_replay;

    static bool sleeping;

    protected: // for Base, so that it can add itself
    std::list<Base*> parts;

    private: // unused
    UI_GTKMM(UI_GTKMM const& ui);
    UI_GTKMM& operator=(UI_GTKMM const& ui);
  }; // class UI_GTKMM : public UI, public Base

} // namespace UI_GTKMM_NS

#endif // #ifdef UI_GTKMM_HEADER

#endif // #ifdef USE_UI_GTKMM
