using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Windows.Forms; using System.CodeDom; using System.CodeDom.Compiler; using System.Runtime.CompilerServices; using System.Reflection; using System.Xml; using Microsoft.CSharp; namespace DarkWynter.Shell { /// /// Leaf ToolStripItems which contain UserControls. /// UserControl is persistant, and invoked by selecting the corresponding ToolStripItem. /// Loads the Tab property in UCAD xml. /// public class UCAD_Control : ToolStripMenuItem { // "Name of DLL where UserControls are found. (eg - "AccountingControls.dll")" string assemblyName = ""; Assembly assembly; private UserControl userControl; public string location = ""; /// /// Try/Catch through Tab nodes to build the UCAD MenuStrip. /// /// /// public UCAD_Control(XmlNode node) { // Special Event handler calls userControl this.Click += new System.EventHandler(UCAD.button_Click); // Get MenuItem label from xml this.Text = node.Attributes["text"].Value; // Stylize this.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.AutoSize = true; this.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ForeColor = UCAD_Settings.menuForeColor; this.BackColor = UCAD_Settings.menuBackColor; //this.TextDirection = ToolStripTextDirection.Vertical270; //this.Size = new System.Drawing.Size(35, 20); //this.Size = new System.Drawing.Size(143, 22); // =="Load the assembly (eg - "DWToolbox.dll")" try { assemblyName = node.Attributes["assemblyName"].Value; string path = GetSolutionDirectory() + assemblyName; assembly = Assembly.LoadFile(path); } catch (Exception e) { Console.WriteLine(e.Message); } try { // ==Create Object - UCAD-Xml property must be in "TopLevelNamespace.Namespace.Class" notation string objectName = node.Attributes["objectName"].Value; if (objectName != "") { // Get the User Control from the Assembly. // DEBUG: Type[] types = assembly.GetTypes(); userControl = (UserControl)assembly.CreateInstance(objectName); // Create a unique ToolStripName so we can access the Control later. this.Name = "button_" + objectName; } // Load UCAD Interface, which connects Toolbox to Shell if (userControl is DarkWynter.Engine.Utilities.IUCAD) { Load_UCADInterfaceControl(); } // Set width and height of UserControl try { userControl.Width = int.Parse(node.Attributes["width"].Value); userControl.Height = int.Parse(node.Attributes["height"].Value); userControl.Location = new Point(0, 0); } catch (Exception e) { Console.WriteLine(e.Message); } // Location, or panel-name where the UserControl is loaded. try { location = node.Attributes["location"].Value; } catch (Exception e) { Console.WriteLine(e.Message); } // Default-load controls into UCAD panels try { if (bool.Parse(node.Attributes["initLoad"].Value)) { Load_InitControlSet(); } } catch (Exception e) { Console.WriteLine(e.Message); } } catch (Exception e) { Console.WriteLine(e.Message); } //=== Recursively Add Subitems === foreach (XmlNode subNode in node.ChildNodes) { // Add subcatagory if (subNode.Name == "Tab") { this.DropDownItems.Add(new UCAD_Control(subNode)); } } } /// /// If UCAD-Xml property ' initLoad="true/false" ' specifies is true, the UserControl is loaded /// at execution time into the location enumerated by UCAD-Xml property ' location="Main/Side/Bottom" '. /// private void Load_InitControlSet() { if (location == "Main") { // Add the buttons UserControl to the main panel UCAD.UCAD_Main_Panel.Controls.Clear(); UCAD.UCAD_Main_Panel.Controls.Add(userControl); } if (location == "Side") { // Add the buttons UserControl to the main panel UCAD.UCAD_Left_Panel.Controls.Clear(); UCAD.UCAD_Left_Panel.Controls.Add(userControl); } if (location == "Bottom") { // Add the buttons UserControl to the main panel UCAD.UCAD_Bottom_Panel.Controls.Clear(); UCAD.UCAD_Bottom_Panel.Controls.Add(userControl); } } /// /// IUCAD interface associates each UCAD panel with panel pointers located in Toolbox-layer UserControls. /// Other UserControls in Toolbox can access the UCAD panels by accessing the interface subscribers panel-pointers. /// private void Load_UCADInterfaceControl() { DarkWynter.Engine.Utilities.IUCAD ucadControl = userControl as DarkWynter.Engine.Utilities.IUCAD; ucadControl.UCAD_FormName = UCAD.UCAD_FormName; ucadControl.UCAD_Main_Panel = UCAD.UCAD_Main_Panel; ucadControl.UCAD_Top_Panel = UCAD.UCAD_Top_Panel; ucadControl.UCAD_Bottom_Panel = UCAD.UCAD_Bottom_Panel; ucadControl.UCAD_Left_Panel = UCAD.UCAD_Left_Panel; } /// /// Gets the Solution directory containing UserControl Dlls. /// /// public static String GetSolutionDirectory() { //// Get Parent Directory string curDir = Directory.GetCurrentDirectory(); return curDir + "\\"; //String workDir = curDir.Substring(0, curDir.IndexOf("SmallBusinessEngine\\bin\\Debug")); //// Get Parent Directory //DirectoryInfo parentDir = Directory.GetParent(curDir); //return parentDir.FullName + "\\"; } /// /// Gets the associated persistant user-control. /// /// public UserControl GetUserControl() { return userControl; } public string GetControlLocation() { return location; } } }