Click here to Skip to main content
15,895,799 members
Articles / Programming Languages / C#

The Application Automation Layer - Using XML to generate Menus

Rate me:
Please Sign up or sign in to vote.
4.81/5 (56 votes)
5 May 200313 min read 238.8K   2.6K   194  
Exploring the issues of menu management as specified externally via an XML file, in the context of status bars, toolbars, and events.
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace AAL
{
	public abstract class AALForm
	{
		protected FormMgr formMgr;
		protected FormInfo formInfo;
		protected Hashtable ctrlList;
		protected ArrayList containerControls;

		public string DataDomain
		{
			get
			{
				if (formInfo.dataDomain != "")
				{
					return formInfo.dataDomain+".";
				}
				else
				{
					return "";
				}
			}
		}

		public FormInfo FormInfo
		{
			get
			{
				return formInfo;
			}
		}

		public AALControl this[string name]
		{
			get
			{
				AALControl ctrl=ctrlList[name] as AALControl;
				Dbg.Assert(ctrl != null, new DbgKey("UnkCtrl"), name);
				return ctrl;
			}
		}

		public StatusBarPanel MenuHelpPanel
		{
			set
			{
				formMgr.MenuHelpForm=this;
				IForm.MenuHelpPanel=value;
			}
		}

		public AALForm(FormInfo fi, FormMgr mgr)
		{
			formInfo=fi;
			formMgr=mgr;
			ctrlList=new Hashtable();
			containerControls=new ArrayList();
			formMgr.IDH.CreateWorkflowDomain(fi.dataDomain);
		}

		public void PreCreateEvent()
		{
			EventData ev=EventData.Marshal(new MED[] {new MED("Function", formInfo.preCreateEvent)});
			formMgr.ICM.Invoke(formInfo.preCreateEvent, null);
		}

		public void PostCreateEvent()
		{
			EventData ev=EventData.Marshal(new MED[] {new MED("Function", formInfo.postCreateEvent)});
			formMgr.ICM.Invoke(formInfo.preCreateEvent, null);
		}

		public virtual void Show()
		{
		}

		public virtual void Remove()
		{
			formMgr.IDH.CreateWorkflowDomain(formInfo.dataDomain);
		}

		public abstract IForm IForm {get;}

		public void AssignMenu(MainMenu menu)
		{
			IForm.AssignMenu(menu);
		}

		public void AddControl(string name, AALControl ctrl)
		{
			ctrlList[name]=ctrl;
		}

		public void AddContainerControl(AALControl ctrl)
		{
			containerControls.Add(ctrl);
		}

		public AALControl FindContainingControl(AALControl ctrl)
		{
			for (int i=0; i<containerControls.Count; i++)
			{
				Control c=((AALControl)containerControls[i]).sysctrl;
				if ( (c.Location.X <= ctrl.sysctrl.Location.X) &&
					(c.Location.Y <= ctrl.sysctrl.Location.Y) &&
					(c.Location.X+c.Size.Width >= ctrl.sysctrl.Location.X) &&
					(c.Location.Y+c.Size.Height >= ctrl.sysctrl.Location.Y) )
				{
					return (AALControl)containerControls[i];
				}
			}
			return null;
		}

		public void SetMenuHelpText(string text)
		{
			IForm.SetMenuHelpText(text);
		}

		public void CreateContainerControls()
		{
			for (int i=0; i<containerControls.Count; i++)
			{
				AALControl ctrl=(AALControl)containerControls[i];
				ctrl.Create();
				IForm.AddControl(ctrl);
				ctrl.PostCreate();
				ControlInfo ci=ctrl.ctrlInfo;
				ci.SetupFont(ctrl.sysctrl);
				ci.SetupAnchor(ctrl.sysctrl);
				//				ctrl.sysctrl.Parent=IForm.Form;
//				IForm.AddContainerControl(ctrl);
			}
		}

		public void CreateControls()
		{
			IEnumerator iter=ctrlList.Values.GetEnumerator();
			while (iter.MoveNext())
			{
				AALControl ctrl=iter.Current as AALControl;
				if (ctrl.IsSimpleContainer)
				{
					// skip container control creation, as this is already done
					continue;
				}

				// ********************
				ctrl.Create();
				IForm.AddControl(ctrl);
				ctrl.PostCreate();
				// ********************

				ControlInfo ci=ctrl.ctrlInfo;
				ci.SetupFont(ctrl.sysctrl);
				ci.SetupAnchor(ctrl.sysctrl);

				if (ci.tooltipText != "")
				{
					ToolTip tp=new ToolTip();
					tp.SetToolTip(ctrl.sysctrl, ci.tooltipText);
				}
			}
		}

		public void UpdateStorage()
		{
			IEnumerator iter=ctrlList.Values.GetEnumerator();
			while (iter.MoveNext())
			{
				AALControl ctrl=iter.Current as AALControl;
				ctrl.UpdateStorage();
			}
		}

		public void UpdateStorage(string ctrlName)
		{
			Dbg.Assert(ctrlList.Contains(ctrlName), new DbgKey("UnkCtrl"), ctrlName);
			((AALControl)ctrlList[ctrlName]).UpdateStorage();
		}

		public void UpdateControl(string ctrlName)
		{
			Dbg.Assert(ctrlList.Contains(ctrlName), new DbgKey("UnkCtrl"), ctrlName);
			((AALControl)ctrlList[ctrlName]).UpdateControl();
		}

		public void UpdateControlList(string ctrlName)
		{
			Dbg.Assert(ctrlList.Contains(ctrlName), new DbgKey("UnkCtrl"), ctrlName);
			((AALControl)ctrlList[ctrlName]).UpdateControlList();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Interacx
United States United States
Blog: https://marcclifton.wordpress.com/
Home Page: http://www.marcclifton.com
Research: http://www.higherorderprogramming.com/
GitHub: https://github.com/cliftonm

All my life I have been passionate about architecture / software design, as this is the cornerstone to a maintainable and extensible application. As such, I have enjoyed exploring some crazy ideas and discovering that they are not so crazy after all. I also love writing about my ideas and seeing the community response. As a consultant, I've enjoyed working in a wide range of industries such as aerospace, boatyard management, remote sensing, emergency services / data management, and casino operations. I've done a variety of pro-bono work non-profit organizations related to nature conservancy, drug recovery and women's health.

Comments and Discussions