using System;
using System.Collections.Generic;
using Gtk;
using System.IO;

namespace DMX2
{
	[System.ComponentModel.ToolboxItem(true)]
	public partial class DriverBoitierV1UI : Gtk.Bin
	{
		DriverBoitierV1 drv;
		public DriverBoitierV1UI (DriverBoitierV1 _drv)
		{
			drv = _drv;
			this.Build ();
			ConstruitCBUnivers();
		}

	ListStore lsCbUnivers = new ListStore(typeof(UniversDMX));		
	void ConstruitCBUnivers ()
		{
			cbUnivers.Model = lsCbUnivers;
			var cellCbUnivers = new CellRendererText();
			cbUnivers.PackStart(cellCbUnivers,false);
			cbUnivers.SetCellDataFunc(cellCbUnivers, new CellLayoutDataFunc(RenderUniversName));


			foreach(UniversDMX u in Conduite.Courante.Patches)
				lsCbUnivers.AppendValues(u);

			TreeIter iter;
			lsCbUnivers.GetIterFirst(out iter);
			cbUnivers.SetActiveIter(iter);

		}

		void RenderUniversName (CellLayout cell_layout, CellRenderer cell, TreeModel tree_model, TreeIter iter)
		{
			UniversDMX univers =  tree_model.GetValue (iter, 0) as UniversDMX;
			if(univers != null)
			(cell as Gtk.CellRendererText).Text = univers.Nom;
		}

		protected void OnCbUniversChanged (object sender, EventArgs e)
		{
			TreeIter iter;
			if(cbUnivers.GetActiveIter(out iter))
			{
				drv.patch = lsCbUnivers.GetValue(iter,0) as UniversDMX;

			}
		}

	}
}

