/**********************************************************************
 *
 *   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 "license.h"
#include "gtk_gui.h"
#include "../../misc/setting.h"

namespace GTK_DOKO {
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtktext.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtkvscrollbar.h>
#ifdef GTK_2_0
#include <gtk/gtktextview.h>
#endif

  /**
   **
   ** constructor
   **
   ** @param	help_a - pointer to the help system
   **
   ** @return	-
   ** 
   ** @version	0.4.4
   **
   ** @author	Diether Knof
   **
   **/
  License::License(GTK_GUI* gui_p) :
    Dialog(gui_p, "License"), // the base class
  logo(gui_p->logo().widget()), // the logo
  text_box(gtk_hbox_new(0, 0)), // the text
#ifdef GTK_2_0
  text(gtk_text_view_new()), // the text
  text_scrollbar(gtk_vscrollbar_new(NULL)) // the scrollbar
#else
    text(gtk_text_new(NULL, NULL)), // the text
  text_scrollbar(gtk_vscrollbar_new(GTK_TEXT(text)->vadj)) // the scrollbar
#endif
  {
    DEBUG_CALLING(INFO_GTK_LICENSE && INFO_GTK_INIT,
		  "License::License(gui_p)");


    // the logo
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window())->vbox),
		       this->logo,
		       FALSE, TRUE, 10);

    // the text box with the text and the scrollbar
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window())->vbox),
		       this->text_box,
		       TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(text_box),
		       this->text,
		       TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(text_box),
		       this->text_scrollbar,
		       FALSE, FALSE, 0);

    // the 'close' button
    gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window())->action_area),
		     this->button_close,
		     FALSE, TRUE, 0);

    DEBUG_RETURNING(VOID,
		    INFO_GTK_LICENSE && INFO_GTK_INIT,
		    "License::License(gui_p)");
  } // License::License(GTK_GUI* gui_p)

  /**
   **
   ** inits the 'license' window
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.4.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    License::init()
    {
      DEBUG_CALLING(INFO_GTK_LICENSE && INFO_GTK_INIT,
		    "License::init()");

      this->Dialog::init();

      // the text field
#ifdef GTK_2_0
      gtk_text_view_set_editable(GTK_TEXT_VIEW(this->text), FALSE);
      gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(this->text), GTK_WRAP_WORD);
#else
      gtk_text_set_editable(GTK_TEXT(this->text), FALSE);
      gtk_text_set_word_wrap(GTK_TEXT(this->text), TRUE);
#endif

      DEBUG_RETURNING(VOID,
		      INFO_GTK_LICENSE && INFO_GTK_INIT,
		      "License::init()");
    } // void License::init()

  /**
   **
   ** updates the language in the gpl window
   **
   ** @param	-
   **
   ** @return	-
   ** 
   ** @version	0.4.4
   **
   ** @author	Diether Knof
   **
   **/
  void
    License::language_update()
    {
      DEBUG_CALLING(INFO_GTK_LICENSE && INFO_GTK_UPDATE,
		    "License::language_update()");

      this->Dialog::language_update();

#ifdef GTK_2_0
      gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(this->text)),
			       GPL.c_str(),
			       -1); // length
#else
      { // the text in the text field
	gtk_text_freeze(GTK_TEXT(this->text));
	// delete the old text
	gtk_text_set_point(GTK_TEXT(this->text), 0);
	gtk_text_forward_delete(GTK_TEXT(this->text),
				gtk_text_get_length(GTK_TEXT(this->text)));
	// insert the new text
	gtk_text_insert(GTK_TEXT(this->text),
			NULL, // font
			NULL, // foreground
			NULL, // background
			GPL.c_str(), // text
			-1); // length

	gtk_text_thaw(GTK_TEXT(this->text));
      } // the text in the text field
#endif

      DEBUG_RETURNING(VOID,
		      INFO_GTK_LICENSE && INFO_GTK_UPDATE,
		      "License::language_update()");
    } // void License::language_update()

} // namespace GTK_DOKO

#endif // #ifdef USE_UI_GTK
