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

namespace GTK_DOKO {

  /**
   **
   ** Constructor
   **
   ** @param	playfield	Playfield of the dialog
   ** @param	title		Title of the window
   **
   ** @return	-
   **
   ** @author	Diether Knof
   **
   ** @version	0.5.4
   **
   **/
  PlayfieldDialog::PlayfieldDialog(Playfield* const playfield,
				   string const& title) :
    Dialog(&(playfield->gui()), title), // the base class
  playfield_(playfield) // the playfield
  {
    DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_INIT,
		  "PlayfieldDialog::PlayfieldDialog()");

    DEBUG_RETURNING(VOID,
		    INFO_GTK_DIALOG && INFO_GTK_INIT,
		    "PlayfieldDialog::PlayfieldDialog()");
  } // PlayfieldDialog::PlayfieldDialog(Playfield* const playfield, string const& title = "")

  /**
   **
   ** Destructor
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @author	Diether Knof
   **
   ** @version	0.5.4
   **
   **/
  PlayfieldDialog::~PlayfieldDialog()
  {
    DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_INIT,
		  "PlayfieldDialog::~PlayfieldDialog()");

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

  /**
   **
   ** -> result
   **
   ** @param	-
   **
   ** @return	the playfield
   **
   ** @author	Diether Knof
   **
   ** @version	0.5.4
   **
   **/
  Playfield&
    PlayfieldDialog::playfield()
    {
      DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_VALUE,
		    "PlayfieldDialog::playfield()");

      DEBUG_ASSERTION((this->playfield_ != NULL),
		      "PlayfieldDialog::playfield()\n"
		      "  `this->playfield_` == NULL");

      DEBUG_RETURNING(*(this->playfield_),
		      INFO_GTK_DIALOG && INFO_GTK_VALUE,
		      "PlayfieldDialog::playfield()");
    } // Playfield& PlayfieldDialog::playfield()

  /**
   **
   ** manages the pressed key:
   ** <Space>, <Return> and <Escape> close the dialog
   **
   ** @param	key	the pressed key
   **
   ** @return	-
   **
   ** @author	Diether Knof
   **
   ** @version	0.5.4
   **
   **/
  void
    PlayfieldDialog::key(GdkEventKey* key)
    {
      DEBUG_CALLING(INFO_GTK_DIALOG && INFO_GTK_KEY,
		    "PlayfieldDialog::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 gui
	this->gui().key(key);
	break;
      } // switch (key->keyval)

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

} // namespace GTK_DOKO
#endif // #ifdef USE_UI_GTK
