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

#ifdef USE_UI_GTK
#ifndef GTK_HELP_HEADER
#define GTK_HELP_HEADER

#include "constants.h"

namespace GTK_DOKO {
#include <gtk/gtkwidget.h>

  class GTK_GUI;

  // a help window

  // in the directory of the constructor should exist:
  // * index.html
  // * toc.html
  // * toc.short.html
  // * credits.html
  class Help {
    public:
      // constructor
      Help(GTK_GUI* gui_p);
      // destructor
      ~Help();

      // initialize the window
      void init();
      // initialize the toc
      void toc_init();
      // initialize the toc
      void bookmarks_init();
      // initialize the searching
      void search_init();
      // initialize gecko
      void gecko_init();


      // the variables
      class GTK_GUI& gui(); // the gui


      // set the location directory
      string const& location_dir_set(string const& location_dir);

      // the current location
      string location() const;
      // the current title
      string title() const;

      // the location of the index
      string location_index() const;
      // the location of the toc
      string location_toc() const;
      // the location of the credits
      string location_credits() const;
      // the location of the toc of the sidebar
      string location_toc_short() const;

      // show the window
      void show();
      // hide the window
      void hide();

      // load the url
      void load(string const& location);

      // redraw all
      void redraw();

      // update the icons
      void icons_update();
      // loads the icons from the directory
      bool icons_load(string const& directory);
      // update the language
      void language_update();

      // events

      // key event
      static gboolean key_event(GtkWidget*, GdkEventKey* key,
				gpointer help);
      // hide the window
      static void show_event(GtkWidget*, gpointer help);
      // show the window
      static void hide_event(GtkWidget*, gpointer help);
      // delete the window
      static gboolean delete_event(GtkWidget*, GdkEvent*, gpointer help);

      // buttons

      // previous page
      static void previous_page_event(GtkWidget*, gpointer help);
      // next page
      static void next_page_event(GtkWidget*, gpointer help);
      // load the index page
      static void index_load_event(GtkWidget*, gpointer help);
      // load the toc page
      static void toc_load_event(GtkWidget*, gpointer help);
      // load the credits page
      static void credits_load_event(GtkWidget*, gpointer help);
      // open the page in a browser
      static void open_in_browser_event(GtkWidget*, gpointer help);
      // the toc in the sidebar request to open a page - pass it to 'gecko'
      static gint toc_open_uri_event(GtkWidget* toc,
				     char const* uri, gpointer help);

      // key event of the entry
      static gboolean location_entry_key_event(GtkWidget*, GdkEventKey* key,
					       gpointer help);

    private:
      // events

      // key event of the entry - load the page
      bool key(GdkEventKey* key);

      // previous page
      void previous_page();
      // next page
      void next_page();
      // load the index page
      void index_load();
      // load the toc page
      void toc_load();
      // load the credits page
      void credits_load();
      // open the page in a browser
      void open_in_browser();
      // load the toc of the sidebar
      void toc_short_load();
      // key event of the entry - load the page
      bool location_entry_key(GdkEventKey* key);

      // an url shall be opened by the toc
      bool toc_open_uri(char const* uri);

    public:
      //
      // bookmarks
      //

      // adds the location to the bookmarks
      void bookmark_add(string const& location, string const& title);

    protected:
      // load the location of the bookmark
      static void bookmark_load_event(GtkWidget* bookmark, gpointer help);
      // adds the location of the current page to the bookmarks
      static void bookmark_add_event(GtkWidget*, gpointer help);

    public:
      //
      // gecko
      //

    protected:
      // events from gecko

      // an url shall be opened
      static gint gecko_open_uri_event(GtkWidget*, char const* uri, gpointer help);
      // the location has changed
      static void gecko_location_change_event(GtkWidget*, gpointer help);
      // the title has changed
      static void gecko_title_change_event(GtkWidget*, gpointer help);

    private:
      // events from gecko

      // an url shall be opened
      bool gecko_open_uri(char const* uri);
      // the location has changed
      void gecko_location_change();
      // the title has changed
      void gecko_title_change();


    protected:
      // the gui
      class GTK_GUI* const gui_p;

      // the location of the directory
      string location_dir;

      // the widgets

      // the window
      GtkWidget* window;

      // some buttons

      // previous page
      GtkWidget* previous_page_button;
      // next page
      GtkWidget* next_page_button;
      // go to the index page
      GtkWidget* index_load_button;
      // go to the toc page
      GtkWidget* toc_load_button;
      // go to the credits page
      GtkWidget* credits_load_button;
      // open the page in a browser
      GtkWidget* open_in_browser_button;
      // hide the window
      GtkWidget* hide_button;

      // the title
      GtkWidget* title_label;
      // input of the location
      GtkWidget* location_entry;

      // the toc in a separate widget (tree/ctree)
      GtkWidget* toc;
      GtkWidget* toc_label;
      bool toc_loaded;
      // search
      GtkWidget* search_widget;
      GtkWidget* search_widget_label;
      // bookmarks
      GtkWidget* bookmarks_container;
      GtkWidget* bookmarks_label;
      GtkWidget* bookmarks_list;
      GtkWidget* bookmark_add_button;

      // the rendering engine (use gecko)
      GtkWidget* gecko;

      // todo:
      // * bookmarks
      // * searching a word

    private:
      Help();
      Help(Help const&);
      Help& operator=(Help const&);
  }; // class Help

} // namespace GTK_DOKO

#endif // #ifndef GTK_HELP_HEADER
#endif // #ifdef USE_UI_GTK
