/*   EXTRAITS DE LA LICENCE
	Copyright CEA, contributeurs : Luc BILLARD et Damien
	CALISTE, laboratoire L_Sim, (2001-2006)
  
	Adresse mèl :
	BILLARD, non joignable par mèl ;
	CALISTE, damien P caliste AT cea P fr.

	Ce logiciel est un programme informatique servant à visualiser des
	structures atomiques dans un rendu pseudo-3D. 

	Ce logiciel est régi par la licence CeCILL soumise au droit français et
	respectant les principes de diffusion des logiciels libres. Vous pouvez
	utiliser, modifier et/ou redistribuer ce programme sous les conditions
	de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 
	sur le site "http://www.cecill.info".

	Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
	pris connaissance de la licence CeCILL, et que vous en avez accepté les
	termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
*/

/*   LICENCE SUM UP
	Copyright CEA, contributors : Luc BILLARD et Damien
	CALISTE, laboratoire L_Sim, (2001-2006)

	E-mail address:
	BILLARD, not reachable any more ;
	CALISTE, damien P caliste AT cea P fr.

	This software is a computer program whose purpose is to visualize atomic
	configurations in 3D.

	This software is governed by the CeCILL  license under French law and
	abiding by the rules of distribution of free software.  You can  use, 
	modify and/ or redistribute the software under the terms of the CeCILL
	license as circulated by CEA, CNRS and INRIA at the following URL
	"http://www.cecill.info". 

	The fact that you are presently reading this means that you have had
	knowledge of the CeCILL license and that you accept its terms. You can
	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
*/
#ifndef VISU_PUBLIC_H
#define VISU_PUBLIC_H

#include <gtk/gtk.h>

#include "visu_tools.h"
#include "visu_dump.h"
#include "visu_rendering.h"

/**********************/
/* Sub panel controls */
/**********************/

/* structure to allocate by every module
   that want to create a subpanel. */
typedef gboolean (*onChangePanelFunc)(gpointer data);
struct subpanel_data
{
  /* Value that is shown in the combo box */
  char *comboLabel;

  /* Value that appears in te tab of the
     GtkNoteBook */
  char *tabLabel;
  /* Name of a file used as an icon in the tab */
/*   char *iconPathName; */

  /* GtkWidgets used */
  GtkWidget *icon;
  GtkWidget *child;

  /* Functions that is called every time the panel
     is entered or left. */
  onChangePanelFunc onEnter;
  onChangePanelFunc onLeave;
};
typedef struct subpanel_data subPanel;


/* Accessible variables of visu interface */
/* Pointer to the current rendered subpanel. */
subPanel* currentSubPanel;
enum
  {
    /*     GTKMAIN_COLUMN_ICON, */ /* A pixmap to represent the subpanel */
    GTKMAIN_COLUMN_NAME,  /* The label shown */
    GTKMAIN_COLUMN_POINTER_TO_DATA,  /* Pointer to the subpanel. */
    GTKMAIN_N_COLUMNS
  };


/* Prototype of the functions used to initialise a new rendering method. */
typedef subPanel* (*subPanelInitFunc) ();

subPanel* createSubPanel(char* name, char *tabName, GtkWidget *child,
			 onChangePanelFunc enter, onChangePanelFunc leave);
subPanel* createSubPanelWithIconFromPath(char* name, char *tabName,
					 char* iconPath, GtkWidget *child,
					 onChangePanelFunc enter, onChangePanelFunc leave);
subPanel* createSubPanelWithIconFromStock(char* name, char *tabName,
					  gchar *id, GtkWidget *child,
					  onChangePanelFunc enter, onChangePanelFunc leave);

/* This method must be called when a new subpanel
   has to be added to visu. All the values of the
   subpanel structure must have been initialised. */
void addSubPanel(subPanel *sp);

/* The main gtk window and other depending windows. */
GtkWidget *mainWindow;
GtkWidget *saveDialog;
GtkWidget *currentRenderingWindow;


/*****************/
/* Miscellaneous */
/*****************/

GObject *visuGtkObject;

char* getLastOpenDirectory();
void setLastOpenDirectory(char* directory);

