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

namespace GTK_DOKO {

  /**
   **
   ** inits the game submenu
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @author	Diether Knof
   ** 
   ** @version	0.5.1
   **
   **/
  void
    Menu::game_init()
    {
      DEBUG_CALLING(INFO_GTK_MENU && INFO_GTK_INIT,
		    "Menu::game_init()");

      { // create the submenu
	gtk_object_set_data(GTK_OBJECT(GTK_BIN(this->game_item)->child), "text",
			    new string("game"));
	this->labels.push_back(GTK_LABEL(GTK_BIN(this->game_item)->child));
	gtk_object_set_data(GTK_OBJECT(GTK_BIN(this->game_new_party)->child), "text",
			    new string("new party"));
	this->labels.push_back(GTK_LABEL(GTK_BIN(this->game_new_party)->child));
	gtk_object_set_data(GTK_OBJECT(GTK_BIN(this->game_party_settings)->child), "text",
			    new string("party settings"));
	this->labels.push_back(GTK_LABEL(GTK_BIN(this->game_party_settings)->child));
	gtk_object_set_data(GTK_OBJECT(GTK_BIN(this->game_quit)->child), "text",
			    new string("quit"));
	this->labels.push_back(GTK_LABEL(GTK_BIN(this->game_quit)->child));

	GtkWidget* menu = gtk_menu_new();
	gtk_menu_append(GTK_MENU(menu), this->game_new_party);
	gtk_menu_append(GTK_MENU(menu), this->game_party_settings);
	gtk_menu_append(GTK_MENU(menu), this->game_quit);
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(this->game_item), menu);
	gtk_menu_bar_append(GTK_MENU_BAR(this->bar), this->game_item);
      } // create the submenu


      // the events
      gtk_signal_connect(GTK_OBJECT(this->game_new_party), "activate",
			 GTK_SIGNAL_FUNC(Menu::game_new_party_event),
			 this);
      gtk_signal_connect(GTK_OBJECT(this->game_party_settings), "activate",
			 GTK_SIGNAL_FUNC(Dialog::show_event),
			 &(this->gui().playfield().party_settings()));
      gtk_signal_connect(GTK_OBJECT(this->game_quit), "activate",
			 GTK_SIGNAL_FUNC(GTK_GUI::quit_event),
			 NULL);

      DEBUG_RETURNING(VOID,
		      INFO_GTK_MENU && INFO_GTK_INIT,
		      "void Menu::game_init()");
    } // void Menu::game_init()


  /**
   **
   ** calls menu_game->new_party()
   **
   ** @param	menu	the menu
   **
   ** @return	-
   ** 
   ** @version	0.4.5
   **
   ** @author	Diether Knof
   **
   **/
  void
    Menu::game_new_party_event(GtkWidget* widget, gpointer menu)
    {
      DEBUG_CALLING(INFO_GTK_MENU && INFO_GTK_EVENT,
		    "Menu::game_new_party_event()");

      DEBUG_ASSERTION((menu != NULL),
		      "Menu::game_new_party_event():\n"
		      "  'menu' == NULL");

      ::game_status = GAMESTATUS::PARTY_NEW;
      static_cast<Menu*>(menu)->gui().main_quit();

      DEBUG_RETURNING(VOID,
		      INFO_GTK_MENU && INFO_GTK_EVENT,
		      "Menu::game_new_party_event()");
    } // void Menu::game_new_party_event(GtkWidget*, gpointer menu)

} // namespace GTK_DOKO

#endif // #ifdef USE_UI_GTK
