using System; using System.ComponentModel; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; using System.Drawing; using System.Text.RegularExpressions; namespace Volian.Controls.Library { public partial class DisplayPanel : Panel { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #region Events public event DisplayPanelEvent ItemClick; internal void OnItemClick(object sender, DisplayPanelEventArgs args) { if (ItemClick != null) ItemClick(sender, args); } public event DisplayPanelEvent ItemSelectedChanged; internal void OnItemSelectedChanged(object sender, DisplayPanelEventArgs args) { if (ItemSelectedChanged != null) ItemSelectedChanged(sender, args); } public event DisplayPanelLinkEvent LinkClicked; internal void OnLinkClicked(object sender, DisplayLinkEventArgs args) { if (LinkClicked != null) LinkClicked(sender, args); else MessageBox.Show(args.LinkInfo.LinkText, "Unhandled Link Click", MessageBoxButtons.OK, MessageBoxIcon.Information); } public event DisplayPanelLinkEvent LinkModifyTran; internal void OnLinkModifyTran(object sender, DisplayLinkEventArgs args) { if (LinkModifyTran != null) LinkModifyTran(sender, args); else MessageBox.Show(args.LinkInfo.LinkText, "Unhandled Link Modify Tran", MessageBoxButtons.OK, MessageBoxIcon.Information); } public event DisplayPanelAttachmentEvent AttachmentClicked; internal void OnAttachmentClicked(object sender, DisplayPanelAttachmentEventArgs args) { if (AttachmentClicked != null) AttachmentClicked(sender, args); else MessageBox.Show(args.MyDisplayItem.MyItem.MyContent.MyEntry.MyDocument.DocumentTitle, "Unhandled Attachment Click", MessageBoxButtons.OK, MessageBoxIcon.Information); } #endregion #region Constructors public DisplayPanel() { InitializeComponent(); this.Paint += new PaintEventHandler(DisplayPanel_Paint); this.DoubleClick += new EventHandler(DisplayPanel_DoubleClick); this.AutoScroll = true; } void DisplayPanel_DoubleClick(object sender, EventArgs e) { ShowLines = !ShowLines; Refresh(); } private void VerticalLine(Graphics g, int x) { Pen bluePen = new Pen(Color.CornflowerBlue,1); g.DrawLine(bluePen, x, 0, x, this.Height); } void DisplayPanel_Paint(object sender, PaintEventArgs e) { if (ShowLines) { //int fifth = Height / 5; //Rectangle r1 = new Rectangle(0, 0, Width, Height - fifth); ////Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(r1, Color.FromArgb(128, 0, 32), Color.FromArgb(96, 0, 16), 90); //Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(r1, Color.FromArgb(255,128, 0, 32), Color.FromArgb(255,96, 0, 16),System.Drawing.Drawing2D.LinearGradientMode.Vertical); //e.Graphics.FillRectangle(b, r1); //r1 = new Rectangle(0, Height - fifth, Width, fifth); //b = new System.Drawing.Drawing2D.LinearGradientBrush(r1, Color.FromArgb(255,96, 0, 16), Color.FromArgb(255,128, 0, 32), 90); //e.Graphics.FillRectangle(b, r1); //VerticalLine(e.Graphics, 60); //VerticalLine(e.Graphics, 102); //VerticalLine(e.Graphics, 415); } } public DisplayPanel(IContainer container) { container.Add(this); InitializeComponent(); this.Paint += new PaintEventHandler(DisplayPanel_Paint); this.BackColorChanged += new EventHandler(DisplayPanel_BackColorChanged); this.DoubleClick += new EventHandler(DisplayPanel_DoubleClick); this.AutoScroll = true; } void DisplayPanel_BackColorChanged(object sender, EventArgs e) { // Walk through controls & set colors InactiveColor = PanelColor = BackColor; foreach (Control ctrl in Controls) { if (ctrl.GetType().Name == "vlnCSLARTB") { DisplayItem rtb = (DisplayItem)ctrl; rtb.BackColor = BackColor; } } } #endregion #region Business private StepSectionLayoutData _Layout; // Volian Property Snippet private ItemInfo _MyItem; public ItemInfo MyItem { get { return _MyItem; } set { //// TIMING: vlnCSLARTB.TimeIt("pMyItem Start"); _MyItem = value; if(value != null) _Layout = _MyItem.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData; //// TIMING: vlnCSLARTB.TimeIt("pMyItem Layout"); //this.Layout += new LayoutEventHandler(DisplayPanel_Layout); //this.Scroll += new ScrollEventHandler(DisplayPanel_Scroll); //// TIMING: vlnCSLARTB.TimeIt("pMyItem Scroll"); Controls.Clear(); ItemLookup = new Dictionary(); //// TIMING: vlnCSLARTB.TimeIt("pMyItem Clear"); //SuspendLayout(); DisplayItem vlnRTF = new DisplayItem(_MyItem, this, null, ChildRelation.None, false); //ResumeLayout(); //// TIMING: vlnCSLARTB.TimeIt("pMyItem End"); } } internal Dictionary _ItemLookup; public Dictionary ItemLookup { get { return _ItemLookup; } set { _ItemLookup = value; } } public void ExpandAsNeeded(ItemInfo item) { int id = item.ItemID; if (ItemLookup.ContainsKey(id)) { ItemLookup[id].AutoExpand(); } else { ExpandAsNeeded((ItemInfo)item.ActiveParent); if (!ItemLookup.ContainsKey(id)) // Expand Parent if not expanded { int parentId = ((ItemInfo)item.ActiveParent).ItemID; ItemLookup[parentId].AutoExpand(); } } } public void ItemSelect(ItemInfo item) { int id = item.ItemID; ExpandAsNeeded(item); ItemLookup[id].ItemSelect(); } private DisplayRTB _DisplayRTB = null; public DisplayRTB DisplayRTB { get { return _DisplayRTB; } set { if (_DisplayRTB == value) return; // Same - No Change if (_DisplayRTB != null) { _DisplayRTB.BackColor = InactiveColor; _DisplayRTB.SaveText(); // Save any changes to the text } _DisplayRTB = value; _DisplayRTB.BackColor = ActiveColor; } } //private ItemInfo _LastItemSelected; //internal ItemInfo LastItemSelected //{ // get { return _LastItemSelected; } //} internal ItemInfo _ItemSelected; public ItemInfo ItemSelected { get { return _ItemSelected; } set { _ItemSelected = value; //if (value == null) //{ // OnItemSelectedChanged(this, null); // return; //} //_LastItemSelected = value; int id = value.ItemID; ExpandAsNeeded(value); ItemLookup[id].ItemSelect(); OnItemSelectedChanged(this, new DisplayPanelEventArgs(ItemLookup[id], null)); } } public DisplayItem DisplayItemSelected { get { return (_ItemSelected != null) ? ItemLookup[_ItemSelected.ItemID] : null; } } public void ItemShow() { if (_ItemSelected != null) ItemLookup[_ItemSelected.ItemID].ItemShow(); } private int _Scrolling = 0; // Volian Property Snippet public int Scrolling { get { return _Scrolling; } set { _Scrolling = value; } } private DisplayPanelSettings _Settings; // Volian Property Snippet public DisplayPanelSettings Settings { get { if (_Settings == null) _Settings = new DisplayPanelSettings(this); return _Settings; } set { _Settings = value;} } //void DisplayPanel_Layout(object sender, LayoutEventArgs e) // { // //if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("layout {0} {1} {2} {3}", e.AffectedComponent.GetType().Name,e.AffectedControl.Name,e.AffectedProperty, sender.GetType().Name); // } //void DisplayPanel_Scroll(object sender, ScrollEventArgs e) //{ // //if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("scroll {0} {1} {2} {3}", e.OldValue, e.NewValue, e.ScrollOrientation,sender.GetType().Name); // Scrolling = false; //} //public void AdjustOutOfRangeControls(int yAdjust) //{ // bool scrolling = Scrolling; // Scrolling = true; // foreach (Control control in Controls) // if (control.GetType().Name == "vlnCSLARTB" && control.Top > Height) // control.Top += yAdjust; // Scrolling = scrolling; //} private int _MaxRNO = -1; // TODO: Need to calculate MaxRNO on a section basis rather than for a panel public int MaxRNO { get { if(_MaxRNO == -1) { int pmode = Convert.ToInt32(_Layout.PMode) - 1; _MaxRNO = Convert.ToInt32( _Layout.MaxRNOTable.Split(",".ToCharArray())[pmode]); } return _MaxRNO; } } private Font _MyFont =null; // Volian Property Snippet public Font MyFont { get { return _MyFont; } set { _ProcFont = _SectFont = _StepFont = _MyFont = value; } } private Font _ProcFont =new Font("Arial",12,FontStyle.Bold); // Volian Property Snippet public Font ProcFont { get { return _ProcFont; } set { _ProcFont = value; } } private Font _SectFont = new Font("Arial", 10, FontStyle.Bold); // Volian Property Snippet public Font SectFont { get { return _SectFont; } set { _SectFont = value; } } private Font _StepFont = new Font("Arial", 10); // Volian Property Snippet public Font StepFont { get { return _StepFont; } set { _StepFont = value; } } private Color _ActiveColor =Color.SkyBlue; // Volian Property Snippet public Color ActiveColor { get { return _ActiveColor; } set { _ActiveColor = value; } } #if (DEBUG) private Color _InactiveColor =Color.Linen; // Volian Property Snippet #else private Color _InactiveColor = Color.White; // Volian Property Snippet #endif public Color InactiveColor { get { return _InactiveColor; } set { _InactiveColor = value; } } #if (DEBUG) private Color _TabColor =Color.Beige; // Volian Property Snippet #else private Color _TabColor = Color.White; // Volian Property Snippet #endif public Color TabColor { get { return _TabColor; } set { _TabColor = value; } } #if (DEBUG) private Color _PanelColor = Color.LightGray;// Volian Property Snippet #else private Color _PanelColor = Color.White; // Volian Property Snippet #endif public Color PanelColor { get { return _PanelColor; } set { _PanelColor = value; BackColor = value; } } private bool _ShowLines =true; // Volian Property Snippet public bool ShowLines { get { return _ShowLines; } set { _ShowLines = value; } } #endregion #region DisplayConversions private Graphics _MyGraphics = null; public Graphics MyGraphics { get { if (_MyGraphics == null) _MyGraphics = CreateGraphics(); return _MyGraphics; } } private int _DPI =0; // Volian Property Snippet public int DPI { get { if (_DPI == 0) _DPI = Convert.ToInt32(MyGraphics.DpiX); return _DPI; } } public int ToDisplay(int value) { //return (DPI * value) / 864; return (DPI * value) / 72; } public int ToDisplay(int? value) { return ToDisplay((int)value); } public int ToDisplay(string value) { return ToDisplay(Convert.ToInt32(value)); } public int ToDisplay(string value,int i) { string s = value.Split(",".ToCharArray())[i]; return ToDisplay(s); } #endregion #region Debug Methods public void ListControls() { // Walk through the controls and find the next control for each if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("'Item','Next'"); foreach (Control control in Controls) if (control.GetType().Name == "vlnCSLARTB") { DisplayItem rtb = (DisplayItem)control; DisplayItem nxt = rtb.NextItem; if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("{0},{1}", rtb.MyID, nxt == null ? 0 : nxt.MyID); } } #endregion } [TypeConverter(typeof(ExpandableObjectConverter))] public partial class DisplayPanelSettings { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); public DisplayPanelSettings(DisplayPanel panel) { _Panel = panel; } public DisplayPanelSettings() { } private DisplayPanel _Panel; [Browsable(false)] public DisplayPanel Panel { get { return _Panel; } set { _Panel = value; } } private float _CircleXOffset = -4; [Category("Circle")] [DisplayName("Circle Horizontal Offset")] public float CircleXOffset { get { return _CircleXOffset; } set { _CircleXOffset = value; if (_Panel != null) _Panel.Refresh(); } } private float _CircleYOffset = -13; [Category("Circle")] [DisplayName("Circle Vertical Offset")] public float CircleYOffset { get { return _CircleYOffset; } set { _CircleYOffset = value; if (_Panel != null) _Panel.Refresh(); } } private Font _CircleFont = new Font("Arial Unicode MS", 23); // Volian Property Snippet [Category("Circle")] [DisplayName("Circle Font")] public Font CircleFont { get { return _CircleFont; } set { _CircleFont = value; if(_Panel != null) _Panel.Refresh(); } } private Color _CircleColor = Color.Black; [Category("Circle")] [DisplayName("Circle Color")] public Color CircleColor { get { return _CircleColor; } set { _CircleColor = value; if (_Panel != null) _Panel.Refresh(); } } private int _CircleDiameter = 25; [Category("Circle")] [DisplayName("Circle Diameter")] public int CircleDiameter { get { return _CircleDiameter; } set { _CircleDiameter = value; if (_Panel != null) _Panel.Refresh(); } } private int _CircleWeight = 2; [Category("Circle")] [DisplayName("Circle Pen Weight")] public int CircleWeight { get { return _CircleWeight; } set { _CircleWeight = value; if (_Panel != null) _Panel.Refresh(); } } private float _NumberLocationX = 20F; [Category("Number")] [DisplayName("Number Location X")] public float NumberLocationX { get { return _NumberLocationX; } set { _NumberLocationX = value; if (_Panel != null) _Panel.Refresh(); } } private float _NumberLocationY = 4; [Category("Number")] [DisplayName("Number Location Y")] public float NumberLocationY { get { return _NumberLocationY; } set { _NumberLocationY = value; if (_Panel != null) _Panel.Refresh(); } } private SizeF _NumberSize = new SizeF(200F, 23F); [Category("Number")] [DisplayName("Number Size")] public SizeF NumberSize { get { return _NumberSize; } set { _NumberSize = value; if (_Panel != null) _Panel.Refresh(); } } private int _TableWidthAdjust = 4; [Category("Table")] [DisplayName("Table Width Adjust")] public int TableWidthAdjust { get { return _TableWidthAdjust; } set { _TableWidthAdjust = value; if (_Panel != null) _Panel.Refresh(); } } private int _CheckOffWeight = 1; [Category("CheckOff")] [DisplayName("CheckOff Pen Weight")] public int CheckOffWeight { get { return _CheckOffWeight; } set { _CheckOffWeight = value; if (_Panel != null) _Panel.Refresh(); } } private Color _CheckOffColor = Color.Black; [Category("CheckOff")] [DisplayName("CheckOff Color")] public Color CheckOffColor { get { return _CheckOffColor; } set { _CheckOffColor = value; if (_Panel != null) _Panel.Refresh(); } } private int _CheckOffSize =12; [Category("CheckOff")] [DisplayName("CheckOff Size")] public int CheckOffSize { get { return _CheckOffSize; } set { _CheckOffSize = value; if (_Panel != null) _Panel.Refresh(); } } private int _CheckOffX =0; [Category("CheckOff")] [DisplayName("CheckOff X")] public int CheckOffX { get { return _CheckOffX; } set { _CheckOffX = value; if (_Panel != null) _Panel.Refresh(); } } private int _CheckOffY =5; // Volian Property Snippet [Category("CheckOff")] [DisplayName("CheckOff Y")] public int CheckOffY { get { return _CheckOffY; } set { _CheckOffY = value; if (_Panel != null) _Panel.Refresh(); } } private int _ChangeBarWeight = 1; [Category("ChangeBar")] [DisplayName("ChangeBar Pen Weight")] public int ChangeBarWeight { get { return _ChangeBarWeight; } set { _ChangeBarWeight = value; if (_Panel != null) _Panel.Refresh(); } } private Color _ChangeBarColor = Color.Black; [Category("ChangeBar")] [DisplayName("ChangeBar Color")] public Color ChangeBarColor { get { return _ChangeBarColor; } set { _ChangeBarColor = value; if (_Panel != null) _Panel.Refresh(); } } } public partial class DisplayPanelEventArgs { private DisplayItem _MyVlnCSLARTB; // Volian Property Snippet public DisplayItem MyVlnCSLARTB { get { return _MyVlnCSLARTB; } set { _MyVlnCSLARTB = value; } } private MouseEventArgs _MyMouseEventArgs; // Volian Property Snippet public MouseEventArgs MyMouseEventArgs { get { return _MyMouseEventArgs; } set { _MyMouseEventArgs = value; } } public DisplayPanelEventArgs(DisplayItem myVlnCSLARTB, MouseEventArgs myMouseEventArgs) { _MyVlnCSLARTB = myVlnCSLARTB; _MyMouseEventArgs = myMouseEventArgs; } } public partial class DisplayPanelAttachmentEventArgs { private DisplayItem _MyDisplayItem; // Volian Property Snippet public DisplayItem MyDisplayItem { get { return _MyDisplayItem; } set { _MyDisplayItem = value; } } public DisplayPanelAttachmentEventArgs(DisplayItem myDisplayItem) { _MyDisplayItem = myDisplayItem; } } public partial class DisplayLinkEventArgs : EventArgs { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private DisplayItem _LinkedRTB; // Volian Property Snippet public DisplayItem LinkedRTB { get { return _LinkedRTB; } set { _LinkedRTB = value; } } private LinkClickedEventArgs _LinkInfo; // Volian Property Snippet public LinkClickedEventArgs LinkInfo { get { return _LinkInfo; } set { _LinkInfo = value; } } public DisplayLinkEventArgs(DisplayItem linkedRTB, LinkClickedEventArgs linkInfo) { LinkedRTB = linkedRTB; LinkInfo = linkInfo; //if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("\r\n LinkInfo '{0}'\r\n", linkInfo.LinkText); } private void ParseLink() { if (_Type == ParsedLinkType.NotParsed) { // First parse the string Match m = Regex.Match(_LinkInfo.LinkText, ".*[#]Link:([A-Za-z]*):(.*)"); switch (m.Groups[1].Value) { case "ReferencedObject": _Type = ParsedLinkType.ReferencedObject; _RoUsageid = m.Groups[2].Value; _Roid = m.Groups[3].Value; break; case "Transition": case "TransitionRange": _Type = (ParsedLinkType)Enum.Parse(_Type.GetType(), m.Groups[1].Value); if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("Link String - '{0}'", m.Groups[2].Value); int transitionID = Convert.ToInt32(m.Groups[2].Value.Split(" ".ToCharArray())[1]); foreach (TransitionInfo ti in _LinkedRTB.MyItem.MyContent.ContentTransitions) { if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("Transition ID = '{0}'", ti.TransitionID); if (ti.TransitionID == transitionID) _MyTransition = ti; } break; } } } private TransitionInfo _MyTransition = null; // Volian Property Snippet public TransitionInfo MyTransition { get { ParseLink(); return _MyTransition; } } public ItemInfo ItemTo { get { ParseLink(); return _MyTransition.MyItemToID; } } public ItemInfo ItemRange { get { ParseLink(); return _MyTransition.MyItemRangeID; } } private string _Roid = null; // TODO: need to return Referenced Object rather than just roid public string Roid { get { ParseLink(); return _Roid; } } private string _RoUsageid = null; // TODO: need to return Referenced Object rather than just roid public string RoUsageid { get { ParseLink(); return _RoUsageid; } } private ParsedLinkType _Type = ParsedLinkType.NotParsed; // Volian Property Snippet public ParsedLinkType Type { get { ParseLink(); return _Type; } } } #region enums public enum ParsedLinkType : int { NotParsed = 0, Transition = 1, TransitionRange = 2, ReferencedObject = 3 } #endregion public delegate void DisplayPanelEvent(object sender, DisplayPanelEventArgs args); public delegate void DisplayPanelLinkEvent(object sender, DisplayLinkEventArgs args); public delegate void DisplayPanelAttachmentEvent(object sender, DisplayPanelAttachmentEventArgs args); public delegate void DisplayRTBLinkEvent(object sender, LinkClickedEventArgs e); }