//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
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 static UCAD_Settings settings = new UCAD_Settings();
public string location = "";
///
/// Try/Catch through Tab nodes to build the UCAD MenuStrip.
///
///
public UCAD_Control(XmlNode node)
{
// This MenuItems's Event handler calls userControl
this.Click += new System.EventHandler(UCAD.Load_Control);
// 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_Control.settings.menuForeColor;
this.BackColor = UCAD_Control.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_Control)
{
UCAD.Load_ProxyControl(userControl as DarkWynter.Engine.Utilities.IUCAD_Control);
}
// 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); }
// Auto-load control into UCAD panels
try
{
if (bool.Parse(node.Attributes["initLoad"].Value))
{
UCAD.Load_Control(this, new EventArgs());
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
// See if control should be visible UCAD panels
try
{
if (bool.Parse(node.Attributes["hideMenu"].Value))
{
this.Visible = false;
}
}
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));
}
}
}
///
/// 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()
{
}
///
/// 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;
}
}
}