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

#include "main_window.h"
#include "menu.h"

#include "ui.h"
#include "cards.h"

#include <gtkmm/box.h>
namespace UI_GTKMM_NS {

  /**
   **
   ** Constructor
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.5.2
   **
   **/
  MainWindow::MainWindow(Base* const parent) :
    Base(parent),
  Window(),
  icon(),
  menu(new Menu(this)),
  container(Gtk::manage(new Gtk::VBox(false, 0)))
  {
    {
#include "../icon.xpm"
      this->icon = Gdk::Pixbuf::create_from_xpm_data(icon_xpm);
      this->set_icon(this->icon);
    }

    this->set_position(Gtk::WIN_POS_CENTER);
    this->set_minimal_size();


    this->signal_key_press_event().connect(SigC::slot(*this, &MainWindow::key_press));

    this->add(*(this->container));
    this->container->pack_start(*(this->menu), false, true);

    this->container->show();

    this->signal_hide().connect(SigC::slot(*this,
					  &MainWindow::quit_program_event)
			      );

    return ;
  } // MainWindow::MainWindow(Base* const parent)

  /**
   **
   ** Destruktor
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @author	Diether Knof
   **
   ** @version	0.5.2
   **
   **
   **/
  MainWindow::~MainWindow()
  {
    delete this->menu;

    return ;
  } // MainWindow::~MainWindow()

  /**
   **
   ** start a new party
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    MainWindow::start_new_party_event()
    {
      this->ui->start_new_party();

      return ;
    } // void MainWindow::start_new_party_event()

  /**
   **
   ** quits the program.
   ** This function is just a wrapper for 'UI_GTKMM::quit_program()',
   ** because 'UI_GTKMM' is no Gtk object, so it cannot be used by the signals.
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.5.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    MainWindow::quit_program_event()
    {
      this->ui->quit_program();

      return ;
    } // void MainWindow::quit_program_event()

  /**
   **
   ** generates an error
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.3
   **
   ** @author	Diether Knof
   **
   **/
  void
    MainWindow::generate_error_event()
    {
      this->ui->generate_error(::translator("generated error").translation());

      return ;
    } // void MainWindow::generate_error_event()

  /**
   **
   ** a key has been pressed
   ** this function is not in 'UI_GTKMM', because 'UI_GTKMM' is not derived
   ** from a 'Gtk::Widget'
   **
   ** @param	key	the key
   **
   ** @return	from 'ui->key_press(key)'
   **
   ** @version	0.6.1
   **
   ** @author	Diether Knof
   **
   **/
  bool
    MainWindow::key_press(GdkEventKey* key)
    {
      return this->ui->key_press(key);
    } // bool MainWindow::key_press(GdkEventKey* key)

  /**
   **
   ** the window is hidden -- quit the program
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.3
   **
   ** @author	Diether Knof
   **
   **/
  void
    MainWindow::on_hide()
    {
      this->ui->quit_program();

      return ;
    } // void MainWindow::on_hide()

  /**
   **
   ** sets the minimal size of the window (depends on the size of the cards)
   **
   ** @param	-
   **
   ** @return	-
   **
   ** @version	0.6.7
   **
   ** @author	Diether Knof
   **
   **/
  void
    MainWindow::set_minimal_size()
    {
      Gdk::Geometry geometry;
      geometry.min_width = 5 * this->ui->cards->height();
      geometry.min_height = 5 * this->ui->cards->height();

      this->set_geometry_hints(*this, geometry, Gdk::HINT_MIN_SIZE);

      return ;
    } // void MainWindow::set_minimal_size()
} // namespace UI_GTKMM_NS

#endif // #ifdef USE_UI_GTKMM
