//*****************************************************************************************
// Truevision - a 3d modeler for gnome and povray
//
// matlib.h
//
// Vincent LE PRINCE <vincentleprince@users.sourceforge.net>
// Copyright (C) 2000-2001 Vincent LE PRINCE
// This file is part of the TRUEVISION Package

//   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 should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
//*******************************************************************************************
#ifndef TV_MATLIB_H
#define TV_MATLIB_H
using namespace std;
#include <vector>
#include "main.h"
#include "tvwidgets.h"

//******************************************************
// Arbre
//******************************************************

// Feuille
class MatLibItem {
	#define SENDER ((MatLibItem*)data)
	friend void sign_matlib_item_clicked( GtkWidget *wid, gpointer data ) { SENDER->selected(); }
	friend bool compare_items( MatLibItem *item1, MatLibItem *item2 );
	#undef SENDER

		private:
			static app_objs *app_ref;
			static GtkStyle *old_style, *new_style;
			GtkWidget *widget, *label;
			char *name;
			char *path;
			char *real_name;
			char* author;
			char *comment;
			void load_unknown_icon( GtkWidget *preview );
			void selected();
			
		public:
			MatLibItem( char *path, char *name, app_objs *appref  );
			~MatLibItem();		
			
			void draw_thumb( GtkWidget *box );
			void unselect() { gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(label), FALSE ); }
			void show_info( TvWidget_entry *name_label, TvWidget_entry *author_label, TvWidget_text *description );
			void load();
};
			

// Node
class MatLibNode {
		friend bool compare_nodes( MatLibNode*node1, MatLibNode *node2 );

		private:
			static app_objs *app_ref;
			char *name;
			char *systempath;
			char *homepath;
			MatLibItem *selected;
			GtkCTreeNode *node;
			vector <MatLibNode*> SubNodes;
			vector <MatLibItem*> Children;
		
		public:
			MatLibNode( char *systempath, char *homepath, char *name, app_objs *appref  );
			~MatLibNode();
			
			void add_to_tree( GtkWidget *tree, GtkCTreeNode *parent );
			void select( GtkWidget *tree ) { gtk_ctree_select( GTK_CTREE(tree), node ); }
			void draw_thumbs( GtkWidget *box, GtkWidget *viewp, GtkWidget *appbar );
			void change_selection( MatLibItem * selection );
			void load_selected() { if ( selected != NULL ) selected->load(); }
};



//*******************************************************
// Librairie
//*******************************************************
#define MATLIB_DEF MatLib *matlib = (MatLib*)(app_ref->matlib);


class MatLib : public app_object {
	#define SENDER ((MatLib*)data)
	friend void sign_matlib_dlg_click( GtkDialog *wid, gint button, gpointer data ) { SENDER->clicked_dlg(button); }
	friend void sign_matlib_dlg_destroy( GtkWidget *wid, GdkEvent *ev, gpointer data ) { SENDER->clicked_dlg(-1); }			
	friend void sign_matlib_tree_select( GtkCTree *tree, GtkCTreeNode *node, gint col, gpointer data ) { SENDER->tree_select(tree, node, col); }		
	#undef SENDER


		private:
			app_objs *app_ref;
			char *systemlib;
			char *homelib;
			GtkWidget *dlg_tree;
			
			GtkWidget *dialog;
			GtkWidget *thumbs_viewp, *thumbs_table, *app_bar;
			TvWidget_entry *name_label, *author_label;
			TvWidget_text *description;
			MatLibNode *root, *selected_node;
			int selected_item;
		
		public:
			MatLib( app_objs *appref );
			~MatLib();
			
			void raise_dlg_box();
			void clicked_dlg( int button );
			void tree_select( GtkCTree *tree, GtkCTreeNode *node, int col );
			void sign_mat_selected( MatLibItem *selection );
};
#endif
