using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; using System.Text.RegularExpressions; namespace Volian.Controls.Library { #region Enums public enum ChildRelation : int { None = 0, After = 1, Before = 2, RNO = 3 } public enum ExpandingStatus : int { No = 0, Expanding = 1, Colapsing = 2, Hiding = 4, Showing = 8, Done = 16 } #endregion //public delegate void vlnCSLARTBLinkEvent(object sender, vlnCSLARTBLinkEventArgs args); public partial class DisplayItem : UserControl { private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); #region Events //public event vlnCSLARTBLinkEvent LinkClicked; //private void OnLinkClicked(object sender, vlnCSLARTBLinkEventArgs args) //{ // if (LinkClicked != null) LinkClicked(sender, args); // else MessageBox.Show(args.LinkInfo.LinkText, "Unhandled Link Click", MessageBoxButtons.OK, MessageBoxIcon.Information); //} //public event vlnCSLARTBEvent BeforeExpand; //private void OnBeforeExpand(object sender, EventArgs args) //{ // if (BeforeExpand != null) BeforeExpand(sender, args); //} //public event vlnCSLARTBEvent BeforeColapse; //private void OnBeforeColapse(object sender, EventArgs args) //{ // if (BeforeColapse != null) BeforeColapse(sender, args); //} #endregion #region Private Fields private bool _ChildrenLoaded=false; private StepSectionLayoutData _Layout; //private FormatInfo _ActiveFormat; private DisplayPanel _Panel; private ChildRelation _Relation; private bool _Loading = true; private List _Before; private List _After; private List _RNO; private StepData _StepData; #endregion // TODO: Look at modules to see if any should be made static #region Properties private ItemInfo _MyItem; public ItemInfo MyItem { get { return _MyItem; } set { _MyItem = value; int typ = (int) value.MyContent.Type; //TimeIt("f"); //TabFormat = TemporaryFormat.TabFormat(this); //TimeIt("g"); if (typ >= 20000) { int stepType = typ % 10000; _StepData = value.ActiveFormat.PlantFormat.FormatData.StepDataList[stepType]; //_StepData = _ActiveFormat.PlantFormat.FormatData.StepDataList[stepType]; } if (value.MyContent.Type == 20001) Circle = true; if (_TabFormat == "o ") CheckOff = true; if ((value.ItemID % 25) == 0) ChangeBar = true; //if (value != null) //{ // this.veRichTextBoxText.MyItem = value; // //this.veRichTextBoxText.Text = _MyItem.MyContent.Text; // //this.lblTab.Text = _MyItem.MyContent.Type < 20000 ? _MyItem.MyContent.Number : _MyItem.Ordinal.ToString(); // //this.lblTab.Text = _MyItem.ItemID.ToString(); // SetTab(); //} } } private void SetText() { if (_MyItem != null) this._DisplayRTB.MyItem = _MyItem; } //private static int _ColS = 8 * 120;//TODO: _layout.ColS private static int __WidthAdjust = 3; private DisplayItem _MyParent = null; public DisplayItem MyParent { get { return _MyParent; } set { _MyParent = value; if (_MyParent != null) { //this.BackColor = Color.Red; //TabFormat = TemporaryFormat.TabFormat(this); switch (_Relation) { case ChildRelation.None: // Same as after //Location = new Point(_MyParent.Left + 20, _MyParent.Bottom); //Width = _MyParent.Width - 20; //break; case ChildRelation.After: // The size depends upon the parent type int iType = (int)_MyParent._Type; switch (iType / 10000) { case 0: ItemLocation = new Point(_MyParent.ItemLocation.X + 20, _MyParent.Bottom); ItemWidth = _Panel.ToDisplay(_Layout.ColT) + _Panel.ToDisplay(_Layout.WidT); break; case 1: //ItemWidth = _Panel.ToDisplay(_ColS) + _Panel.ToDisplay(_layout.WidSTableEdit, Convert.ToInt32(_layout.PMode)-1); ItemLocation = new Point(_MyParent.ItemLocation.X + 20, _MyParent.Bottom); int borderWidth = _DisplayRTB.Width - _DisplayRTB.ClientRectangle.Width; TextWidth = __WidthAdjust + borderWidth + _Panel.ToDisplay(_Layout.WidSTableEdit, Convert.ToInt32(_Layout.PMode) - 1); break; case 2: // if Table then determine width and location based upon it's parent's location if (_StepData.Type == "TABLE" || _StepData.ParentType == "TABLE") { _DisplayRTB.Font = _StepData.Font.WindowsFont; ItemWidth = (int)TableWidth(_DisplayRTB.Font, _MyItem.MyContent.Text); //ItemLocation = new Point(_MyParent.TextLeft, _MyParent.Bottom); ItemLocation = new Point(50, _MyParent.Bottom); ItemLocation = TableLocation(_MyParent, _Layout, ItemWidth); } else { ItemLocation = new Point(_MyParent.TextLeft, _MyParent.Bottom); ItemWidth = _MyParent.TextWidth; } break; } break; case ChildRelation.RNO: if (RNOLevel <= _Panel.MaxRNO) { int colR = _Panel.ToDisplay(_Layout.ColRTable, Convert.ToInt32(_Layout.PMode) - 1); if(colR - _MyParent.Width < 0) colR = _MyParent.Width + 0; ItemLocation = new Point(_MyParent.ItemLeft + RNOLevel * colR , _MyParent.Top); } else { TextLocation = new Point(_MyParent.TextLeft, _MyParent.BottomMost.Bottom); //ItemLocation = new Point(_MyParent.ItemLeft, _MyParent.BottomMost.Bottom); } // Same size as the Parent TabFormat = ""; TextWidth = _MyParent.TextWidth; break; case ChildRelation.Before: Location = new Point(_MyParent.Left + 20, _MyParent.Top); _Panel.Scrolling++; _MyParent.Top = Bottom; _Panel.Scrolling--; // Could be a Caution or Note - Need to get WidT Width = _Panel.ToDisplay(_Layout.WidT); //Width = _MyParent.Width - 20; break; } //veRichTextBoxText.ResizeForText(); } } } private float TableWidth(Font fnt, string txt) { string[] lines = txt.Split("\n".ToCharArray()); float max = 0; Graphics g = this.CreateGraphics(); PointF pnt = new PointF(0, 0); foreach (string line in lines) { string line2 = Regex.Replace(line, @"\\.*? ", ""); // Remove RTF Commands //if (line != line2) // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'{0}' <> '{1}'", line, line2); SizeF siz = g.MeasureString(line2, fnt,pnt,StringFormat.GenericTypographic) ; if (siz.Width+ _Panel.Settings.TableWidthAdjust > max) max = siz.Width + _Panel.Settings.TableWidthAdjust; } return max; } private Point TableLocation(DisplayItem parent, StepSectionLayoutData layout, int width) { int x = parent.TextLeft; int y = parent.Bottom; if (x + width > parent.Right) x = parent.Right - width; int colT = _Panel.ToDisplay(layout.ColT); if (x < colT) x = colT; return new Point(x,y); } public int ItemLeft { get { return Left+lblTab.Left; } set { Left = value - lblTab.Left; } } public int ItemTop { get { return Top; } set { _Panel.Scrolling++; Top = value; _Panel.Scrolling--; } } public Point ItemLocation { get { return new Point(Location.X + lblTab.Left, Location.Y); } set { Location = new Point(value.X - lblTab.Left,value.Y); } } public int ItemWidth { get { return Width - lblTab.Left; } set { //if(_MyLog.IsDebugEnabled)_MyLog.Debug("ItemWidth"); Width = value + lblTab.Left; } } public int TextWidth { get { return _DisplayRTB.Width; } set { //if(_MyLog.IsDebugEnabled)_MyLog.Debug("TextWidth"); Width = value + lblTab.Left + lblTab.Width; } } public Point TextLocation { get { return new Point(Location.X + _DisplayRTB.Left, Location.Y); } set { Location = new Point(value.X - _DisplayRTB.Left, value.Y); } } public int TextLeft { get { return Left + _DisplayRTB.Left; } } private string _TabFormat ; // Volian Property Snippet public string TabFormat { get { return _TabFormat; } set { _TabFormat = value; if (_MyItem != null) { string tabString = _TabFormat; switch (_Type / 10000) { case 0: // Procedure //// TIMING: vlnCSLARTB.TimeIt("TabFormat Start"); tabString = _MyItem.MyContent.Number.PadRight(20); //// TIMING: vlnCSLARTB.TimeIt("TabFormat End"); break; case 1: // Section //// TIMING: vlnCSLARTB.TimeIt("TabFormat Start"); tabString = _MyItem.MyContent.Number.PadRight(20); //// TIMING: vlnCSLARTB.TimeIt("TabFormat End"); break; case 2: // Step //// TIMING: vlnCSLARTB.TimeIt("TabFormat Start"); //int ordinal = _MyItem.Ordinal; int ordinal = Ordinal; //// TIMING: vlnCSLARTB.TimeIt("TabFormat End"); string alpha = AlphabeticalNumbering.Convert(ordinal); tabString = tabString.Replace("", alpha.ToLower()); tabString = tabString.Replace("", alpha); string roman = RomanNumeral.Convert(ordinal); tabString = tabString.Replace("", roman.ToLower()); tabString = tabString.Replace("", roman); tabString = tabString.Replace("", ordinal.ToString().PadLeft(2)); tabString = tabString.Replace("", MyID.ToString()); break; } lblTab.Text = tabString; //lblTab.Visible = (tabString != ""); lblTab.Width = tabString.Length * 8; _DisplayRTB.Left = lblTab.Left + lblTab.Width;// +2; _DisplayRTB.Width = Width - _DisplayRTB.Left; // TODO: Performance - SetToolTip(); //// TIMING: vlnCSLARTB.TimeIt("TabFormat Done"); } } } public int Ordinal { get { int count = 1; for (DisplayItem tmp = this; tmp.Previous != null; tmp = tmp.Previous) count++; return count; } } private DisplayItem _Previous = null; public DisplayItem Previous { get { return _Previous; } set { _Previous = value; if (_Previous != null) { Location = new Point(_Previous.Left, _Previous.BottomMost.Bottom); Width = Previous.Width; switch (_Relation) { case ChildRelation.None: break; case ChildRelation.After: break; case ChildRelation.RNO: break; case ChildRelation.Before: _Panel.Scrolling++; UpOne.Top = BottomMost.Bottom; _Panel.Scrolling--; break; } if (_Previous.Next != this) _Previous.Next = this; } } } private DisplayItem _Next = null; public DisplayItem Next { get { return _Next; } set { _Next = value; if (_Next != null) { if (_Next.Previous != this) { _Next.Previous = this; Next.Location = new Point(Left, Bottom); } } } } //private delegate vlnCSLARTB FindNext(); public DisplayItem TopMost { get { if (Expanded && _Before != null) return _Before[0].TopMost; return this; } } public new int Bottom { get { return Top + (Visible ? Height : 0); } } public DisplayItem BottomMost { get { DisplayItem tmpr = null; if ((Expanding != ExpandingStatus.No || Expanded) && _RNO != null) tmpr = _RNO[_RNO.Count - 1].BottomMost; DisplayItem tmpa = this; if ((Expanding != ExpandingStatus.No || Expanded) & _After != null) tmpa = _After[_After.Count - 1].BottomMost; if (tmpr == null) return tmpa; //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("Left {0}, Right {1}", tmpa.Bottom, tmpr.Bottom); if (tmpa.Bottom >= tmpr.Bottom) return tmpa; return tmpr; } } private DisplayItem FirstSibling { get { DisplayItem tmp = this; while (tmp.Previous != null) tmp = tmp.Previous; return tmp; } } private int _ExpandPrefix = 0; private int _ExpandSuffix = 0; private DisplayItem LastSibling { get { DisplayItem tmp = this; while (tmp.Next != null) tmp = tmp.Next; return tmp; } } public bool Expanded { get { return !_Colapsing && (Expanding != ExpandingStatus.No || vlnExp.Expanded); } set { vlnExp.Expanded = value; } } private ExpandingStatus _Expanding = ExpandingStatus.No; // Volian Property Snippet public ExpandingStatus Expanding { get { return _Expanding; } set { _Expanding = value; } } private bool _Colapsing = false; // Volian Property Snippet public bool Colapsing { get { return _Colapsing; } set { _Colapsing = value; } } public bool CanExpand { get { return vlnExp.Visible; } set { vlnExp.Visible = value; } } public string MyText { get { return _MyItem == null ? null : _MyItem.MyContent.Text; } } public int MyID { get { return _MyItem == null ? 0 : _MyItem.ItemID; } } //private bool ShowMoves = false; private bool _Moving = false; // Volian Property Snippet public bool Moving { get { return _Moving; } set { _Moving = value; } } private int _RNOLevel =0; // Volian Property Snippet public int RNOLevel { get { return _RNOLevel; } set { _RNOLevel = value; } } private int _SeqLevel = 0; // Volian Property Snippet public int SeqLevel { get { return _SeqLevel; } set { _SeqLevel = value; } } private int _Type; #endregion #region Constructors public DisplayItem(ItemInfo item, DisplayPanel panel, DisplayItem parent, ChildRelation relationType, bool expand) { //// TIMING: vlnCSLARTB.TimeIt("CSLARTB Top"); InitializeComponent();// TODO: Performance 25% //// TIMING: vlnCSLARTB.TimeIt("CSLARTB InitComp"); BackColor = panel.PanelColor; _DisplayRTB.BackColor = panel.InactiveColor; // TODO: Adjust top based upon format // TODO: Remove Label and just output ident on the paint event lblTab.Top = 3; _DisplayRTB.Top = 3; this.Paint += new PaintEventHandler(vlnCSLARTB_Paint); this.BackColorChanged += new EventHandler(vlnCSLARTB_BackColorChanged); _DisplayRTB.Enter += new EventHandler(_DisplayRTB_Enter); if (item != null) { _Type = (int)item.MyContent.Type; switch (_Type / 10000) { case 0: _DisplayRTB.Font = lblTab.Font = panel.ProcFont; break; case 1: _DisplayRTB.Font = lblTab.Font = panel.SectFont; break; case 2: _DisplayRTB.Font = lblTab.Font = panel.StepFont; _StepData = item.ActiveFormat.PlantFormat.FormatData.StepDataList[_Type%10000]; break; } } else { if (panel.MyFont != null) _DisplayRTB.Font = lblTab.Font = panel.MyFont; } if (expand) vlnExp.ShowExpanded(); _Panel = panel; if(item != null)panel.ItemLookup.Add(item.ItemID, this); _Relation = relationType; if(parent != null)RNOLevel = parent.RNOLevel; //List siblings; //TimeIt("d"); if (item != null) { //FormatInfo fi = item.ActiveFormat; //// TIMING: vlnCSLARTB.TimeIt("CSLARTB before _Layout"); _Layout = item.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData; //// TIMING: vlnCSLARTB.TimeIt("CSLARTB _Layout"); //_layout = item.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData; if (parent != null) SeqLevel = parent.SeqLevel + ((relationType == ChildRelation.After || relationType == ChildRelation.Before) && TemporaryFormat.IsSequential(item) ? 1 : 0); //// TIMING: vlnCSLARTB.TimeIt("CSLARTB seqLevel"); MyItem = item; } //TabFormat = TemporaryFormat.TabFormat(item,SeqLevel); //// TIMING: vlnCSLARTB.TimeIt("CSLARTB MyItem"); switch (relationType) { case ChildRelation.After: AddItem(parent, ref parent._After); break; case ChildRelation.Before: AddItem(parent, ref parent._Before); break; case ChildRelation.RNO: RNOLevel = parent.RNOLevel + 1; AddItem(parent, ref parent._RNO); break; case ChildRelation.None: break; } if (item != null) { //MyItem = item; if (relationType == ChildRelation.None) { if (_Type == 0 && _Layout != null) { Width = _Panel.ToDisplay(_Layout.WidT); } } //if (item != null) //{ // //int iType = ((int)item.MyContent.Type) / 10000; //} } //// TIMING: vlnCSLARTB.TimeIt("CSLARTB Parent"); SetText(); //// TIMING: vlnCSLARTB.TimeIt("CSLARTB SetText"); //MyItem = item; //TabFormat = TemporaryFormat.TabFormat(this); if (item != null) { Name = string.Format("Item-{0}", item.ItemID); // Don't allow substeps to expand switch (_Type / 10000) { case 1: //CanExpand = (item.MyContent.ContentPartCount != 0); CanExpand = true; vlnExp.Attachment = (item.MyContent.ContentPartCount == 0); break; case 2: CanExpand = item.IsHigh && item.HasChildren; // TemporaryFormat.IsHigh(item); ; break; default: CanExpand = false; break; } //CanExpand = (item.MyContent.ContentPartCount != 0); if(expand && (item.MyContent.ContentPartCount != 0)) // If it should expand and it can expand Expand(true); else if(parent == null)// If it is the top node if(_Type >= 20000) // and it is a step - fully expand Expand(true); else // otherwise only expand one level Expand(false); //BringToFront(); } //// TIMING: vlnCSLARTB.TimeIt("CSLARTB before Controls Add"); panel.Controls.Add(this); _Loading = false; //TabFormat = " "; //// TIMING: vlnCSLARTB.TimeIt("CSLARTB Controls Add"); } void _DisplayRTB_Enter(object sender, EventArgs e) { _Panel._ItemSelected = _MyItem; _Panel.OnItemSelectedChanged(sender, new DisplayPanelEventArgs(this, null)); } public void AutoExpand() { Expand(_Type >= 20000); } private bool _Circle=false; public bool Circle { get { return _Circle; } set { _Circle = value; } } private bool _CheckOff=false; public bool CheckOff { get { return _CheckOff; } set { _CheckOff = value; } } private bool _ChangeBar=false; public bool ChangeBar { get { return _ChangeBar; } set { _ChangeBar = value; } } public void ItemSelect() { _DisplayRTB.Focus(); _DisplayRTB.SelectAll(); if (CanExpand) AutoExpand(); // Expand the item if you can int scrollValue = _Panel.VerticalScroll.Value + (Top - (_Panel.Height / 2)); // calculate scroll center for the item if(scrollValue > _Panel.VerticalScroll.Minimum && scrollValue <= _Panel.VerticalScroll.Maximum) // If it isn't within range _Panel.VerticalScroll.Value = scrollValue; // Center the item } public void ItemShow() { _DisplayRTB.Focus(); } private void vlnCSLARTB_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; //g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.DrawString(lblTab.Text, _DisplayRTB.Font, Brushes.Black ,new RectangleF(new PointF(_Panel.Settings.NumberLocationX,_Panel.Settings.NumberLocationY),_Panel.Settings.NumberSize), StringFormat.GenericDefault); if (Circle) { Pen penC = new Pen(_Panel.Settings.CircleColor, _Panel.Settings.CircleWeight); g.DrawArc(penC, lblTab.Left + 1, 0, _Panel.Settings.CircleDiameter, _Panel.Settings.CircleDiameter, 0F, 360F); //g.DrawString("\u20DE", _Panel.Settings.CircleFont, bluPen.Brush, lblTab.Left + _Panel.Settings.CircleXOffset, _Panel.Settings.CircleYOffset); } if (CheckOff) { Pen penCO = new Pen(_Panel.Settings.CheckOffColor, _Panel.Settings.CheckOffWeight); g.DrawRectangle(penCO, _Panel.Settings.CheckOffX, _Panel.Settings.CheckOffY, _Panel.Settings.CheckOffSize, _Panel.Settings.CheckOffSize); } if (ChangeBar) { Pen penCB = new Pen(_Panel.Settings.ChangeBarColor, _Panel.Settings.ChangeBarWeight); g.DrawLine(penCB, 0, 0, 0, Height); } } void vlnCSLARTB_BackColorChanged(object sender, EventArgs e) { _DisplayRTB.BackColor = BackColor; } #endregion #region AddItem public void AddItem(DisplayItem parent, ref List siblings) { if (siblings == null) { siblings = new List(); siblings.Add(this); MyParent = parent; } else { DisplayItem lastChild = LastChild(siblings); siblings.Add(this); Previous = lastChild; } TabFormat = TemporaryFormat.TabFormat(this); } public DisplayItem AddNext(ItemInfo item,bool expand) { DisplayItem tmp = new DisplayItem(item, _Panel,MyParent, ChildRelation.None,expand); Next = tmp; return tmp; } #region Add Children public DisplayItem LastChild(List children) { return children[children.Count - 1]; } public void AddChildBefore(ItemInfo item,bool expand) { DisplayItem child = new DisplayItem(item, _Panel,this, ChildRelation.Before,expand); //if (_Before == null) //{ // _Before = new List(); // _Before.Add(child); // child.MyParent = this; //} //else //{ // vlnCSLARTB lastChild = LastChild(_Before); // _Before.Add(child); // child.Previous = lastChild; //} //_Before.Add(child); } public void AddChildBefore(ItemInfoList itemList, bool expand) { if (itemList != null) foreach (ItemInfo item in itemList) AddChildBefore(item, expand); } public void AddChildRNO(ItemInfo item,bool expand) { DisplayItem child = new DisplayItem(item, _Panel,this, ChildRelation.RNO,expand); //if (_RNO == null) //{ // _RNO = new List(); // _RNO.Add(child); // child.MyParent = this; //} //else //{ // child.Previous = LastChild(_RNO); // _RNO.Add(child); //} } public void AddChildRNO(ItemInfoList itemList,bool expand) { if (itemList != null) foreach (ItemInfo item in itemList) AddChildRNO(item,expand); } public void AddChildAfter(ItemInfo item,bool expand) { DisplayItem child = new DisplayItem(item, _Panel, this, ChildRelation.After,expand); child.RNOLevel = this.RNOLevel; //if (_After == null) //{ // _After = new List(); // _After.Add(child); // child.MyParent = this; //} //else //{ // vlnCSLARTB lastChild=LastChild(_After); // _After.Add(child); // child.Previous = lastChild; //} } public void AddChildAfter(ItemInfoList itemList,bool expand) { if (itemList != null) foreach (ItemInfo item in itemList) AddChildAfter(item,expand); } #endregion #endregion private void veRichTextBoxText_HeightChanged(object sender, EventArgs args) { this.Height = _DisplayRTB.Height+10; } private void vlnExp_BeforeColapse(object sender, vlnExpanderEventArgs args) { Cursor tmp = Cursor.Current; Cursor.Current = Cursors.WaitCursor; int top = TopMost.Top;// This does'nt work - this is since the last time it was expanded. _Colapsing = true; // Hide Children HideChildren(); // Adjust Positions _ExpandPrefix = Top - top; _ExpandSuffix = BottomMost.Bottom - Bottom; if (Top != top) { _Panel.Scrolling++; Top = top; _Panel.Scrolling--; } else AdjustLocation(); BottomMost.AdjustLocation(); _Colapsing = false; Cursor.Current = tmp; } protected void HideChildren() { HideChildren(_Before); HideChildren(_RNO); HideChildren(_After); } private void HideChildren(List children) { if (children != null) { foreach (DisplayItem child in children) { if (child.Expanded) child.HideChildren(); child.Visible = false; } } } protected void UnhideChildren(bool expand) { UnhideChildren(_Before,expand); UnhideChildren(_RNO, expand); UnhideChildren(_After, expand); if(!vlnExp.Expanded) vlnExp.ShowExpanded(); } private void UnhideChildren(List children,bool expand) { if (children != null) { foreach (DisplayItem child in children) { if (child.Expanded) child.UnhideChildren(expand); else if (expand) child.Expand(expand); child.Visible = true; } } } protected void AdjustChildren() { AdjustChildren(_Before); AdjustChildren(_RNO); AdjustChildren(_After); } private void AdjustChildren(List children) { if (children != null) { foreach (DisplayItem child in children) { child.AdjustLocation(); if (child.Expanded) child.AdjustChildren(); } } } private void vlnExp_AttachmentClick(object sender, vlnExpanderEventArgs args) { _Panel.OnAttachmentClicked(sender, new DisplayPanelAttachmentEventArgs(this)); } public void Expand(bool expand) { //// TIMING: vlnCSLARTB.TimeIt("Expand Start"); if (_ChildrenLoaded) { // Unhide Children Expanding = ExpandingStatus.Showing; UnhideChildren(expand); if (_ExpandPrefix != 0) { _Panel.Scrolling++; TopMost.Top = Top; _Panel.Scrolling--; } else TopMost.AdjustLocation(); AdjustChildren(); //if(_Before != null ) // Top = _Before[_Before.Count - 1].BottomMost.Bottom; } else { Expanding = ExpandingStatus.Expanding; _ChildrenLoaded = true; //_Panel.SuspendLayout(); AddChildBefore(MyItem.Cautions, expand); AddChildBefore(MyItem.Notes, expand); AddChildAfter(MyItem.Procedures, expand); AddChildAfter(MyItem.Sections, expand); AddChildAfter(MyItem.Steps, expand); AddChildAfter(MyItem.Tables, expand); AddChildRNO(MyItem.RNOs, expand); //if (args.Mode == vlnExpanderMode.ExpandAll) // ExpandChildren(args); //_Panel.ResumeLayout(); if (!vlnExp.Expanded) vlnExp.ShowExpanded(); } Expanding = ExpandingStatus.Done; BottomMost.AdjustLocation(); Expanding = ExpandingStatus.No; //// TIMING: vlnCSLARTB.TimeIt("Expand End"); } private void vlnExp_BeforeExpand(object sender, vlnExpanderEventArgs args) { Cursor tmp = Cursor.Current; Cursor.Current = Cursors.WaitCursor; if (!_Loading && Expanding == ExpandingStatus.No) Expand(_Type >= 20000); Cursor.Current = tmp; //Expand(args.Mode == vlnExpanderMode.ExpandAll); } private void ExpandChildren(List children) { if (children != null) { foreach (DisplayItem child in children) { if (child.CanExpand) { child.Expand(true); } child.Visible = true; } } } private void ExpandChildren() { // Walk though Children performing Expand ExpandChildren(_Before); ExpandChildren(_RNO); ExpandChildren(_After); } public DisplayItem NextItem { get { //if (this.MyID == _WatchFor) // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("{0}", _WatchFor); DisplayItem tmp = this; if (tmp.Next == null && FirstSibling._Relation == ChildRelation.Before) return UpOne; if (Expanded && tmp._After != null) return tmp._After[0].TopMost; // check to see if there is a _After if there is go that way while (tmp != null && tmp.Next == null) // if no Next walk up the parent path { tmp = tmp.UpOne; if (tmp == null) // No Parent return null; if (tmp.Expanding == ExpandingStatus.Expanding || tmp.Moving) // Parent Expanding or Moving - Wait return null; DisplayItem btm = tmp.BottomMost; //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'BottomMost',{0},'{1}'", btm.MyID, btm.MyText); if (this != btm) { if (tmp.Next != null && tmp.Next.TopMost.Top != btm.Bottom) { _Panel.Scrolling++; tmp.Next.TopMost.Top = btm.Bottom; _Panel.Scrolling--; } return null; // Not the bottom - don't adjust anything else } } if (tmp != null) return tmp.Next.TopMost;// if no _After - check to see if there is a Next //if (tmp != null) return tmp.Next;// if no _After - check to see if there is a Next return null; } } private DisplayItem UpOne { get { DisplayItem tmp = this; while (tmp != null && tmp.MyParent == null) tmp = tmp.Previous; if (tmp != null) return tmp.MyParent; return null; } } //static int _WatchFor = 333; private void AdjustLocation() { //if (this.MyID == _WatchFor) // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("{0}",_WatchFor); DisplayItem tmp = NextItem; if (tmp == null) return; //if(tmp.Top > _Panel.Height && Bottom > _Panel.Height){ // if(Bottom - tmp.Top != 0) // _Panel.AdjustOutOfRangeControls(Bottom - tmp.Top); // return; //} if (tmp != null && !tmp.Moving && tmp.Top != Bottom ) { //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'Adjust Location',{0},'Move',{1}", MyID, tmp.MyID); //tmp.TopMost.Top = Bottom; _Panel.Scrolling++; tmp.Top = Bottom; _Panel.Scrolling--; } } //private void SetToolTip() //{ // toolTip1.SetToolTip(veRichTextBoxText, // string.Format("ID={0}, ItemLeft={1}, ItemWidth={2}, TextWidth={3}, Width={4}",MyID,ItemLeft,ItemWidth,TextWidth,Width)); //} //private static double Seconds() //{ // DateTime t = DateTime.Now; // return ((t.Hour * 60.0) + t.Minute) * 60.0 + t.Second + (t.Millisecond / 1000.0); //} //private static DateTime tLast = DateTime.Now; //private static Dictionary dicTiming = new Dictionary(); //public static void TimeIt(string p) //{ // DateTime tNow = DateTime.Now; // if (!dicTiming.ContainsKey(p)) dicTiming[p] = 0; // dicTiming[p] += (tNow.Ticks - tLast.Ticks); // //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\t{0}\t{1:0.000}", p, tNow - tLast); // tLast = tNow; //} //public static void TimeItList() //{ // //string sep = "\r\n"; // long total = 0; // foreach (string s in dicTiming.Keys) // { // //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("{0}\"{1}\"",sep, s); // total += dicTiming[s]; // //sep = "\t"; // } // //sep = "\r\n"; // foreach (string s in dicTiming.Keys) // { // //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("{0}{1}", sep, (dicTiming[s]*100)/total ); // //sep = "\t"; // long i = (dicTiming[s]*10000)/total; // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\"{0}\"\t{1}\t{2}\t\"{3}\"", s, dicTiming[s], ((float)i) / 100, "".PadRight((int)(i / 100), 'X')); // } // //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\r\n{0:0.000}", tNow - tLast); //} //public static void TimeItSetup() //{ // dicTiming = new Dictionary(); // DateTime tNow = DateTime.Now; // // Reset all Counts // //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("{0:0.000}", tNow - tLast); // tLast = tNow; //} public IDisplayRTB TextBox { get { return (IDisplayRTB)_DisplayRTB; } } private void vlnCSLARTB_Resize(object sender, EventArgs e) { //return; //TimeIt("ResizeStart"); if (_MyItem == null) return; //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'Resize',{0},{1},{2},{3},{4}", MyID, Top, Left, Height, Width); //SetToolTip(); AdjustLocation(); //TimeIt("ResizeEnd"); } private void vlnCSLARTB_Move(object sender, EventArgs e) { //return; if (_Panel.Scrolling == 0) return; //_MyLog.DebugFormat("'Move',{0},{1},{2},{3},{4}", MyID, Top, Left, Height, Width); if (_MyItem == null) return; //if (_Panel.Scrolling) return; if (Expanding == ExpandingStatus.Expanding) return; _Moving = true; //if (_Panel.Automatic == false) return; DisplayItem tmp = (DisplayItem)sender; if (tmp._Previous == null && tmp._MyParent == null) { //_Panel.Scrolling = true; return; } //if (ShowMoves) //if (MyID == 367) //{ // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat(",{0},{1},{2},{3},'{4}'", MyID, tmp.MyID, Top, Left, e.GetType().Name); // //ShowMoves = true; //} //SetToolTip(); AdjustLocation(); //if (_After != null) //{ // if (_After[0].TopMost.Top != Bottom) // { // if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'Adjust After',{0},'{1}'", MyID, MyText); // _After[0].TopMost.Top = Bottom; // } //} if (_RNO != null) { if (_RNO[0].TopMost.Top != Top) { //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\r\n'Adjust RNO',{0},'Move',{1}", MyID, _RNO[0].MyID); if (RNOLevel >= _Panel.MaxRNO) { DisplayItem tmpBottom = this; if (_After != null) tmpBottom = _After[_After.Count - 1].BottomMost; _Panel.Scrolling++; _RNO[0].TopMost.Top = tmpBottom.Bottom; _Panel.Scrolling--; } else { _Panel.Scrolling++; _RNO[0].TopMost.Top = Top; _Panel.Scrolling--; } } } _Moving = false; BottomMost.AdjustLocation(); } //private void veRichTextBoxText_LinkClicked(object sender, LinkClickedEventArgs e) //{ // //MessageBox.Show(e.LinkText); // _Panel.OnLinkClicked(sender, new DisplayLinkEventArgs(this, e)); //} void _DisplayRTB_LinkGoTo(object sender, System.Windows.Forms.LinkClickedEventArgs e) { _MyLog.DebugFormat("_DisplayRTB_LinkGoTo " + e.LinkText); _Panel.OnLinkClicked(sender, new DisplayLinkEventArgs(this, e)); } private void lblTab_MouseDown(object sender, MouseEventArgs e) { _Panel.OnItemClick(this, new DisplayPanelEventArgs(this, e)); } private void veRichTextBoxText_Enter(object sender, EventArgs e) { _DisplayRTB.BackColor = _Panel.ActiveColor; } private void veRichTextBoxText_Leave(object sender, EventArgs e) { _DisplayRTB.BackColor = _Panel.InactiveColor; } private void veRichTextBoxText_Resize(object sender, EventArgs e) { //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("'Resize Text',{0},{1},{2},{3},{4}", MyID, Top, Left, Height, Width); } } }