/**
 * gtkMainCreate_fileChooserFilter:
 * @list: a GList of #FileFormat ;
 * @filterDefault: a pointer to store the default filter.
 *
 * Create a list of GtkFileFilter created from the given list of file formats.
 *
 * Returns: a list of filters. This list should be freed after use.
 */
GList* gtkMainCreate_fileChooserFilter(GList *list, GtkFileFilter **filterDefault);
/**
 * gtkMainCreate_defaultFileChooser:
 * @data: an allocated #VisuData to store the file names ;
 * @fileChooser: a pointer to store the created GtkFileChooser ;
 * @fileWidget: a pointer to store the created ancapsulating widget.
 *
 * This method is a default method to launch a file chooser that select
 * a single file, with the filters of the current RenderingMethod. It creates a
 * modal dialog (@fileWidget), and wait for its reponse. If OK is clicked, the selected
 * filename is stored. If Cancel is clicked, nothing is done. In all cases
 * the dialog is not destroyed and it can be retrieve via the @fileWidget argument.
 *
 * Returns: 0 if no file has been set, 1 if the calling method should
 *          call loadAndRenderFileWithGtk() with a g_idle_add method.
 */
int gtkMainCreate_defaultFileChooser(VisuData *data, GtkFileChooser **fileChooser,
				     GtkWidget **fileWidget);


/* Open a directory selector. The callback function of ok button is given
   as the user_data. */
gchar* getSelectedDirectory();

/* This method loads the general function to load data from file
   and deals with errors with gtkDialogs. */
gboolean loadAndRenderFileWithGtk(gpointer data);

/* Draw the alert window with the specified message. */
void raiseAlertDialog(char *message);
/* Draw the alert window with the specified message. */
void raiseAlertDialogWithScrollView(char *message);





/* This method hides the specified window and save its coordinates if
   it is specified by a parameter. */
void visuHideWindow(GtkWindow *win);
/* This method shows the specified window and try to put it at its
   former position if the good parameter is used. */
void visuShowWindow(GtkWindow *win);

void setRememberPosition(int val);
int getRememberPosition();





/**
 * createGtkWidgetFunc:
 *
 * This prototype is used whenever a method is required to create a GtkWidget.
 *
 * Returns: a newly created GtkWidget.
 */
typedef GtkWidget* (*createGtkWidgetFunc)(void);

/**
 * createGtkLoadWidgetFunc:
 * @data: a #VisuData to store the informations ;
 * @fileChooser: a pointer to store the created GtkFileChooser ;
 * @fileWidget: a pointer to store the created ancapsulating widget.
 * 
 * Methods that conform to this prototype is used to set filename(s)
 * to be loaded when the 'load' button is pushed. It must creates a
 * GtkWidget that will be destroy after use and it must also use a GtkFileChooser.
 *
 * Returns: 0 if no filename as been set, 1 if the calling method should
 *          call loadAndRenderFileWithGtk() with a g_idle_add method.
 */
typedef int (*createGtkLoadWidgetFunc) (VisuData *data, GtkFileChooser **fileChooser,
					GtkWidget **fileWidget);

/**
 * gtkMainSet_renderingSpecificMethods:
 * @method: a #RenderingMethod object;
 * @methodLoad: a #createGtkLoadWidgetFunc method (can be NULL).
 * @createLoadWidget: a #createGtkWidgetFunc method (can be NULL).
 *
 * This function is used by a client to add gtk methods to a rendering method.
 * The @methodLoad argument is called to when the 'load' button is pushed.
 */
void gtkMainSet_renderingSpecificMethods(RenderingMethod *method,
					 createGtkWidgetFunc createLoadWidget,
					 createGtkLoadWidgetFunc methodLoad);
/**
 * gtkMainGet_renderingSpecificOpen:
 * @method: a #RenderingMethod object.
 *
 * This method is used to retrieve the #createGtkLoadWidgetFunc associate with
 * the specified @method.
 *
 * Returns: a load method if one has been specified for @method
 *          or gtkMainCreate_defaultFileChooser().
 */
createGtkLoadWidgetFunc gtkMainGet_renderingSpecificOpen(RenderingMethod *method);

/* developpment methods, should be removed. */
subPanel* createEmptySubPanel(char* label);

#endif
