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

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

namespace GTK_DOKO
{

  /*****************************************************************************
   *
   * XGtkLabel::XGtkLabel(string const& text)
   *
   * Parameters:	text - text for the label
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	Constructor
   *
   ****************************************************************************/
  XGtkLabel::XGtkLabel(string const& text) :
    XGtkWidget(),
  label_p(gtk_label_new("")) // the label
  {
    DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_INIT,
		  "XGtkLabel::XGtkLabel()");

    gtk_object_set_data(GTK_OBJECT(this->label()),
			"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,
		    "XGtkLabel::XGtkLabel()");
  } // XGtkLabel::XGtkLabel()

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

    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,
		    "XGtkLabel::~XGtkLabel()");
  } // XGtkLabel::XGtkLabel()

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

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

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

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

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

  /*****************************************************************************
   *
   * void XGtkLabel::language_update()
   *
   * Parameters:	-
   *
   * Result:	-
   * 
   * Version:	0.4.3
   *
   * Description:	updates the language
   *
   ****************************************************************************/
  void
    XGtkLabel::language_update()
    {
      DEBUG_CALLING(INFO_GTK_WIDGET && INFO_GTK_UPDATE,
		    "XGtkLabel::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,
		      "XGtkLabel::language_update()");
    } // void XGtkLabel::language_update()

}
#endif
