using System;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Diagnostics;
using System.Globalization;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading;

using System.Printing;

using miew.String;
using agree;

using ActiproSoftware.Windows.Controls.Docking;
using ActiproSoftware.Windows.Controls.Ribbon;
using ActiproSoftware.Windows.Controls.Ribbon.Controls;


namespace agree.Wpf
{
	class MyDockPanel : DockPanel
	{
		StatusBar statusbar;
		MainWindow w;

		public MyDockPanel(MainWindow w)
		{
			this.w = w;
			MyRibbon rbn = new MyRibbon();

			MyDockSite mds = new MyDockSite(w);

			this.Children.Add(rbn);
			this.Children.Add(mds);

			statusbar = new StatusBar();
			statusbar.Items.Add("Ready");
			w.StatusBar = statusbar;
		}
	};

	class MyWorkspace : Workspace
	{
		public TabbedMdiContainer tmc;
		public TabbedMdiHost tmh;

		public MyWorkspace()
		{
			tmc = new TabbedMdiContainer();

			SplitContainer sc_doc = new SplitContainer();
			sc_doc.Children.Add(tmc);

			tmh = new TabbedMdiHost();
			tmh.Content = sc_doc;

			this.Content = tmh;
		}
	};


	class MyDockSite : DockSite
	{
		MainWindow w;
		public MyWorkspace wksp;
		ToolWindowContainer twc;
		SplitContainer sc_outer;

		static public MyDockSite g_docksite;

		public MyDockSite(MainWindow w)
		{
			this.w = w;
			g_docksite = this;
			wksp = new MyWorkspace();

			w.object_browser = new ObjectBrowserToolWindow(this);
			twc = new ToolWindowContainer();
			twc.Items.Add(w.object_browser);
			twc.SetValue(DockSite.ControlSizeProperty, new Size(47, 40));

			sc_outer = new SplitContainer();
			sc_outer.Children.Add(twc);
			sc_outer.Children.Add(wksp);

			this.Content = sc_outer;

			this.CommandBindings.Add(new ShowItemCommand(w).CommandBinding);
			//this.CommandBindings.Add(new ShowHighlightedItemCommand(w).CommandBinding);
			this.CommandBindings.Add(new Open3dWindow(w).CommandBinding);
//			this.CommandBindings.Add(new OpenEdgeWindow(w).CommandBinding);

#if false
			// seems like doing it this way, the bindings are not yet available?
			//var q = this.CommandBindings.OfType<CommandBinding>();
			//var r = q.First(cb => cb.Command is ShowExpandedType);
			//r.Command.Execute(g.tm.type_dict["head-adj-scop"]);


			set.Execute(g.tm.type_dict["head-adj-scop"], this);

			set2.Execute(g.tm.type_dict["head-adj-scop"], this);

			Edge e1 = g.tm.type_dict["drop-obj"].Expanded;
			Edge e1_args;
			if (!g.tm.tray.GetEdgeAtPath(e1, "args", out e1_args))
				throw new Exception();
			Edge e1_part = g.tm.tray.GetListEdges(e1_args).First();

			Edge e2 = g.tm.type_dict["กิน_6578"].Expanded;
			Edge result = default(Edge);// new UnifyHelper(g.tm).UnifyRulePart(e1, e1_part, e2);

			set3.Execute(new EdgeWindow.CommandArgs
			{
				e = result,
				title = String.Format("{0} ARGS.FIRST ⊓ {1}", e1.Type.Name, e2.Type.Name)
			}, this);
#endif
			//this.CommandBindings.OfType<CommandBinding>().First(cb => cb.Command is ShowExpandedType).Command.Execute(g.tm.type_dict["head-adj-scop"]);
		}

	};
}