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

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

namespace GTK_DOKO
{

  /*****************************************************************************
   *
   * XGtkLabelWidget::XGtkLabelWidget(string const& text)
   *
   * Parameters:	text - text for the label
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  XGtkLabelWidget::XGtkLabelWidget(string const& text) :
    XGtkWidget(), // the widget
  container_p(gtk_hbox_new(FALSE, 10)), // the container
  label_p(gtk_label_new(""))
  {
    DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_INIT,
		  "XGtkLabelWidget::XGtkLabelWidget()");

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

    // pack the widgets in the container
    gtk_box_pack_start(GTK_BOX(this->container()),
		       this->label(),
		       FALSE, FALSE, 0);

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

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

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

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

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

    gtk_widget_destroy(this->label());
    gtk_widget_destroy(this->container());

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

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

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

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

      DEBUG_ASSERTION((this->container_p != NULL),
		      "XGtkLabelWidget::container()\n"
		      "  `container_p` == NULL");

      DEBUG_RETURNING(this->container_p,
		      INFO_GTK_WIDGET && INFO_GTK_VALUE,
		      "XGtkLabelWidget::container()");
    } // GtkWidget* XGtkLabelWidget::container()

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

      DEBUG_ASSERTION((this->label_p != NULL),
		      "XGtkLabelWidget::label()\n"
		      "  `label_p` == NULL");

      DEBUG_RETURNING(this->label_p,
		      INFO_GTK_WIDGET && INFO_GTK_VALUE,
		      "XGtkLabelWidget::label()");
    } // GtkWidget* XGtkLabelWidget::label()

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

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

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

}
#endif
