#include <gtk/gtk.h>
#include <glib/gi18n.h>


enum {
	ATTRS_COLUMN_IS_TITLE,
	ATTRS_COLUMN_IS_ATTR,
	ATTRS_COLUMN_IS_SLOT,
	ATTRS_COLUMN_ATTR_NAME,
	ATTRS_COLUMN_ATTR_VALUE,
	ATTRS_COLUMN_ATTR_START,
	ATTRS_COLUMN_ATTR_END,
	ATTRS_NUM_COLUMNS
};

#define GLADE_RESPONSE_CLEAR 42

static GtkWidget *
glade_eprop_attrs_view (void)
{
	GtkWidget         *view_widget;
 	GtkCellRenderer   *renderer;
	GtkTreeViewColumn *column;
	GtkTreeModel      *model;

	model = (GtkTreeModel *)gtk_tree_store_new
	  (ATTRS_NUM_COLUMNS,
	   G_TYPE_BOOLEAN,    /* Whether this is the title */
		 G_TYPE_BOOLEAN,    /* Oposite of above */
		 G_TYPE_BOOLEAN,    /* Whether this is an empty slot to edit */
		 G_TYPE_STRING,     /* Attribute name */
		 G_TYPE_STRING,     /* Attribute value */	
		 G_TYPE_UINT,       /* Attribute start value */
		 G_TYPE_UINT);      /* Attribute end value */

	view_widget = gtk_tree_view_new_with_model (model);
	gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (view_widget), FALSE);
	gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view_widget), FALSE);

	/********************* attribute name column *********************/
 	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), 
		      "editable", FALSE, 
		      "weight", PANGO_WEIGHT_BOLD,
		      NULL);

	column = gtk_tree_view_column_new_with_attributes
		(_("Attribute"),  renderer, 
		 "text",       ATTRS_COLUMN_ATTR_NAME, 
		 "weight-set", ATTRS_COLUMN_IS_TITLE,
		 NULL);

	gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);


	/********************* attribute value column *********************/
 	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer), 
		      "editable", FALSE, 
		      "style",       PANGO_STYLE_ITALIC,
		      "foreground",  "Gray", 
		      NULL);

	column = gtk_tree_view_column_new_with_attributes
		(_("Attribute"),  renderer, 
		 "text",           ATTRS_COLUMN_ATTR_VALUE, 
		 "style-set",      ATTRS_COLUMN_IS_SLOT,
		 "foreground-set", ATTRS_COLUMN_IS_SLOT,
		 "visible",        ATTRS_COLUMN_IS_ATTR,
		 NULL);

	gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (view_widget), column);

	return view_widget;
}

static void
glade_eprop_attrs_populate_view (GtkTreeView         *view)
{
	GtkTreeStore       *model = (GtkTreeStore *)gtk_tree_view_get_model (view);
	GtkTreeIter         iter, *parent_iter;


	/* First make parent iters...
	 */
	gtk_tree_store_append (model, &iter, NULL);
	gtk_tree_store_set (model, &iter,
			    ATTRS_COLUMN_IS_TITLE, TRUE,
			    ATTRS_COLUMN_IS_ATTR, FALSE,
			    ATTRS_COLUMN_ATTR_NAME, _("Weight"),
			    -1);

	gtk_tree_store_append (model, &iter, NULL);
	gtk_tree_store_set (model, &iter,
			    ATTRS_COLUMN_IS_TITLE, TRUE,
			    ATTRS_COLUMN_IS_ATTR, FALSE,
			    ATTRS_COLUMN_ATTR_NAME, _("Style"),
			    -1);

#ifdef TREEVIEW_WAS_WORKING
	parent_iter = gtk_tree_iter_copy (&iter);
	gtk_tree_store_append (model, &iter, parent_iter);
	gtk_tree_store_set (model, &iter,
			    ATTRS_COLUMN_IS_TITLE, FALSE,
			    ATTRS_COLUMN_IS_ATTR, TRUE,
			    ATTRS_COLUMN_ATTR_NAME, _("Style"),
			    ATTRS_COLUMN_ATTR_VALUE, "Dummy Value",
			    -1);

	gtk_tree_iter_free (parent_iter);
#endif

	/* Populate here ...
	 */
/* 	for (list = attributes; list; list = list->next) */
/* 	{ */
/* 	} */


}



static void
glade_eprop_attrs_show_dialog (void)
{
	GtkWidget        *dialog, *parent, *vbox, *sw, *tree_view;
	gint              res;

	dialog = gtk_dialog_new_with_buttons (_("Setup Text Attributes"),
					      NULL,
					      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
					      GTK_STOCK_CLEAR, GLADE_RESPONSE_CLEAR,
					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					      GTK_STOCK_OK, GTK_RESPONSE_OK,
					      NULL);

	gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);

	vbox = gtk_vbox_new (FALSE, 6);
	gtk_widget_show (vbox);

	gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);

	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0);

	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_widget_show (sw);
	gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
	gtk_widget_set_size_request (sw, 400, 200);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);

	tree_view = glade_eprop_attrs_view ();
	glade_eprop_attrs_populate_view (GTK_TREE_VIEW (tree_view));

	gtk_tree_view_expand_all (GTK_TREE_VIEW (tree_view));

	gtk_widget_show (tree_view);
	gtk_container_add (GTK_CONTAINER (sw), tree_view);

	/* Run the dialog */
	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res == GTK_RESPONSE_OK) 
	{
/* 		gtk_tree_model_foreach */
/* 			(gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)), */
/* 			 (GtkTreeModelForeachFunc) */
/* 			 glade_eprop_accel_accum_accelerators, &accelerators); */
		
/* 		value = g_new0 (GValue, 1); */
/* 		g_value_init (value, GLADE_TYPE_ACCEL_GLIST); */
/* 		g_value_take_boxed (value, accelerators); */

/* 		glade_editor_property_commit (eprop, value); */

/* 		g_value_unset (value); */
/* 		g_free (value); */
	} 
	else if (res == GLADE_RESPONSE_CLEAR)
	{
/* 		value = g_new0 (GValue, 1); */
/* 		g_value_init (value, GLADE_TYPE_ACCEL_GLIST); */
/* 		g_value_set_boxed (value, NULL); */

/* 		glade_editor_property_commit (eprop, value); */

/* 		g_value_unset (value); */
/* 		g_free (value); */
	}

	/* Clean up ...
	 */
	gtk_widget_destroy (dialog);


}

gint
main (gint argc, gchar *argv[])
{


  gtk_init (&argc, &argv);


  glade_eprop_attrs_show_dialog ();


  return 0;
}
