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

namespace GTK_DOKO
{

  /*****************************************************************************
   *
   * TableDialog::TableDialog(class Table* table_a,
   *		  string const& title_a = "")
   *
   * Parameters:	table_a - pointer to the table
   *		title_a - title of the window
   *
   * Result:	none
   * 
   * Version:	0.3.7
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  TableDialog::TableDialog(class Table* table_a, string const& title_a) :
    Dialog(&(table_a->gui()), title_a), // the base class
  table_p(table_a) // the table
  {
    DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_INIT,
		  "TableDialog::TableDialog()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_DIALOG && INFO_GTK_INIT,
		    "TableDialog::TableDialog()");
  } // TableDialog::TableDialog(class Table* table_a)

  /*****************************************************************************
   *
   * TableDialog::~TableDialog()
   *
   * Parameters:	none
   *
   * Result:	none
   * 
   * Version:	0.3.7
   *
   * Description:	Destructor
   *
   ****************************************************************************/
  TableDialog::~TableDialog()
  {
    DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_INIT,
		  "TableDialog::~TableDialog()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_DIALOG && INFO_GTK_INIT,
		    "TableDialog::~TableDialog()");
  } // TableDialog::~TableDialog()

  /*****************************************************************************
   *
   * Table& TableDialog::table()
   *
   * Parameters:	none
   *
   * Result:	The table
   * 
   * Version:	0.3.7
   *
   * Description:	Result
   *
   ****************************************************************************/
  Table&
    TableDialog::table()
    {
      DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_VALUE,
		    "TableDialog::table()");

      DEBUG_ASSERTION((table_p != NULL),
		      "TableDialog::table()\n"
		      "  `table_p` == NULL");

      DEBUG_RETURNING(*table_p,
		      INFO_GTK_DIALOG && INFO_GTK_VALUE,
		      "TableDialog::table()");
    } // Table& TableDialog::table()

  /*****************************************************************************
   *
   * virtual void TableDialog::key(GdkEventKey* key)
   *
   * Parameters:	key - the pressed key
   *
   * Result:	none
   * 
   * Version:	0.3.7
   *
   * Description:	manages the pressed keys for the TableDialog window
   *
   ****************************************************************************/
  void
    TableDialog::key(GdkEventKey* key)
    {
      DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_KEY,
		    "TableDialog::key()");

#include <gdk/gdkkeysyms.h>

      switch (key->keyval) {
      case GDK_space:
      case GDK_Return: // close this window
#ifdef RELEASE
      case GDK_Escape:
#endif
	this->close();
	break;

      default: // pass the key to the table
	this->table().key(key);
	break;
      } // switch (key->keyval)

      DEBUG_RETURNING(VOID,
		      INFO_GTK_DIALOG && INFO_GTK_KEY,
		      "TableDialog::key()");
    } // void TableDialog::key(GdkKeyEvent);

}
#endif
