/**********************************************************************
 *
 *   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 "XGtkButton.h"

#include "../../../misc/language.h"

namespace GTK_DOKO
{

  /*****************************************************************************
   *
   * XGtkButton::XGtkButton(string const& text)
   *
   * Parameters:	text - text for the button
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  XGtkButton::XGtkButton(string const& text) :
    XGtkWidget(),
  button_p(gtk_button_new_with_label("")) // the button
  {
    DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_INIT,
		  "XGtkButton::XGtkButton()");

    gtk_object_set_data(GTK_OBJECT(this->button()),
			"text",
			new string(text));

    // set the text of the check widget
    this->language_update();

    // show all widgets
    gtk_widget_show_all(this->widget());

    DEBUG_RETURNING(VOID,
		    INFO_GTK_WIDGET && INFO_GTK_INIT,
		    "XGtkButton::XGtkButton()");
  } // XGtkButton::XGtkButton()

  /*****************************************************************************
   *
   * XGtkButton::~XGtkButton()
   *
   * Parameters:	-
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	Destructor
   *
   ****************************************************************************/
  XGtkButton::~XGtkButton()
  {
    DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_INIT,
		  "XGtkButton::~XGtkButton()");

    delete (string*)gtk_object_get_data(GTK_OBJECT(this->widget()), "text");
    gtk_widget_destroy(this->widget());

    DEBUG_RETURNING(VOID,
		    INFO_GTK_WIDGET && INFO_GTK_INIT,
		    "XGtkButton::~XGtkButton()");
  } // XGtkButton::XGtkButton()

  /*****************************************************************************
   *
   * GtkWidget* XGtkButton::widget()
   *
   * Parameters:	-
   *
   * Result:	the widget (container)
   *
   * Version:	0.4.3
   *
   * Description:	Result
   *
   ****************************************************************************/
  GtkWidget*
    XGtkButton::widget()
    {
      DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_VALUE,
		    "XGtkButton::widget()");

      DEBUG_RETURNING(this->button(),
		      INFO_GTK_WIDGET && INFO_GTK_VALUE,
		      "XGtkButton::widget()");
    } // GtkWidget* XGtkButton::widget()

  /*****************************************************************************
   *
   * GtkWidget* XGtkButton::button()
   *
   * Parameters:	-
   *
   * Result:	the button
   *
   * Version:	0.4.3
   *
   * Description:	Result
   *
   ****************************************************************************/
  GtkWidget*
    XGtkButton::button()
    {
      DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_VALUE,
		    "XGtkButton::button()");

      DEBUG_ASSERTION((this->button_p != NULL),
		      "XGtkButton::button()\n"
		      "  `button_p` == NULL");

      DEBUG_RETURNING(this->button_p,
		      INFO_GTK_WIDGET && INFO_GTK_VALUE,
		      "XGtkButton::button()");
    } // GtkWidget* XGtkButton::button()

  /*****************************************************************************
   *
   * GtkWidget* XGtkButton::label()
   *
   * Parameters:	-
   *
   * Result:	the label of the button
   *
   * Version:	0.4.3
   *
   * Description:	Result
   *
   ****************************************************************************/
  GtkWidget*
    XGtkButton::label()
    {
      DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_VALUE,
		    "XGtkButton::label()");

      DEBUG_RETURNING(GTK_BIN(this->button())->child,
		      INFO_GTK_WIDGET && INFO_GTK_VALUE,
		      "XGtkButton::label()");
    } // GtkWidget* XGtkButton::label()

  /*****************************************************************************
   *
   * void XGtkButton::language_update()
   *
   * Parameters:	-
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	updates the language
   *
   ****************************************************************************/
  void
    XGtkButton::language_update()
    {
      DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_UPDATE,
		    "XGtkButton::language_update()");

      // update the text of the button
      gtk_label_set_text(GTK_LABEL(this->label()),
			 ::language(*((string*)gtk_object_get_data(GTK_OBJECT(this->button()),
								   "text"))
				   ).c_str());

      DEBUG_RETURNING(VOID,
		      INFO_GTK_WIDGET && INFO_GTK_UPDATE,
		      "XGtkButton::language_update()");
    } // void XGtkButton::language_update()

}
#endif
