/**********************************************************************
 *
 *   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_GTK
#ifndef GTK_TABLE_HEADER
#define GTK_TABLE_HEADER

#include "table.dialog.h"

#include "pixmap.h"

#include "hands.h"
#include "names.h"
#include "icongroups.h"
#include "trick.h"
#include "poverty.h"
#include "trickpiles.h"
#include "last_trick.h"
#include "full_trick.h"
#include "party_points.h"


namespace GTK_DOKO {
#include <gtk/gtkwidget.h>
  class Playfield;

  class Table {
    public:
      // constructor
      Table(Playfield* const playfield);

      // inits the table
      void init();

      // loads the background
      bool background_load();
      bool background_load(string const& filename);

      // the variables
      class GTK_GUI& gui(); // the gui
      class Playfield& playfield(); // the playfield
      GtkWidget* widget(); // the event box
      GtkWidget* drawing_area(); // drawing area

      // pixmap
      GdkPixmap* pixmap();

    public:
      // width of the table
      unsigned width() const;
      // height of the table
      unsigned height() const;

    protected:
      // background pixmap
      Pixmap& background_pm();
      // background gc
      GdkGC* background_gc();

    public:

      Handgs& hands(); // the hands of the players
      Handg& hand(Player const& player); // the hand of the given player
      IconGroups& icongroups(); // the icongroups of the players
      IconGroup& icongroup(Player const& player); // icongroup of the given player
      Names& names(); // the names of the players
      Name& name(Player const& player); // the name of the given player
      TrickPiles& trickpiles(); // the trickpiles of the players
      TrickPile& trickpile(Player const& player); // trickpile of the given player
      Trick& trick(); // the trick
      Poverty& poverty(); // the elements for the poverty (p.e. cards)
      FullTrick& full_trick(); // The full trick window
      LastTrick& last_trick(); // The last trick window
      PartyPoints& party_points(); // the party points window

    public:

      void party_open(); // the party is opened
      void party_start(); // the party is started
      void game_open(); // the game is opened
      void game_start(); // the game is started
      void game_finish(); // the game is finished
      void game_close(); // the game is closed
      void party_finish(); // the party is finished
      void party_close(); // the party is closed

      // set the new minimum size
      void min_size_set();

      // update the cards
      void cards_update();

      // update the language
      void language_update();

      // update the table
      void update(int const x, int const y,
		  int const width, int const height);
      // update the table
      void update();

      // draws the whole table_pm and copies it to the table
      void draw_all();

      // draws the background of the table
      void background_draw();
      // draws the background of the table
      void background_draw(int const x, int const y,
			   int const width, int const height);

    private:

      // copies the graphic from the pixmap to the DrawingArea
      void expose(GdkEventExpose* event);
      // resizes the window
      void resize(GdkEventConfigure* configure_event);
      // a mouse click
      void mouse_click(GdkEventButton* button_event);


      // copies the graphic from the pixmap to the DrawingArea
      static gboolean expose_event(GtkWidget*, GdkEventExpose* event,
				   gpointer table_p);
      // resizes the window
      static gboolean resize_event(GtkWidget*, GdkEventConfigure* configure_event,
				   gpointer table_p);
      // a mouse click
      static gboolean mouse_click_event(GtkWidget*, GdkEventButton* button_event,
					gpointer table_p);
    protected:
      // key event
      static gboolean key_event(GtkWidget* widget, GdkEventKey* key,
				gpointer table);

    public:
      void key(GdkEventKey* key);

    private:
      Playfield* const playfield_p; // the playfield

      GtkWidget* event_box_p; // event box
      GtkWidget* drawing_area_p; // drawing area
      GdkPixmap* pixmap_p; // pixmap

      unsigned width_p; // width
      unsigned height_p; // height

      Pixmap background_pm_p; // background pixmap
      GdkGC* background_gc_p; // background gc

      Handgs hands_p; // the hands of the players
      Names names_p; // the names of the players
      IconGroups icongroups_p; // the icongroups of the players
      Trick trick_p; // the trick
      Poverty poverty_p; // the poverty elements
      TrickPiles trickpiles_p; // the trickpiles of the players
      FullTrick full_trick_p; // the full trick window
      LastTrick last_trick_p; // the last trick window
      PartyPoints party_points_p; // the last trick window

      // the cards for the border
      vector<Card> border_card;

    private:
      // constructor
      Table();
      // constructor -- not to be used
      Table(Table const&);
      // setting equal -- not to be used
      Table& operator=(Table const&);
  }; // class Table

} // namespace GTK_DOKO

#endif // #ifndef GTK_TABLE_HEADER
#endif // #ifdef USE_UI_GTK
