diff --git a/PROMS/Volian.Controls.Library/DSOTabPanel.cs b/PROMS/Volian.Controls.Library/DSOTabPanel.cs index 73fb0d8f..2418226b 100644 --- a/PROMS/Volian.Controls.Library/DSOTabPanel.cs +++ b/PROMS/Volian.Controls.Library/DSOTabPanel.cs @@ -368,7 +368,7 @@ namespace Volian.Controls.Library if (MyDisplayTabItem.MyItemInfo != null) // lib doc with no associated active procedure defaults to edit { StepTabPanel stpanel = _MyDisplayTabControl.GetProcedureTabPanel(MyDisplayTabItem.MyItemInfo); - PanelViewEditMode = (stpanel==null)? E_ViewMode.Edit : stpanel.MyStepPanel.PanelViewEditMode; + PanelViewEditMode = (stpanel == null) ? E_ViewMode.Edit : stpanel.MyStepPanel.VwMode; } try { diff --git a/PROMS/Volian.Controls.Library/EditItem.Designer.cs b/PROMS/Volian.Controls.Library/EditItem.Designer.cs new file mode 100644 index 00000000..4f44466c --- /dev/null +++ b/PROMS/Volian.Controls.Library/EditItem.Designer.cs @@ -0,0 +1,43 @@ +namespace Volian.Controls.Library +{ + partial class EditItem + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + protected bool _BeingDisposed = false; + + public bool BeingDisposed + { + get { return _BeingDisposed; } + set { _BeingDisposed = value; } + } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + _BeingDisposed = true; + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/PROMS/Volian.Controls.Library/EditItem.cs b/PROMS/Volian.Controls.Library/EditItem.cs new file mode 100644 index 00000000..2a3977ad --- /dev/null +++ b/PROMS/Volian.Controls.Library/EditItem.cs @@ -0,0 +1,2088 @@ +using System; +using System.ComponentModel; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using System.Drawing; +using System.Windows.Forms; +using System.Text.RegularExpressions; +using VEPROMS.CSLA.Library; +using Volian.Base.Library; + +namespace Volian.Controls.Library +{ + #region Enums + public enum ChildRelation : int + { + None = 0, + After = 1, + Before = 2, + RNO = 3 + } + public enum E_ChangeBarPosition : int + { + Left = 0, + Right = 1 + } + #endregion + public abstract partial class EditItem : UserControl + { + #region EditItemUnique + //private static int _EditItemUnique = 0; + //private static int EditItemUnique + //{ + // get + // { + // if (_EditItemUnique == 3) + // Console.WriteLine("here"); + // return ++_EditItemUnique; + // } + //} + //private int _MyEditItemUnique = EditItemUnique; + + //public int MyEditItemUnique + //{ + // get {return _MyEditItemUnique; } + //} + #endregion + #region Constructor + public EditItem() + { + InitializeComponent(); + } + + public EditItem(IContainer container) + { + container.Add(this); + InitializeComponent(); + } + #endregion + #region Properties + protected static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); + protected ChildRelation _MyChildRelation; + protected bool _Loading = true; + protected EditItem _MyParentEditItem = null; + protected EditItem _MySectionRTBItem; + protected EditItem _MyPreviousEditItem = null; + protected EditItem _MyNextEditItem = null; + private bool _ChildrenLoaded = false; + public bool HasChildren + { + get { return _MyBeforeEditItems != null || _MyRNOEditItems != null || _MyAfterEditItems != null; } + } + internal List _MyBeforeEditItems; + public List MyBeforeEditItems + { + get { return _MyBeforeEditItems; } + set { _MyBeforeEditItems = value; } + } + internal List _MyAfterEditItems; + public List MyAfterEditItems + { + get { return _MyAfterEditItems; } + set { _MyAfterEditItems = value; } + } + internal List _MyRNOEditItems; + public List MyRNOEditItems + { + get { return _MyRNOEditItems; } + set { _MyRNOEditItems = value; } + } + private StepSectionLayoutData _MyStepSectionLayoutData; + public StepSectionLayoutData MyStepSectionLayoutData + { + get { return _MyStepSectionLayoutData; } + set { _MyStepSectionLayoutData = value; } + } + private StepData _MyStepData; + public StepData MyStepData + { + get { return _MyStepData; } + set { _MyStepData = value; } + } + private ItemInfo _MyItemInfo; + private int _ExpandPrefix = 0; + public int ExpandPrefix + { + get { return _ExpandPrefix; } + set { _ExpandPrefix = value; } + } + private int _ExpandSuffix = 0; + public int ExpandSuffix + { + get { return _ExpandSuffix; } + set { _ExpandSuffix = value; } + } + private bool _Colapsing = false; + /// + /// Gets or sets colapsing + /// + public bool Colapsing + { + get { return _Colapsing; } + set { _Colapsing = value; } + } + private bool _Moving = false; + private int _RNOLevel = 0; + private int _SeqLevel = 0; + private int _ContentType; + public int ContentType + { + get { return _ContentType; } + set { _ContentType = value; } + } + private bool _Circle = false; + private bool _CheckOff = false; + private bool _ChangeBar = false; + private StepPanel _MyStepPanel; + public StepPanel MyStepPanel + { + get { return _MyStepPanel; } + set { _MyStepPanel = value; } + } + /// + /// This returns the section or procedure for the current item. + /// If the item is a step or section, it returns the section + /// If it is a procedure, it returns the procedure + /// + public EditItem MySectionRTBItem + { + get + { + if (_MySectionRTBItem == null) + { + if (MyItemInfo.IsSection || MyItemInfo.IsProcedure) _MySectionRTBItem = (RTBItem)this; + else _MySectionRTBItem = _MyParentEditItem.MySectionRTBItem; + } + return _MySectionRTBItem; + } + set { _MySectionRTBItem = value; } + } + /// + /// Gets or Sets ItemInfo + /// + public ItemInfo MyItemInfo + { + get { return _MyItemInfo; } + set + { + _MyItemInfo = value; + if (VlnSettings.StepTypeToolType) SetToolTip(_MyItemInfo.ToolTip); + ChangeBar = _MyItemInfo.HasChangeBar; + // Deal with changes in content data + value.MyContent.Changed += new ContentInfoEvent(MyContent_Changed); + // Deal with change in item data + value.Changed += new ItemInfoEvent(value_Changed); + value.OrdinalChanged += new ItemInfoEvent(value_OrdinalChanged); + } + } + void value_Changed(object sender) + { + ChangeBar = _MyItemInfo.HasChangeBar; + } + protected void MyContent_Changed(object sender) + { + // Update the text to reflect the content change + MyItemInfo.RefreshItemAnnotations(); + RefreshContent(); + } + void value_OrdinalChanged(object sender) + { + RefreshOrdinal(); + } + public EditItem ActiveParent + { + get { return _MyParentEditItem != null ? _MyParentEditItem : _MyPreviousEditItem.ActiveParent; } + } + /// + /// Return the Parent EditItem + /// + private EditItem UpOneEditItem + { + get + { + EditItem tmp = this; + while (tmp != null && tmp.MyParentEditItem == null) tmp = tmp.MyPreviousEditItem; + if (tmp != null) return tmp.MyParentEditItem; + return null; + } + } + private Stack _LastMethods = new Stack(); + //private string _LastMethod = ""; + internal void LastMethodsPush(string str) + { + MyStepPanel._LastAdjust = str; + _LastMethods.Push(str); + } + internal string LastMethodsPop() + { + //MyStepPanel._LastAdjust = ""; + return _LastMethods.Pop(); + } + internal bool LastMethodsEmpty + { + get { return _LastMethods.Count == 0; } + } + /// + /// This should find the item that precedes the current item vertically + /// and then return the Bottom of that item. + /// + /// + internal int FindTop(int bottom) + { + int lastBottomPrev = bottom; // This is necessary if the value of bottom can be negative. + if (_MyPreviousEditItem != null) + lastBottomPrev = _MyPreviousEditItem.BottomMostEditItem.Bottom; + int? bottomRNO = BottomOfParentRNO(); + if (lastBottomPrev > bottom) bottom = (int)(lastBottomPrev); // RHM 20090615 ES02 Step8 + // Moving from Step 8 to the Note preceeding step 8 caused the step 9 to be positioned in the wrong place. + //if (lastBottomParent > bottom) bottom = lastBottomParent; + //if (bottomRNO == null) return bottom; + return (int)max(bottomRNO, bottom); + } + /// + /// The Top of the EditItem + /// + public int ItemTop + { + get { return Top; } + set + { + MyStepPanel.ItemMoving++; + Top = value; + MyStepPanel.ItemMoving--; + } + } + private E_ChangeBarPosition _ChangeBarPosition = E_ChangeBarPosition.Right; + public E_ChangeBarPosition ChangeBarPosition + { + get { return _ChangeBarPosition; } + set { _ChangeBarPosition = value; } + } + /// + /// Sets the next item and adjusts the location, + /// This also sets the previous for the "next" item + /// which adjusts other locations. + /// + public EditItem MyNextEditItem + { + get { return _MyNextEditItem; } + set + { + _MyNextEditItem = value; + if (_MyNextEditItem != null) + { + if (_MyNextEditItem.MyPreviousEditItem != this) + { + _MyNextEditItem.MyPreviousEditItem = this; + MyNextEditItem.Location = new Point(Left, Bottom); + } + } + } + } + /// + /// returns the TopMostChild + /// + public EditItem TopMostEditItem + { + get + { + if (Expanded && _MyBeforeEditItems != null) return _MyBeforeEditItems[0].TopMostEditItem; + return this; + } + } + /// + /// Returns the bottom location (Top + Height) + /// + public new int Bottom + { + get + { + return Top + (Hidden ? 0 : Height); + } + } + private bool _Hidden = false; + public bool Hidden + { + get { return _Hidden; } + set { _Hidden = value; Visible = !value; } + } + /// + /// Bottom most child + /// + public EditItem BottomMostEditItem + { + get + { + EditItem tmpr = null; // BottomMost RNO + //int rnoOffset = 0; + if ((MyExpandingStatus != ExpandingStatus.No || Expanded) && _MyRNOEditItems != null) + { + //rnoOffset = this.Top - _MyRNOEditItems[0].Top; + tmpr = _MyRNOEditItems[_MyRNOEditItems.Count - 1].BottomMostEditItem; + } + EditItem tmpa = this; // BottomMost After + if ((MyExpandingStatus != ExpandingStatus.No || Expanded) & _MyAfterEditItems != null) + tmpa = _MyAfterEditItems[_MyAfterEditItems.Count - 1].BottomMostEditItem; + // return the bottom most of the two results + if (tmpr == null) + return tmpa; + //if (rnoOffset > 0) + //Console.WriteLine("RNO Bottom Offset {0}", rnoOffset); + //if (tmpa.Bottom >= (tmpr.Bottom + rnoOffset)) + if (tmpa.Bottom >= (tmpr.Bottom)) + return tmpa; + return tmpr; + } + } + /// + /// Bottom most child excluding RNOs + /// + public EditItem BottomMostEditItemNoRNOs + { + get + { + EditItem tmpa = this; // BottomMost After + if ((MyExpandingStatus != ExpandingStatus.No || Expanded) & _MyAfterEditItems != null) + tmpa = _MyAfterEditItems[_MyAfterEditItems.Count - 1].BottomMostEditItem; + // return the bottom most + return tmpa; + } + } + /// + /// First sibling + /// + private EditItem FirstSiblingEditItem + { + get + { + EditItem tmp = this; + while (tmp.MyPreviousEditItem != null) + tmp = tmp.MyPreviousEditItem; + return tmp; + } + } + /// + /// Last sibling + /// + private EditItem LastSiblingEditItem + { + get + { + EditItem tmp = this; + while (tmp.MyNextEditItem != null) + tmp = tmp.MyNextEditItem; + return tmp; + } + } + private ExpandingStatus _MyExpandingStatus = ExpandingStatus.No; + /// + /// Sets or Gets expanding status + /// + public ExpandingStatus MyExpandingStatus + { + get { return _MyExpandingStatus; } + set { _MyExpandingStatus = value; } + } + /// + /// Gets the ItemID from the ItemInfo + /// + public int MyID + { + get { return _MyItemInfo == null ? 0 : _MyItemInfo.ItemID; } + } + /// + /// Tracks when a EditItem is moving + /// + public bool Moving + { + get { return _Moving; } + set { _Moving = value; } + } + /// + /// The RNO (Contingency) Level + /// + public int RNOLevel + { + get { return _RNOLevel; } + set { _RNOLevel = value; } + } + /// + /// Sequential Level - Only counts levels of Sequential substeps + /// + public int SeqLevel + { + get { return _SeqLevel; } + set { _SeqLevel = value; } + } + // TODO: This should be changed to get the Circle format from the data + /// + /// Show a circle or not + /// + public bool Circle + { + get { return _Circle; } + set { _Circle = value; } + } + // TODO: This should be changed to get the Checkoff status from the data + /// + /// Has a check-off or not + /// + public bool CheckOff + { + get { return _CheckOff; } + set { _CheckOff = value; } + } + // TODO: This should be changed to get the ChangeBar status from the data + /// + /// Has a changebar or not + /// + public bool ChangeBar + { + get { return _ChangeBar; } + set + { + _ChangeBar = value; + this.Invalidate(); + } + } + #endregion // Properties + #region AddItem + /// + /// Adds an item to a list + /// + /// Parent Container + /// EditItem List + public void AddItem(EditItem parentEditItem, ref List siblingEditItems, EditItem nextEditItem) + { + if (siblingEditItems == null) // Create a list of siblings + { + siblingEditItems = new List(); + siblingEditItems.Add(this); + MyParentEditItem = parentEditItem; + } + else // Add to the existing list + { + if (nextEditItem == null) // Add to the end of the list + { + EditItem lastChild = LastChild(siblingEditItems); + siblingEditItems.Add(this); + MyPreviousEditItem = lastChild; + } + else // Add to the middle of the list before a particular item + { + EditItem prevChild = nextEditItem.MyPreviousEditItem; + EditItem parent = nextEditItem.MyParentEditItem; + siblingEditItems.Insert(siblingEditItems.IndexOf(nextEditItem), this); + MyStepPanel.ItemMoving++; + _MyNextEditItem = nextEditItem; + nextEditItem._MyPreviousEditItem = this; + MyPreviousEditItem = prevChild;// If a previous exists - this will adjust the location and width of the EditItem + nextEditItem.MyParentEditItem = null; + MyParentEditItem = parent; // If a parent exists - this will adjust the location and width of the EditItem + //nextEditItem.MyPreviousEditItem = this; + MyStepPanel.ItemMoving--; + } + } + if (MyItemInfo.IsCaution || MyItemInfo.IsNote) + { + EditItem prev = this; + while (prev.MyPreviousEditItem != null) prev = prev.MyPreviousEditItem; + prev.SetAllTabs(); + } + else + SetAllTabs(); + } + // clear tabs, clears then all so that next 'get' will calculate new. + public void SetAllTabs() + { + RefreshTab(); + + if (_MyAfterEditItems != null) foreach (EditItem chld in _MyAfterEditItems) chld.SetAllTabs(); + if (_MyNextEditItem != null) _MyNextEditItem.SetAllTabs(); + // Update the RNO tab if it exists - RHM 20100106 + if (_MyRNOEditItems != null) foreach (EditItem chld in _MyRNOEditItems) chld.SetAllTabs(); + } + /// + /// Add the next item to a list + /// + /// + /// + /// + //public EditItem AddNext(ItemInfo myItemInfo, bool expand) + //{ + // EditItem tmp = new EditItem(myItemInfo, MyStepPanel, MyParentEditItem, ChildRelation.None, expand); + // MyNextEditItem = tmp; + // return tmp; + //} + #endregion + #region RemoveItem + protected void ShowTops(string title) + { + int TopMostY = TopMostEditItem.Top; + int? TopMostParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.TopMostEditItem.Top)); + int? ParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.Top)); + //Console.Write("{0}: TopMostY={1}, TopMostParentY={2}, ParentY = {3}",title, TopMostY, TopMostParentY, ParentY); + Console.Write("{0}{1},{2},{3}", title, TopMostY, TopMostParentY.ToString() ?? "null", ParentY.ToString() ?? "null"); + } + private bool _BeingRemoved = false; + public bool BeingRemoved + { + get { return _BeingRemoved; } + set { _BeingRemoved = value; } + } + public void RemoveItem() + { + BeingRemoved = true; + MyStepPanel.SelectedEditItem = null; // Unselect the item to be deleted + //ShowTops("\r\n"); + int TopMostYBefore = TopMostEditItem.Top; + EditItem newFocus = DeleteItem(); + if (newFocus == null) return; + newFocus.SetFocus(); + Dispose(); + newFocus.SetAllTabs(); + int TopMostYAfter = newFocus.TopMostEditItem.Top; + if (TopMostYAfter > TopMostYBefore) + newFocus.TopMostEditItem.Top = TopMostYBefore; + newFocus.AdjustLocation(); + //newFocus.ShowTops(""); + } + public EditItem DeleteItem() + { + EditItem newFocus = null; + int? TopMostParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.TopMostEditItem.Top)); + int? ParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.Top)); + try + { + Item.DeleteItemAndChildren(MyItemInfo); + } + catch (System.Data.SqlClient.SqlException ex) + { + HandleSqlExceptionOnDelete(ex); + return null; + } + // Remove EditItems + RemoveFromParentsChildList(); + if (MyNextEditItem != null) + { + if (MyPreviousEditItem != null) + { + MyNextEditItem.MyPreviousEditItem = MyPreviousEditItem; + MyPreviousEditItem = null; + newFocus = MyNextEditItem; + } + else + { + MyNextEditItem.MyParentEditItem = MyParentEditItem; + MyParentEditItem = null; + MyNextEditItem.MyPreviousEditItem = null; + newFocus = MyNextEditItem; + } + // Adjust the vertical locations of all of the items below the item deleted + MyNextEditItem.TopMostEditItem.AdjustLocation(); + MyNextEditItem = null; + } + else if (MyPreviousEditItem != null) + { + MyPreviousEditItem.MyNextEditItem = null; + newFocus = MyPreviousEditItem; + MyPreviousEditItem = null; + //Console.Write(",\"Previous\","); + } + else + { + newFocus = MyParentEditItem; + MyParentEditItem = null; + //Console.Write(",\"Parent\","); + } + return newFocus; + } + + private void HandleSqlExceptionOnDelete(System.Data.SqlClient.SqlException ex) + { + if (ex.Message.Contains("has External Transitions and has no next step")) + { + using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitions(MyID)) + { + DialogResult ans = MessageBox.Show("Transitions exist to this step and cannot be adjusted automatically." + + "\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" + + "\r\n\r\nSubsteps with Problem Transitions" + + exTrans.Summarize(), + "Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (ans == DialogResult.Yes) + { + MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(exTrans[0].MyContent.ContentItems[0]); + + } + else + SetFocus(); + } + } + else if (ex.Message.Contains("has External Transitions to it's children")) + { + using (TransitionInfoList exTrans = TransitionInfoList.GetExternalTransitionsToChildren(MyID)) + { + DialogResult ans = MessageBox.Show("Transitions exist to substeps of this step and cannot be adjusted automatically." + + "\r\n\r\nDo you want to be placed on the " + (exTrans.Count > 1 ? "first " : "") + "substep with the problem Transition?" + + "\r\n\r\nSubsteps with Problem Transitions:" + + exTrans.Summarize(), + "Cannot Delete This Step", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (ans == DialogResult.Yes) + { + MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(exTrans[0].MyContent.ContentItems[0]); + } + } + } + else + MessageBox.Show(ex.Message, "SQL Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + private void RemoveFromParentsChildList() + { + EditItem top = this; + while (top.MyPreviousEditItem != null) top = top.MyPreviousEditItem; + EditItem parentEditItem = top.MyParentEditItem; + if (parentEditItem == null) return; // No parent, nothing to remove. + if (parentEditItem.MyAfterEditItems != null && parentEditItem.MyAfterEditItems.Contains(this)) + { + parentEditItem.MyAfterEditItems.Remove(this); + if (parentEditItem.MyAfterEditItems.Count == 0) + parentEditItem.MyAfterEditItems = null; + } + else if (parentEditItem.MyBeforeEditItems != null && parentEditItem.MyBeforeEditItems.Contains(this)) + { + parentEditItem.MyBeforeEditItems.Remove(this); + if (parentEditItem.MyBeforeEditItems.Count == 0) + parentEditItem.MyBeforeEditItems = null; + } + else if (parentEditItem.MyRNOEditItems != null && parentEditItem.MyRNOEditItems.Contains(this)) + { + parentEditItem.MyRNOEditItems.Remove(this); + if (parentEditItem.MyRNOEditItems.Count == 0) + parentEditItem.MyRNOEditItems = null; + } + if (parentEditItem.MyAfterEditItems == null && parentEditItem.MyBeforeEditItems == null && parentEditItem.MyRNOEditItems == null) + parentEditItem.CanExpand = false; + } + //private void ShowSiblings(string title) + //{ + // Console.WriteLine("---{0} {1}---",title,MyID); + // EditItem top = this; + // while (top.MyPreviousEditItem != null) top = top.MyPreviousEditItem; + // do + // { + // Console.WriteLine("{0} EditItem - {1} {2}", top.MyID == MyID ? "*" : " ", top.MyID, top.MyItemInfo.MyContent.Text); + // top = top.MyNextEditItem; + // } while (top != null); + //} + #endregion + #region Add Children + /// + /// Add a child before (Notes, Cautions, etc.) + /// + /// + /// + public void AddChildBefore(ItemInfo myItemInfo, bool expand) + { + EditItem child = new RTBItem(myItemInfo, MyStepPanel, this, ChildRelation.Before, expand); + } + /// + /// Add a list of children before + /// + /// + /// + public void AddChildBefore(ItemInfoList myItemInfoList, bool expand) + { + if (myItemInfoList != null) + foreach (ItemInfo item in myItemInfoList) + AddChildBefore(item, expand); + } + /// + /// Add an RNO (Contingency) child + /// + /// + /// + public void AddChildRNO(ItemInfo myItemInfo, bool expand) + { + EditItem child = new RTBItem(myItemInfo, MyStepPanel, this, ChildRelation.RNO, expand); + } + /// + /// Add a list of RNO (Contingency) children + /// + /// + /// + public void AddChildRNO(ItemInfoList myItemInfoList, bool expand) + { + if (myItemInfoList != null) + foreach (ItemInfo item in myItemInfoList) + AddChildRNO(item, expand); + } + /// + /// Add a child after + /// + /// + /// + public EditItem AddChildAfter(ItemInfo MyItemInfo, bool expand) + { + EditItem child = null; + if (MyItemInfo.MyContent.ContentGridCount != 0) + child = new GridItem(MyItemInfo, MyStepPanel, this, ChildRelation.After, expand); + else + child = new RTBItem(MyItemInfo, MyStepPanel, this, ChildRelation.After, expand); + return child; + } + public EditItem AddChildAfter(ItemInfo MyItemInfo, EditItem nextEditItem) + { + EditItem child = null; + if (MyItemInfo.MyContent.ContentGridCount != 0) + child = new GridItem(MyItemInfo, MyStepPanel, this, ChildRelation.After, true, nextEditItem); + else + child = new RTBItem(MyItemInfo, MyStepPanel, this, ChildRelation.After, true, nextEditItem); + return child; + } + public EditItem AddChildBefore(ItemInfo MyItemInfo, EditItem nextEditItem) + { + EditItem child = null; + if (MyItemInfo.MyContent.ContentGridCount != 0) + child = new GridItem(MyItemInfo, MyStepPanel, this, ChildRelation.Before, true, nextEditItem); + else + child = new RTBItem(MyItemInfo, MyStepPanel, this, ChildRelation.Before, true, nextEditItem); + return child; + } + public EditItem AddChildRNO(ItemInfo MyItemInfo, EditItem nextEditItem) + { + // not sure about this, i.e. whether a grid can be added here. + EditItem child = null; + if (MyItemInfo.MyContent.ContentGridCount != 0) + child = new GridItem(MyItemInfo, MyStepPanel, this, ChildRelation.RNO, true, nextEditItem); + else + child = new RTBItem(MyItemInfo, MyStepPanel, this, ChildRelation.RNO, true, nextEditItem); + return child; + } + /// + /// Adds a sibling after the current EditItem + /// + public void AddSiblingAfter() + { + AddSiblingAfter("", true); + } + public void AddSiblingAfter(string text, bool updateStatus) + { + SaveContents(); + ItemInfo newItemInfo = MyItemInfo.InsertSiblingAfter(text); + DoAddSiblingAfter(newItemInfo, updateStatus); + } + public void AddSiblingAfter(int? type, bool updateStatus) + { + SaveContents(); + ItemInfo newItemInfo = MyItemInfo.InsertSiblingAfter("", "", type); + DoAddSiblingAfter(newItemInfo, updateStatus); + } + private void DoAddSiblingAfter(ItemInfo newItemInfo, bool updateStatus) + { + EditItem newEditItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newEditItem = ActiveParent.AddChildAfter(newItemInfo, MyNextEditItem); + break; + case ChildRelation.Before: + newEditItem = ActiveParent.AddChildBefore(newItemInfo, MyNextEditItem); + break; + case ChildRelation.RNO: + newEditItem = ActiveParent.AddChildRNO(newItemInfo, MyNextEditItem); + break; + default: // Need debug + break; + } + //EditItem newEditItem = ActiveParent.AddChildAfter(newItemInfo, ); + if (updateStatus) + MyStepPanel.SelectedEditItem = newEditItem;//Update Screen + } + protected static int _WatchThis = 1; + public void AddSiblingBefore() + { + AddSiblingBefore("", true); + } + public void AddSiblingBefore(string text, bool updateSelection) + { + // Save RTB text before creating a new item because the process of creating + // a new item will save a change to iteminfo excluding text changes. This + // shouldn't be necessary for adding sibling after because the current step + // doesn't get saved during the insert after because of the MyPrevious field + // is only set on an insert before, which is what saves the item without + // any updates from the richtextbox text. + SaveContents(); + ItemInfo newItemInfo = MyItemInfo.InsertSiblingBefore(text); + EditItem newEditItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newEditItem = ActiveParent.AddChildAfter(newItemInfo, this); + break; + case ChildRelation.Before: + newEditItem = ActiveParent.AddChildBefore(newItemInfo, this); + break; + case ChildRelation.RNO: + newEditItem = ActiveParent.AddChildRNO(newItemInfo, this); + break; + default: // Need debug + break; + } + if (updateSelection) + MyStepPanel.SelectedEditItem = newEditItem;//Update Screen + } + public void AddChild(E_FromType fromType, int type) + { + AddChild("", fromType, type); + } + public void AddChild(string text, E_FromType fromType, int type) + { + if (_MyItemInfo.IsHigh || _MyItemInfo.IsSection) + CanExpand = true; + this.Expanded = true; + _WatchThis = 1; + ItemInfo newItemInfo = MyItemInfo.InsertChild(fromType, type, text); + // TODO: We need to determine where this will go in the stack of children + EditItem nextItem = null; + if (newItemInfo.NextItem != null) + nextItem = MyStepPanel.FindItem(newItemInfo.NextItem); + else if (fromType == E_FromType.Table && MyAfterEditItems != null) + nextItem = MyAfterEditItems[0]; + // Cautions come before notes, so if this is a Caution and there are Notes, put this first + else if (fromType == E_FromType.Caution && ((ItemInfo)newItemInfo.ActiveParent).Notes != null + && ((ItemInfo)newItemInfo.ActiveParent).Notes.Count > 0) + nextItem = MyStepPanel.FindItem(((ItemInfo)newItemInfo.ActiveParent).Notes[0]); + // TODO: May need similar logic if a Table is being added to a step that has substeps + // else if (fromType == E_FromType.Table && ((ItemInfo)newItemInfo.ActiveParent).Steps != null + //&& ((ItemInfo)newItemInfo.ActiveParent).Steps.Count > 0) + // nextItem = MyStepPanel.FindItem(((ItemInfo)newItemInfo.ActiveParent).Steps[0]); + EditItem newEditItem; + switch (fromType) + { + case E_FromType.Caution: + newEditItem = this.AddChildBefore(newItemInfo, nextItem); + break; + case E_FromType.Note: + newEditItem = this.AddChildBefore(newItemInfo, nextItem); + break; + case E_FromType.Procedure: + newEditItem = this.AddChildAfter(newItemInfo, nextItem); + break; + case E_FromType.RNO: + newEditItem = this.AddChildRNO(newItemInfo, nextItem); + break; + case E_FromType.Section: + newEditItem = this.AddChildAfter(newItemInfo, nextItem); + break; + case E_FromType.Step: + newEditItem = this.AddChildAfter(newItemInfo, nextItem); + break; + case E_FromType.Table: + newEditItem = this.AddChildAfter(newItemInfo, nextItem); + break; + default: + newEditItem = this.AddChildAfter(newItemInfo, nextItem); + break; + } + MyStepPanel.SelectedEditItem = newEditItem;//Update Screen + } + /// + /// Add a list of children after + /// + /// + /// + public EditItem AddChildAfter(ItemInfoList myItemInfoList, bool expand) + { + EditItem child = null; + if (myItemInfoList != null) + foreach (ItemInfo item in myItemInfoList) + child = AddChildAfter(item, expand); + return child; + } + #endregion + #region CopyPaste + public void PasteSiblingBefore(int copyStartID) + { + ItemInfo newItemInfo = MyItemInfo.PasteSiblingBefore(copyStartID); + EditItem newEditItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newEditItem = ActiveParent.AddChildAfter(newItemInfo, this); + break; + case ChildRelation.Before: + newEditItem = ActiveParent.AddChildBefore(newItemInfo, this); + break; + case ChildRelation.RNO: + newEditItem = ActiveParent.AddChildRNO(newItemInfo, this); + break; + default: // Need debug + break; + } + if (newEditItem != null) MyStepPanel.SelectedEditItem = newEditItem;//Update Screen + MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Before, newItemInfo.MyContent.Type)); + + } + public void PasteSiblingAfter(int copyStartID) + { + ItemInfo newItemInfo = MyItemInfo.PasteSiblingAfter(copyStartID); + EditItem newEditItem = null; + switch (_MyChildRelation) + { + case ChildRelation.After: + newEditItem = ActiveParent.AddChildAfter(newItemInfo, MyNextEditItem); + break; + case ChildRelation.Before: + newEditItem = ActiveParent.AddChildBefore(newItemInfo, MyNextEditItem); + break; + case ChildRelation.RNO: + newEditItem = ActiveParent.AddChildRNO(newItemInfo, MyNextEditItem); + break; + default: // Need debug + break; + } + MyStepPanel.SelectedEditItem = newEditItem;//Update Screen + MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.After, newItemInfo.MyContent.Type)); + + } + public EditItem PasteReplace(int copyStartID) + { + // To allow a Paste Step into an empty (new) step/substep, we need to add a character to the the Text field + // to simulate replacing an existing step - otherwise we will get null references. + if (MyStepPanel.SelectedEditItem.Empty) + MyStepPanel.SelectedEditItem.Empty=false; + MyStepPanel.SelectedEditItem = null; // Unselect the item to be deleted + ChildRelation childRelation = _MyChildRelation; + EditItem newFocus = null; + EditItem nextEditItem = MyNextEditItem; + EditItem prevEditItem = MyPreviousEditItem; + EditItem parentEditItem = ActiveParent; + + int TopMostYBefore = TopMostEditItem.Top; + int? TopMostParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.TopMostEditItem.Top)); + int? ParentY = (MyParentEditItem == null ? null : (int?)(MyParentEditItem.Top)); + ItemInfo newItemInfo = null; + try + { + newItemInfo = Item.PasteReplace(MyItemInfo, copyStartID); + } + catch (System.Data.SqlClient.SqlException ex) + { + HandleSqlExceptionOnDelete(ex); + return this; + } + // Remove the EditItem that was the replaced item. + RemoveFromParentsChildList(); + + if (MyNextEditItem != null) + { + if (MyPreviousEditItem != null) + { + MyNextEditItem.MyPreviousEditItem = MyPreviousEditItem; + MyPreviousEditItem = null; + } + else + { + MyNextEditItem.MyParentEditItem = MyParentEditItem; + MyParentEditItem = null; + MyNextEditItem.MyPreviousEditItem = null; + } + MyNextEditItem = null; + } + else if (MyPreviousEditItem != null) + { + MyPreviousEditItem.MyNextEditItem = null; + newFocus = MyPreviousEditItem; + MyPreviousEditItem = null; + } + else + { + newFocus = MyParentEditItem; + MyParentEditItem = null; + } + + // add copied item to ui where the replaced item was. + EditItem newEditItem = null; + switch (childRelation) + { + case ChildRelation.After: + newEditItem = parentEditItem.AddChildAfter(newItemInfo, nextEditItem); + break; + case ChildRelation.Before: + newEditItem = parentEditItem.AddChildBefore(newItemInfo, nextEditItem); + break; + case ChildRelation.RNO: + newEditItem = parentEditItem.AddChildRNO(newItemInfo, nextEditItem); + break; + default: // Need debug + break; + } + MyStepPanel.SelectedEditItem = newEditItem; //Update Screen + MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Replace, newItemInfo.MyContent.Type)); + return newEditItem; + } + public void IdentifyChildren(bool highlight) + { + // Highlight children of EditItem: + if (MyAfterEditItems != null) + { + foreach (EditItem sia in MyAfterEditItems) + { + sia.IdentifyMe(highlight); + sia.IdentifyChildren(highlight); + } + } + if (MyBeforeEditItems != null) + { + foreach (EditItem sib in MyBeforeEditItems) + { + sib.IdentifyMe(highlight); + sib.IdentifyChildren(highlight); + } + } + if (MyRNOEditItems != null) + { + foreach (EditItem sir in MyRNOEditItems) + { + sir.IdentifyMe(highlight); + sir.IdentifyChildren(highlight); + } + } + } + #endregion + #region Event Handlers + private string WatchThisIndent + { + get { return "".PadLeft(_WatchThis, '\t'); } + } + protected bool RNOBelow + { + get + { + if (_MyRNOEditItems != null) + { + return _MyRNOEditItems[0].RNOLevel > _MyItemInfo.ColumnMode; + //return _MyRNOEditItems[0].Left == Left; + } + return false; + } + } + protected bool RNORight + { + get + { + if (_MyRNOEditItems != null) + { + return _MyRNOEditItems[0].RNOLevel <= _MyItemInfo.ColumnMode; + //return _MyRNOEditItems[0].Left != Left; + } + return false; + } + } + protected void MoveRNO() + { + if (_MyRNOEditItems != null) + { + if (_MyRNOEditItems[0].TopMostEditItem.Top != Top) + { + //if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\r\n'Adjust RNO',{0},'Move',{1}", MyID, _RNO[0].MyID); + EditItem rnoTop = _MyRNOEditItems[0].TopMostEditItem; + if (rnoTop.RNOLevel <= _MyItemInfo.ColumnMode) + { + //EditItem tmpBottom = this; + //if (_MyAfterEditItems != null) tmpBottom = _MyAfterEditItems[_MyAfterEditItems.Count - 1].BottomMostEditItem; + MyStepPanel.ItemMoving++; + rnoTop.LastMethodsPush(string.Format("EditItem_Move RNO Right {0}", rnoTop.MyID)); + //rnoTop.Top = tmpBottom.Bottom; + rnoTop.Top = Top; + rnoTop.LastMethodsPop(); + MyStepPanel.ItemMoving--; + } + else + { + MyStepPanel.ItemMoving++; + rnoTop.LastMethodsPush(string.Format("EditItem_Move RNO Below {0} {1} {2}", rnoTop.MyID, BottomMostEditItemNoRNOs.MyID, BottomMostEditItemNoRNOs.Bottom)); + rnoTop.Top = BottomMostEditItemNoRNOs.Bottom; + rnoTop.LastMethodsPop(); + MyStepPanel.ItemMoving--; + } + } + } + } + /// + /// Handles movement of the EditItems + /// + /// + /// + private void EditItem_Move(object sender, EventArgs e) + { + int watchThis = _WatchThis; + //if (MyID == _lookForID || MyID == 2111) + //{ + // //vlnStackTrace.ShowStack("{0} Move TO {1} - {2}, BottomMost {3}", MyID, Top, MyPath, BottomMostRTBItem.MyPath); + // Console.WriteLine("{0} Move TO {1} - {2}, BottomMost {3}", MyID, Top, MyPath, BottomMostRTBItem.MyPath); + //} + //if (MyID > _StartingID) + // Console.WriteLine("{0}--------------- {1} Top = {2} Bottom {3}", WatchThisIndent, MyID, Top, Bottom); + if (MyStepPanel.ItemMoving == 0) + { + //vlnStackTrace.ScrollInStack(); + return; // If 0 - Indicates scrolling which requires no action. + } + //ShowMe("Move"); + if (MyItemInfo == null) + return; + //if (_WatchThis > 0 && MyID > _StartingID) + //{ + + // Console.WriteLine("{0}Start Move {1},{2}", WatchThisIndent, MyID, this); + // if (MyID == _LookForID) + // Console.WriteLine("{0}---------------", WatchThisIndent,MyID, this); + // _WatchThis++; + //} + if (MyExpandingStatus == ExpandingStatus.Expanding) + { + _WatchThis = watchThis; + return; + } + Moving = true; + EditItem tmp = (EditItem)sender; + if (tmp.MyPreviousEditItem == null && tmp.MyParentEditItem == null) + { + _WatchThis = watchThis; + return; + } + if (RNOBelow) // Adjust substeps first + { + //Console.WriteLine("RNOBelow"); + AdjustLocation(); + MoveRNO(); + } + else // Adjust RNO First + { + if (RNORight) + { + //Console.WriteLine("RNORight"); + MoveRNO(); + } + AdjustLocation(); + } + Moving = false; + EditItem btm = BottomMostEditItem; + if (this != btm) + btm.AdjustLocation(); + //if (_WatchThis > 0 && MyID > _StartingID) + //{ + // Console.WriteLine("{0}Finish Move {1},{2}",WatchThisIndent, MyID, this); + //} + _WatchThis = watchThis; + } + /// + /// Adjust the locations when the EditItem is resized + /// + /// + /// + private void EditItem_Resize(object sender, EventArgs e) + { + if (MyItemInfo == null) return; + if (_IgnoreResize) return; + AdjustLocation(); + HandleResize(); + + } + #endregion // Event Handlers + #region Private and Protected Methods + /// + /// Calculates the table location + /// + /// + /// + /// + /// + protected Point TableLocation(EditItem myParentEditItem, StepSectionLayoutData myStepSectionLayoutData, int width) + { + // Should center on parent unless it is a centered table in the AER column + int center = myParentEditItem.ContentLeft + myParentEditItem.ContentWidth / 2; + int rightLimit = myParentEditItem.Right; + // Then should center on the wid Limit + if (MyItemInfo.FormatStepData.Type.Contains("AER") == false && MyItemInfo.RNOLevel == 0) + { + int colR = MyStepPanel.ToDisplay(MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode); + rightLimit += colR * MyItemInfo.ColumnMode; + center += (colR * MyItemInfo.ColumnMode) / 2; + center -= (myParentEditItem.ContentLeft - (int)MyItemInfo.MyDocStyle.Layout.LeftMargin) / 2; + } + + // Calulate the x location + //int x = myParentEditItem.TextLeft; + int x = center - width / 2; + if (x + width > rightLimit) x = rightLimit - width; + int colT = MyStepPanel.ToDisplay(myStepSectionLayoutData.ColT); + if (x < colT) x = colT; + int y = FindTop(myParentEditItem.Bottom); + return new Point(x, y); + } + protected void DoMouseWheel(MouseEventArgs e) + { + MyStepPanel.MouseWheel(e); + } + protected void InsertPgBrk() + { + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnInsPgBrk_Click(this, new EventArgs()); + } + protected void OpenAnnotations() + { + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnAnnots_Click(this, new EventArgs()); + } + protected bool CheckClipboard() + { + return (MyStepPanel.MyStepTabPanel.MyDisplayTabControl.MyCopyStep != null); + } + protected void CopyStep() + { + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.DoCopyStep(); + } + /// + /// Finds the last child in a list + /// + /// + /// + private static EditItem LastChild(List childEditItems) + { + return childEditItems[childEditItems.Count - 1]; + } + /// + /// If the selected EditItem is within the window leave it as it is. + /// If not, scroll so that the selected window is centered. + /// + protected void ScrollToCenter() + { + //vlnStackTrace.ShowStack("CenterScroll {0} Current {1} Top {2} Bottom {3} Limit {4}", _MyItem.ItemID, _Panel.VerticalScroll.Value, Top, Bottom, _Panel.Height);// Show StackTrace + //Console.WriteLine("CenterScroll {0} Current {1} Top {2} Bottom {3} Limit {4}", _MyItem.ItemID, _Panel.VerticalScroll.Value, Top, Bottom, _Panel.Height); + if (Top >= 0 && Bottom <= MyStepPanel.Height) return;// Don't move if within screen. + int scrollValue = MyStepPanel.VerticalScroll.Value + (Top - (MyStepPanel.Height / 2)); // calculate scroll center for the item + //Console.WriteLine("CenterScroll {0} Current {1} New {2} Min {3} Max {4}", _MyItem.ItemID, _Panel.VerticalScroll.Value, scrollValue, _Panel.VerticalScroll.Minimum, _Panel.VerticalScroll.Maximum); + if (scrollValue >= MyStepPanel.VerticalScroll.Minimum && scrollValue <= MyStepPanel.VerticalScroll.Maximum) // If it is within range + MyStepPanel.VerticalScroll.Value = scrollValue; // Center the item + } + + /// + /// Hide a Items Children - Part of colapsing + /// + protected void HideChildren() + { + HideChildren(_MyBeforeEditItems); + HideChildren(_MyRNOEditItems); + HideChildren(_MyAfterEditItems); + } + /// + /// Hide a list of children - Part of colapsing + /// + /// + private void HideChildren(List childEditItems) + { + if (childEditItems != null) + { + foreach (EditItem child in childEditItems) + { + if (child.Expanded) child.HideChildren(); + child.Hidden = true; + } + } + } + /// + /// Unhide an items Children - Part of expanding + /// + /// + protected void UnhideChildren(bool expand) + { + UnhideChildren(_MyBeforeEditItems, expand); + UnhideChildren(_MyRNOEditItems, expand); + UnhideChildren(_MyAfterEditItems, expand); + MatchExpanded(); + + } + /// + /// Unhide a list of children - part of expanding + /// + /// + /// + private void UnhideChildren(List childEditItems, bool expand) + { + if (childEditItems != null) + { + foreach (EditItem child in childEditItems) + { + if (child.Expanded) + child.UnhideChildren(expand); + else if (expand) + child.Expand(expand); + child.Hidden = false; + } + } + } + /// + /// Move children as necessary + /// + protected void AdjustChildren() + { + AdjustChildren(_MyBeforeEditItems); + AdjustChildren(_MyRNOEditItems); + AdjustChildren(_MyAfterEditItems); + } + /// + /// Move a list of children + /// + /// + private void AdjustChildren(List childEditItems) + { + if (childEditItems != null) + { + foreach (EditItem child in childEditItems) + { + child.AdjustLocation(); + if (child.Expanded) child.AdjustChildren(); + } + } + } + /// + /// Expand a list of children + /// + /// + private void ExpandChildren(List childEditItems) + { + if (childEditItems != null) + { + foreach (EditItem child in childEditItems) + { + if (child.CanExpand) + { + child.Expand(true); + } + child.Hidden = false; + } + } + } + /// + /// Expand children + /// + private void ExpandChildren() + { + // Walk though Children performing Expand + ExpandChildren(_MyBeforeEditItems); + ExpandChildren(_MyRNOEditItems); + ExpandChildren(_MyAfterEditItems); + } + private string MyPath + { + get + { + if (MyItemInfo.MyContent.Type >= 20000) + return MyItemInfo.Path.Substring(MyItemInfo.ActiveSection.Path.Length); + return MyItemInfo.MyContent.ToString(); + } + } + private EditItem AEREditItem + { + get + { + if (RNOLevel == 0) return null; + if (MyParentEditItem != null) + { + if (MyParentEditItem.RNOLevel < RNOLevel) + return MyParentEditItem; + else + return MyParentEditItem.AEREditItem; + } + else if (MyPreviousEditItem != null) + { + return MyPreviousEditItem.AEREditItem; + } + //Volian.Base.Library.vlnStackTrace.ShowStackLocal("'AEREditItem',{0},{1}", MyID, MyItemInfo.DBSequence); + return null; + } + } + /// + /// Adjust the Location of all items below the current item. + /// + internal void AdjustLocation() + { + //Console.WriteLine("'AdjustLocation',{0},{1},'{2}'", MyID, MyItemInfo.DBSequence, Volian.Base.Library.vlnStackTrace.CalledFrom4); + if (RNORight) MoveRNO(); // This is needed when an AER is Deleted that has an RNO. + if (RNOLevel > 0 && AEREditItem != null) + AEREditItem.AdjustLocation(); + EditItem nextEditItem = NextDownEditItem; + //if (MyID == 2138) + // Console.WriteLine("2138"); + //if (_WatchThis > 0 && MyID > _StartingID) + //if((nextEditItem == null ? 0 : nextEditItem.MyID) == MyID) + //if(_LookForID.Contains(MyID)) + // Console.WriteLine("{0}AdjustLocation {1},{2},{3} -> {4},{5} ({6}) {7}", WatchThisIndent, MyID, MyItemInfo.Ordinal, MyPath, + // nextEditItem == null ? 0 : nextEditItem.MyID, nextEditItem == null ? 0 : nextEditItem.MyItemInfo.Ordinal, nextEditItem == null ? "Null" : nextEditItem.MyPath, + // _NextDownEditItemPath); + //if (_WatchThis && MyID == 2119) + // Console.WriteLine("I'm here"); + //if (MyID > 2120) + // Console.WriteLine("{0}\t{1}", MyID, nextEditItem == null ? 0 : nextEditItem.MyID); + if (nextEditItem != null) + { + //int bottom = BottomMostEditItem.Bottom; + if (nextEditItem != null) + { + //if (MyID == 2123) + // _LookForID = 2123; + int bottom = nextEditItem.FindTop(Bottom); + if (nextEditItem.Top != bottom) + // if (nextEditItem != null && !nextEditItem.Moving && nextEditItem.Top != bottom) + { + MyStepPanel.ItemMoving++; + nextEditItem.LastMethodsPush(string.Format("AdjustLocation {0}", MyID)); + nextEditItem._NextDownEditItemPath = _NextDownEditItemPath; + nextEditItem.Top = bottom; + nextEditItem.LastMethodsPop(); + MyStepPanel.ItemMoving--; + } + } + else + { + Console.WriteLine("{0}** No Adjustment next = {1}, moving = {2}", WatchThisIndent, nextEditItem, nextEditItem == null ? false : nextEditItem.Moving); + } + } + } + /// + /// Automatically expands Steps if not currently expanded + /// + internal void AutoExpand() + { + if (CanExpand && Expanded == false)// TODO: May need to do some additional checking for subsections + { + //vlnStackTrace.ShowStack(">AutoExpand ID {0} - Can {1} Expanded {2}", _MyItem.ItemID, CanExpand, Expanded); + Expand(_ContentType >= 20000); + //Console.WriteLine(" + /// Expand an item and it's children + /// If the children have been loaded then just expand them + /// If not, load the children and expand their children etc. + /// + /// normally equal to _Type > = 20000 (Step) + public void Expand(bool expand) + { + //// TIMING: DisplayItem.TimeIt("Expand Start"); + if (_ChildrenLoaded) + { + // Unhide Children + MyExpandingStatus = ExpandingStatus.Showing; + UnhideChildren(expand); + if (ExpandPrefix != 0) + { + MyStepPanel.ItemMoving++; + TopMostEditItem.Top = Top; + MyStepPanel.ItemMoving--; + } + else + TopMostEditItem.AdjustLocation(); + AdjustChildren(); + //if(_Before != null ) + // Top = _Before[_Before.Count - 1].BottomMost.Bottom; + } + else + { + MyExpandingStatus = ExpandingStatus.Expanding; + _ChildrenLoaded = true; + //_Panel.SuspendLayout(); + AddChildBefore(MyItemInfo.Cautions, expand); + AddChildBefore(MyItemInfo.Notes, expand); + AddChildAfter(MyItemInfo.Procedures, expand); + AddChildAfter(MyItemInfo.Sections, expand); + if (MyItemInfo.RNOs != null && MyItemInfo.RNOLevel < MyItemInfo.ColumnMode) + AddChildRNO(MyItemInfo.RNOs, expand); + AddChildAfter(MyItemInfo.Tables, expand); + AddChildAfter(MyItemInfo.Steps, expand); + if (MyItemInfo.RNOs != null && MyItemInfo.RNOLevel >= MyItemInfo.ColumnMode) + AddChildRNO(MyItemInfo.RNOs, expand); + MatchExpanded(); + } + MyExpandingStatus = ExpandingStatus.Done; + BottomMostEditItem.AdjustLocation(); + MyExpandingStatus = ExpandingStatus.No; + //// TIMING: DisplayItem.TimeIt("Expand End"); + } + public EditItem BeforeItem + { + get + { + if (_MyAfterEditItems != null) + { + foreach (EditItem EditItem in _MyAfterEditItems) + { + if (EditItem._MyBeforeEditItems != null) + return EditItem.TopMostEditItem; + EditItem beforeItem = EditItem.BeforeItem; + if (beforeItem != null) return beforeItem; + } + } + return null; + } + } + public EditItem ItemAbove + { + get + { + if (_MyChildRelation == ChildRelation.Before) return _MyParentEditItem.ItemAbove; + if (_MyPreviousEditItem != null) return _MyPreviousEditItem.BottomMostEditItem; + if (_MyChildRelation == ChildRelation.After) return _MyParentEditItem; + if (_MyChildRelation == ChildRelation.RNO) return _MyParentEditItem; + return null; + } + } + private static int? max(int? value1, int value2) + { + if (value1 == null || value2 > value1) return value2; + return value1; + } + private static int min(int value1, int value2) + { + if (value2 < value1) return value2; + return value1; + } + public int FindRight() + { + if (!RNORight) return Right; + return _MyRNOEditItems[0].FindRight(); + } + public int? BottomOfParentRNO() + { + int? bottom = null; + EditItem EditItem = this; + if (!MyItemInfo.IsTablePart) + { + if (EditItem._MyChildRelation == ChildRelation.None) + return null; + if (EditItem._MyChildRelation == ChildRelation.After && !RNORight) + return null; + } + while (EditItem != null && EditItem._MyChildRelation != ChildRelation.None && EditItem._MyChildRelation != ChildRelation.After) + EditItem = EditItem.UpOneEditItem; + if (EditItem == null || EditItem._MyChildRelation == ChildRelation.None) + return null; + EditItem parent = EditItem.UpOneEditItem; + int right = FindRight(); + bool centeredTable = (MyItemInfo.IsTablePart && MyItemInfo.FormatStepData.Type.Contains("AER") == false && MyItemInfo.RNOLevel == 0); + while (parent != null && parent.MyItemInfo.IsSection == false) + { + if (parent._MyRNOEditItems != null) + { + if (centeredTable || right > parent._MyRNOEditItems[0].Left) + { + if (parent._MyRNOEditItems[0].BottomMostEditItem.RNOLevel > RNOLevel && RNOLevel < _MyItemInfo.ColumnMode) + bottom = max(bottom, parent._MyRNOEditItems[0].BottomMostEditItem.Bottom); + } + } + parent = parent.UpOneEditItem; + } + return bottom; + } + private string _NextDownEditItemPath = "None"; + /// + /// This finds the next EditItem down. + /// + public EditItem NextDownEditItem + { + get + { + EditItem EditItem = this; + _NextDownEditItemPath = "Path 1"; + // If this item appears before it's parent, and it doesn't have anything below it, return the parent + if (MyNextEditItem == null && MyAfterEditItems == null && FirstSiblingEditItem._MyChildRelation == ChildRelation.Before) + return UpOneEditItem; + _NextDownEditItemPath = "Path 2"; + if (Expanded && _MyAfterEditItems != null)// check to see if there is a _After + return MyAfterEditItems[0].TopMostEditItem;// if there is, go that way + _NextDownEditItemPath = "Path 3"; + if (Expanded && MyRNOEditItems != null && MyItemInfo.RNOLevel >= MyItemInfo.ColumnMode)// check to see if there is a _After + return MyRNOEditItems[0].TopMostEditItem;// if there is, go that way + while (EditItem != null && EditItem.MyNextEditItem == null) // if no Next walk up the parent path + { + bool lastWasRNO = (EditItem._MyChildRelation == ChildRelation.RNO); + EditItem = EditItem.UpOneEditItem; + _NextDownEditItemPath = "Path 4"; + if (EditItem == null) // No Parent + return null; + _NextDownEditItemPath = string.Format("Path 5 {0}, {1}", EditItem.MyExpandingStatus, EditItem.Moving); + if (EditItem.MyExpandingStatus == ExpandingStatus.Expanding || EditItem.Moving) // Parent Expanding or Moving - Wait + return null; + _NextDownEditItemPath = "Path 5 RNO"; + if (EditItem.RNOBelow && !Ancestor(EditItem.MyRNOEditItems[0])) + return EditItem.MyRNOEditItems[0]; + _NextDownEditItemPath = "Path 6"; + if (EditItem.MyNextEditItem == null && EditItem.FirstSiblingEditItem._MyChildRelation == ChildRelation.Before) + return EditItem.UpOneEditItem; + EditItem btm = EditItem.BottomMostEditItem; // Find the Bottom EditItem of this ancestor + EditItem beforeItem = EditItem.BeforeItem; + if (lastWasRNO && beforeItem != null) + { + _NextDownEditItemPath = "Path 7"; + if (beforeItem.ItemAbove.Bottom > this.Bottom) return null; + _NextDownEditItemPath = "Path 8"; + return beforeItem; + } + if (this != btm) // If this is not the bottom, then just adjust things with respect to the bottom + { + EditItem btmNext = btm.NextDownEditItem; + //if (EditItem.MyNextEditItem != null && EditItem.MyNextEditItem.TopMostEditItem.Top != btm.Bottom) + if (btmNext != null) + { + int bottom = btmNext.FindTop(btm.Bottom); + if (btmNext.Top != bottom) + { + MyStepPanel.ItemMoving++; + //EditItem.MyNextEditItem.TopMostEditItem.Top = btm.Bottom; + //Console.WriteLine("{0}***Move in NextDownEditItem {1},{2} From {3} To {4}",WatchThisIndent, btmNext.MyID, btmNext, btmNext.Top, btm.Bottom); + btmNext.LastMethodsPush(string.Format("NextDownEditItem {0} {1}", MyID, EditItem.MyID)); + //ShowMe(string.Format("FindTop = {0}", btmNext.FindTop(btm.Bottom))); + btmNext.Top = bottom; + btmNext.LastMethodsPop(); + MyStepPanel.ItemMoving--; + } + } + _NextDownEditItemPath = string.Format("Path 9 {0}", btm); + return null; // Not the bottom - don't adjust anything else + } + //else + //{ + //} + } + if (EditItem != null) + { + // Need to verify that the bottom of the parents RNO does not excede the bottom of this item. + EditItem next = EditItem.MyNextEditItem.TopMostEditItem; + _NextDownEditItemPath = "Path A"; + //if (Bottom >= (BottomOfParentRNO(next) ?? Bottom)) + return next;// if no _After - check to see if there is a Next + //_NextDownEditItemPath = "Path B"; + //return null; + } + _NextDownEditItemPath = "Path C"; + return null; + } + } + + private bool Ancestor(EditItem EditItem) + { + if (MyID == EditItem.MyID) return true; + if (MyItemInfo.IsHigh) return false; + return UpOneEditItem.Ancestor(EditItem); + } + public override string ToString() + { + return _MyItemInfo == null ? base.ToString() : string.Format("{0},'{1}'", MyID, MyPath); // + "-" + MyItemInfo.MyContent.Text; + } + #endregion + #region Abstract Methods and Properties + public abstract int TableWidth { get; } + public abstract int BorderWidth { get; } + public abstract Point ContentLocation { get; set; } + public abstract string TabFormat { get; set; } + public abstract void AdjustTableWidthAndLocation(); + public abstract void SetToolTip(string tip); + public abstract void RefreshContent(); + //public abstract EditItem MyPreviousEditItem { get; set; } + public abstract int ItemLeft { get; set; } + public abstract int ContentLeft { get; } + public abstract int ContentWidth { get; set; } + public abstract Point ItemLocation { get; set; } + public abstract int ItemWidth { get; set; } + public abstract void RefreshOrdinal(); + public abstract bool Expanded { get; set; } + public abstract void RefreshTab(); + public abstract void SetFocus(); + public abstract void SaveContents(); + public abstract bool CanExpand { get; set; } + public abstract void HandleResize(); + public abstract void MatchExpanded(); + public abstract void ItemSelect(); + public abstract void ItemShow(); + public abstract StepRTB MyStepRTB { get; } + public abstract DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg); + public abstract bool FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse); + public abstract void PositionToEnd(); + public abstract string SelectedTextForFind { get;} + public abstract bool SpellCheckNext(); + public abstract void IdentifyMe(bool highlight); + public abstract void SetActive(); + public abstract bool Empty { get; set; } + //public abstract bool IsEmpty(); + //public abstract void MakeNotEmpty(); + public abstract void RefreshDisplay(bool activeMode); + public abstract void ToggleEditView(E_ViewMode vwMode); + public abstract int TabLeft { get; set; } + public abstract Font TabFont { get; set; } + public abstract string TabText { get; } + public abstract Point TabLocation { get; } + public abstract Font ContentFont { get; set; } + public abstract float ContentTop { get; } + public abstract void SetupHeader(ItemInfo itemInfo); + public abstract void ShowExpanded(); + public abstract void SetText(); + public abstract void SetExpandAndExpander(ItemInfo itemInfo); + #endregion + protected string _TabFormat; + private static int _WidthAdjust = 3; + protected bool _IgnoreResize = false; + /// + /// Sets the parent and postions the item with respect to the parent + /// + public EditItem MyParentEditItem + { + get { return _MyParentEditItem; } + set + { + LastMethodsPush("set_MyParentRTBItem"); + _MyParentEditItem = value; + if (_MyParentEditItem != null) + { + switch (_MyChildRelation) + { + case ChildRelation.None: // Same as after + case ChildRelation.After: // Procedures, sections, substeps, and tables/figures + // The size depends upon the parent type + int iType = (int)_MyParentEditItem.ContentType; + + switch (iType / 10000) + { + case 0: // Procedure + ItemLocation = new Point(_MyParentEditItem.ItemLocation.X + 20, _MyParentEditItem.Bottom); + ItemWidth = MyStepPanel.ToDisplay(MyStepSectionLayoutData.ColT) + MyStepPanel.ToDisplay(MyStepSectionLayoutData.WidT); + break; + case 1: // Section + if (this == TopMostEditItem) + ItemLocation = new Point(_MyParentEditItem.ItemLocation.X + 20, _MyParentEditItem.Bottom); + else + TopMostEditItem.ItemLocation = new Point(TopMostEditItem.ItemLocation.X, _MyParentEditItem.Bottom); + //TextWidth = _WidthAdjust + borderWidth + MyStepPanel.ToDisplay(_MyStepSectionLayoutData.WidSTableEdit, Convert.ToInt32(_MyStepSectionLayoutData.PMode) - 1); + ContentWidth = _WidthAdjust + BorderWidth + MyStepPanel.ToDisplay(MyStepSectionLayoutData.WidSTableEdit, MyItemInfo.ColumnMode); + break; + case 2: // Step + // if Table then determine width and location based upon it's parent's location + if (MyStepData.Type == "Table" || MyStepData.ParentType == "Table") + { + AdjustTableWidthAndLocation(); + } + else + { + ItemLocation = new Point(_MyParentEditItem.ContentLeft, _MyParentEditItem.Bottom); + ItemWidth = _MyParentEditItem.ContentWidth; + } + break; + } + break; + case ChildRelation.RNO: + // this is set so that TextWidth command below will be correct. TextWidth uses + // the tab start & tab width to calculate the overall width. + TabFormat = ""; // this is set so that TextWidth command below will be correct + _IgnoreResize = true; + ContentWidth = _MyParentEditItem.ContentWidth; + _IgnoreResize = false; + if (RNOLevel <= MyItemInfo.ColumnMode) + { + //int colR = MyStepPanel.ToDisplay(_MyStepSectionLayoutData.ColRTable, Convert.ToInt32(_MyStepSectionLayoutData.PMode) - 1); + int colR = MyStepPanel.ToDisplay(MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode); + if (colR - _MyParentEditItem.Width < 0) colR = _MyParentEditItem.Width + 0; + MyStepPanel.ItemMoving++; + //Left = _MyParentRTBItem.ItemLeft + RNOLevel * colR; + //ItemLocation = new Point(_MyParentRTBItem.ItemLeft + RNOLevel * colR, _MyParentRTBItem.Top); + LastMethodsPush(string.Format("set_MyParentRTBItem RNO Right {0}", MyID)); + ItemLocation = new Point(_MyParentEditItem.ItemLeft + RNOLevel * colR, _MyParentEditItem.Top); + int top = _MyParentEditItem.FindTop(_MyParentEditItem.Top); + if (top != _MyParentEditItem.Top) + { + _MyParentEditItem.LastMethodsPush(string.Format("set_MyParentRTBItem RNO Right {0}", MyID)); + _MyParentEditItem.Top = top; + _MyParentEditItem.LastMethodsPop(); + Top = top; + } + LastMethodsPop(); + MyStepPanel.ItemMoving--; + } + else + { + MyStepPanel.ItemMoving++; + LastMethodsPush(string.Format("set_MyParentRTBItem RNO Below {0} {1} {2}", MyID, _MyParentEditItem.BottomMostEditItem.MyID, _MyParentEditItem.BottomMostEditItem.Bottom)); + ContentLocation = new Point(_MyParentEditItem.ContentLeft, _MyParentEditItem.BottomMostEditItem.Bottom); + LastMethodsPop(); + //TextLocation = new Point(_MyParentRTBItem.TextLeft, FindTop(_MyParentRTBItem.Top)); + MyStepPanel.ItemMoving--; + } + // Same size as the Parent + break; + case ChildRelation.Before: // Cautions and Notes + //if(_WatchThis > 0 && MyID > 2111) + // Console.WriteLine("Setting MyParent: \r\n\tParent {0},{1} \r\n\tTopMostItem {2},{3} \r\n\tNext {4}, {5}", _MyParentRTBItem.MyID, _MyParentRTBItem + // ,_MyParentRTBItem.TopMostRTBItem.MyID,_MyParentRTBItem.TopMostRTBItem + // , _MyNextRTBItem == null ? 0 : _MyNextRTBItem.MyID, _MyNextRTBItem == null ? "None" : _MyNextRTBItem.ToString()); + + //Location = new Point(_MyParentRTBItem.Left + 20, max(_MyParentRTBItem.Top, (_MyNextRTBItem == null ? 0 : _MyNextRTBItem.Top )) ?? 0); + _IgnoreResize = true; + Width = MyStepPanel.ToDisplay(MyStepSectionLayoutData.WidT); + _IgnoreResize = false; + MyStepPanel.ItemMoving++; + //Location = new Point(_MyParentRTBItem.Left + 20, FindTop(_MyParentRTBItem.Top)); + int myTop = MyNextEditItem == null ? _MyParentEditItem.Top : MyNextEditItem.Top; + Location = new Point(_MyParentEditItem.Left + 20, FindTop(myTop)); + MyStepPanel.ItemMoving--; + //_MyParentRTBItem.Top = Bottom; + // Could be a Caution or Note - Need to get WidT + break; + } + } + LastMethodsPop(); + } + } + /// + /// Sets the previous item and adjusts locations + /// + public /*override*/ EditItem MyPreviousEditItem + { + get { return _MyPreviousEditItem; } + set + { + LastMethodsPush("set_MyPreviousRTBItem"); + _MyPreviousEditItem = value; + if (_MyPreviousEditItem != null) + { + _IgnoreResize = true; + if (MyStepData != null && (MyStepData.Type.ToLower().Contains("table") || MyStepData.ParentType.ToLower().Contains("table"))) + { + ItemWidth = TableWidth; + Location = new Point(_MyPreviousEditItem.Left, FindTop(_MyPreviousEditItem.BottomMostEditItem.Bottom)); + } + else if (value.MyItemInfo.IsTablePart) + { + ItemLocation = new Point(value.MyParentEditItem.ContentLeft, value.MyParentEditItem.Bottom); + ItemWidth = value.MyParentEditItem.ContentWidth; + } + else + { + Width = MyPreviousEditItem.Width; + if (TopMostEditItem == this) + Location = new Point(_MyPreviousEditItem.Left, FindTop(_MyPreviousEditItem.BottomMostEditItem.Bottom)); + else + TopMostEditItem.Location = new Point(TopMostEditItem.Left, FindTop(_MyPreviousEditItem.BottomMostEditItem.Bottom)); + } + _IgnoreResize = false; + //ShowMe(""); + //if (MyID > _StartingID) + // Console.WriteLine("{0}-->Setting MyPreviousRTBItem {1},{2},{3},{4},{5},{6},{7}", WatchThisIndent, MyID, this + // , _MyPreviousRTBItem + // ,Top + // , _MyPreviousRTBItem.BottomMostRTBItem.Bottom + // , FindTop(_MyPreviousRTBItem.BottomMostRTBItem.Bottom) + // , _MyPreviousRTBItem.Bottom); + //Location = new Point(_MyPreviousRTBItem.Left, _MyPreviousRTBItem.BottomMostRTBItem.Bottom); + switch (_MyChildRelation) + { + case ChildRelation.None: + break; + case ChildRelation.After: + break; + case ChildRelation.RNO: + break; + case ChildRelation.Before: + //MyStepPanel.ItemMoving++; + //UpOneRTBItem.Top = BottomMostRTBItem.Bottom; + //MyStepPanel.ItemMoving--; + break; + } + if (_MyPreviousEditItem.MyNextEditItem != this) _MyPreviousEditItem.MyNextEditItem = this; + } + LastMethodsPop(); + } + } + protected void SetupEditItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem) + { + if (itemInfo.ItemID == 10366) Console.WriteLine("Here"); + //if (itemInfo.ItemID == 225) _MyStepRTB.Resize += new EventHandler(_MyStepRTB_Resize); + //_MyStepRTB.MyRTBItem = this; + //// TIMING: DisplayItem.TimeIt("CSLARTB InitComp"); + BackColor = myStepPanel.PanelColor; + //_MyStepRTB.BackColor = myStepPanel.InactiveColor; + // TODO: Adjust top based upon format + // TODO: Remove Label and just output ident on the paint event + TabLeft = 20; + SetupHeader(itemInfo); + this.Paint += new PaintEventHandler(EditItem_Paint); + this.BackColorChanged += new EventHandler(EditItem_BackColorChanged); + this.Move += new EventHandler(EditItem_Move); + this.Resize += new EventHandler(EditItem_Resize); + if (itemInfo != null) + { + ContentType = (int)itemInfo.MyContent.Type; + switch (ContentType / 10000) + { + case 0: // Procedure + ContentFont = myStepPanel.ProcFont;// lblTab.Font = myStepPanel.ProcFont; + TabFont = itemInfo.MyTab.MyFont.WindowsFont; + break; + case 1: // Section + ContentFont = myStepPanel.SectFont;// lblTab.Font = myStepPanel.SectFont; + TabFont = itemInfo.MyTab.MyFont.WindowsFont; + break; + case 2: // Steps + ContentFont = myStepPanel.StepFont;//lblTab.Font = myStepPanel.StepFont; + TabFont = itemInfo.MyTab.MyFont.WindowsFont; + MyStepData = itemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList[ContentType % 10000]; + break; + } + //this.Move += new EventHandler(DisplayItem_Move); + } + else + { + if (myStepPanel.MyFont != null) ContentFont = TabFont = myStepPanel.MyFont; + } + if (expand) ShowExpanded(); + MyStepPanel = myStepPanel; + if (itemInfo != null) myStepPanel._LookupEditItems.Add(itemInfo.ItemID, this); + _MyChildRelation = myChildRelation; + if (myParentEditItem != null) RNOLevel = myParentEditItem.RNOLevel; + if (itemInfo != null) + { + //// TIMING: DisplayItem.TimeIt("CSLARTB before _Layout"); + MyStepSectionLayoutData = itemInfo.ActiveFormat.MyStepSectionLayoutData; + //// TIMING: DisplayItem.TimeIt("CSLARTB _Layout"); + if (myParentEditItem != null) + SeqLevel = myParentEditItem.SeqLevel + ((myChildRelation == ChildRelation.After || myChildRelation == ChildRelation.Before) && itemInfo.IsSequential ? 1 : 0); + //// TIMING: DisplayItem.TimeIt("CSLARTB seqLevel"); + MyItemInfo = itemInfo; + MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged); + } + //// TIMING: DisplayItem.TimeIt("CSLARTB MyItem"); + myStepPanel.Controls.Add(this); + + switch (myChildRelation) + { + case ChildRelation.After: + AddItem(myParentEditItem, ref myParentEditItem._MyAfterEditItems, nextEditItem); + break; + case ChildRelation.Before: + AddItem(myParentEditItem, ref myParentEditItem._MyBeforeEditItems, nextEditItem); + break; + case ChildRelation.RNO: + RNOLevel = myParentEditItem.RNOLevel + 1; + AddItem(myParentEditItem, ref myParentEditItem._MyRNOEditItems, nextEditItem); + break; + case ChildRelation.None: + break; + } + if (itemInfo != null) + { + if (myChildRelation == ChildRelation.None) + { + if (ContentType == 0 && MyStepSectionLayoutData != null) + { + LastMethodsPush(string.Format("SetupRTBItem {0}", MyID)); + Width = MyStepPanel.ToDisplay(MyStepSectionLayoutData.WidT); + } + } + } + //// TIMING: DisplayItem.TimeIt("CSLARTB Parent"); + SetText(); + //// TIMING: DisplayItem.TimeIt("CSLARTB SetText"); + if (itemInfo != null) + { + Name = string.Format("Item-{0}", itemInfo.ItemID); + SetExpandAndExpander(itemInfo); + if (expand && (itemInfo.MyContent.ContentPartCount != 0)) // If it should expand and it can expand + Expand(true); + else + if (myParentEditItem == null)// If it is the top node + if (ContentType >= 20000) // and it is a step - fully expand + Expand(true); + else // otherwise only expand one level + Expand(false); + } + //// TIMING: DisplayItem.TimeIt("CSLARTB before Controls Add"); + //myStepPanel.Controls.Add(this); + int top = FindTop(0); + if (Top < top) + { + LastMethodsPush("SetupRTBItem"); + MyStepPanel.ItemMoving++; + Top = top; + MyStepPanel.ItemMoving--; + LastMethodsPop(); + } + _Loading = false; + //// TIMING: DisplayItem.TimeIt("CSLARTB Controls Add"); + } + void MyConfig_PropertyChanged(object sender, PropertyChangedEventArgs e) + { + SaveConfig(); + } + public void SaveConfig() + { + if (!MyItemInfo.MyConfig.IsDirty) return; + using (Item itm = MyItemInfo.Get()) + { + itm.MyContent.Config = MyItemInfo.MyConfig.ToString(); + itm.Save(); + } + MyItemInfo.MyConfig.IsDirty = false; + } + /// + /// If the background changes, change the background of the RichTextBox + /// + /// + /// + void EditItem_BackColorChanged(object sender, EventArgs e) + { + //IdentifyMe(false); + } + // TODO: the format of the circles, Checkoffs and Changebars should come from the format file + /// + /// This adds drawing items to the RTBItem as needed including + /// Circle around the Tab Number + /// Check-Offs + /// Change Bars + /// + /// + /// + private void EditItem_Paint(object sender, PaintEventArgs e) + { + Graphics g = e.Graphics; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; + //g.DrawString(lblTab.Text, MyItemInfo.MyTab.MyFont.WindowsFont, Brushes.Red, new RectangleF(new PointF(MyStepPanel.MyStepPanelSettings.NumberLocationX, MyStepPanel.MyStepPanelSettings.NumberLocationY), MyStepPanel.MyStepPanelSettings.NumberSize), StringFormat.GenericDefault); + // adjust x location of label by 7, to position correctly. + //g.DrawString(lblTab.Text, MyItemInfo.MyTab.MyFont.WindowsFont, Brushes.Blue, new RectangleF(new PointF(Convert.ToSingle(lblTab.Location.X-7), Convert.ToSingle(lblTab.Location.Y)), MyStepPanel.MyStepPanelSettings.NumberSize), StringFormat.GenericDefault); + //g.DrawLine(Pens.DarkGreen, lblTab.Location.X-7, 0, lblTab.Location.X-7, this.Height); + //g.DrawLine(Pens.DarkGreen, MyStepRTB.Location.X - 7, 0, MyStepRTB.Location.X - 7, this.Height); + g.DrawString(TabText, MyItemInfo.MyTab.MyFont.WindowsFont, Brushes.Black, new RectangleF(new PointF(Convert.ToSingle(TabLocation.X), Convert.ToSingle(TabLocation.Y)), MyStepPanel.MyStepPanelSettings.NumberSize), StringFormat.GenericDefault); + //g.DrawLine(Pens.DarkGreen, lblTab.Location.X, 0, lblTab.Location.X, this.Height); + //g.DrawLine(Pens.DarkGreen, MyStepRTB.Location.X, 0, MyStepRTB.Location.X, this.Height); + if (Circle) + { + Pen penC = new Pen(MyStepPanel.MyStepPanelSettings.CircleColor, MyStepPanel.MyStepPanelSettings.CircleWeight); + g.DrawArc(penC, TabLeft + 1, 0, MyStepPanel.MyStepPanelSettings.CircleDiameter, MyStepPanel.MyStepPanelSettings.CircleDiameter, 0F, 360F); + } + if (CheckOff) + { + Pen penCO = new Pen(MyStepPanel.MyStepPanelSettings.CheckOffColor, MyStepPanel.MyStepPanelSettings.CheckOffWeight); + g.DrawRectangle(penCO, MyStepPanel.MyStepPanelSettings.CheckOffX, MyStepPanel.MyStepPanelSettings.CheckOffY, MyStepPanel.MyStepPanelSettings.CheckOffSize, MyStepPanel.MyStepPanelSettings.CheckOffSize); + } + if (ChangeBar) + { + Pen penCB = new Pen(MyStepPanel.MyStepPanelSettings.ChangeBarColor, MyStepPanel.MyStepPanelSettings.ChangeBarWeight); + if (ChangeBarPosition == E_ChangeBarPosition.Left) + g.DrawLine(penCB, 0, ContentTop, 0, Height); // left, top, right, bottom. + else + { + g.DrawLine(penCB, Width - 2, ContentTop, Width - 2, Height); + } + } + } + } +} diff --git a/PROMS/Volian.Controls.Library/FindReplace.cs b/PROMS/Volian.Controls.Library/FindReplace.cs index 0baa0cc2..c1bbe352 100644 --- a/PROMS/Volian.Controls.Library/FindReplace.cs +++ b/PROMS/Volian.Controls.Library/FindReplace.cs @@ -16,36 +16,19 @@ namespace Volian.Controls.Library private bool findingbookmarks = false; //private bool _offsetStartPos = false; - private RTBItem _MyRTBItem; - public RTBItem MyRTBItem + private EditItem _MyEditItem; + public EditItem MyEditItem { - get { return _MyRTBItem; } + get { return _MyEditItem; } set { - _MyRTBItem = value; - //DocVersionInfo dvi = _MyItemInfo.MyProcedure.ActiveParent as DocVersionInfo; //MyRTBItem.MyItemInfo.MyProcedure.ActiveParent as DocVersionInfo; - _MyDocVersion = _MyRTBItem.MyItemInfo.MyProcedure.ActiveParent as DocVersionInfo; + _MyEditItem = value; + if (_MyEditItem == null) return; + _MyDocVersion = _MyEditItem.MyItemInfo.MyProcedure.ActiveParent as DocVersionInfo; SetupContextMenu(); //_offsetStartPos = false; // in a different rtf box, don't offset find position first time around } } - //private DocVersionInfo _MyDVI; - //public DocVersionInfo MyDVI - //{ - // get - // { - // if (_MyDVI != null) return _MyDVI; - // if (_MyRTBItem != null) - // { - // ItemInfo procInfo = _MyRTBItem.MyItemInfo.MyProcedure as ItemInfo; - // if (procInfo == null) return null; - // _MyDVI = procInfo.ActiveParent as DocVersionInfo; - // return _MyDVI; - // } - // return null; - // } - //} - private DocVersionInfo _MyDocVersion; public DocVersionInfo Mydocversion { @@ -81,7 +64,6 @@ namespace Volian.Controls.Library public FindReplace() { - //DocVersionInfo dvi = MyRTBItem.MyItemInfo.MyProcedure.ActiveParent as DocVersionInfo; InitializeComponent(); LoadFindReplaceTextListBox(); //if (dvi != null && dvi.VersionType > 127) @@ -136,7 +118,7 @@ namespace Volian.Controls.Library { btnFindNext_Click(sender, e); if (found) // found is set in btnFindNext_Click() - MyRTBItem.MyStepRTB.ReplaceText(cmboReplaceText.Text, cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked, false, null); + MyEditItem.ReplaceText(cmboReplaceText.Text, cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked, false, null); } private void btnRplAll_Click(object sender, EventArgs e) @@ -144,7 +126,7 @@ namespace Volian.Controls.Library btnFindNext_Click(sender, e); while (found) // found is set in btnFindNext_Click() { - if (MyRTBItem.MyStepRTB.ReplaceText(cmboReplaceText.Text, cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked, true, this) == DialogResult.Cancel) + if (MyEditItem.ReplaceText(cmboReplaceText.Text, cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked, true, this) == DialogResult.Cancel) found = false; else btnFindNext_Click(sender, e); @@ -157,11 +139,11 @@ namespace Volian.Controls.Library btnFindNext_Click(sender, e); while (found) // found is set in btnFindNext_Click() { - MyDisplayBookMarks.AddBookMark(MyRTBItem.MyItemInfo); + MyDisplayBookMarks.AddBookMark(MyEditItem.MyItemInfo); btnFindNext_Click(sender, e); } StepPanelTabDisplayEventArgs args = new StepPanelTabDisplayEventArgs("Bookmarks"); - MyRTBItem.MyStepPanel.OnTabDisplay(sender, args); + MyEditItem.MyStepPanel.OnTabDisplay(sender, args); findingbookmarks = false; } @@ -177,10 +159,14 @@ namespace Volian.Controls.Library found = false; AddToComboLists(); doingfind = true; - while (!MyRTBItem.MyStepRTB.FindText(cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked)) + while (!MyEditItem.FindText(cmboFindText.Text, cbxCaseSensitive.Checked, cbxWholeWord.Checked, cbxReverse.Checked)) { - ItemInfo next = (cbxReverse.Checked) ? MyRTBItem.MyItemInfo.SearchPrev : MyRTBItem.MyItemInfo.SearchNext; - while (!next.IsSection && !next.MyContent.Text.ToUpper().Contains(cmboFindText.Text.ToUpper())) + ItemInfo next = (cbxReverse.Checked) ? MyEditItem.MyItemInfo.SearchPrev : MyEditItem.MyItemInfo.SearchNext; + + // TODO: Searchable text for grids/tables will be in MyContent.Text - but is not there now. + // uncomment next line and remove following line (and it's associated method code) when it is available. + //while (!next.IsSection && !next.MyContent.Text.ToUpper().Contains(cmboFindText.Text.ToUpper())) + while (!next.IsSection && !FindNextText(next)) next = (cbxReverse.Checked) ? next.SearchPrev : next.SearchNext; if (next.IsSection) { @@ -193,14 +179,22 @@ namespace Volian.Controls.Library } return; } - MyRTBItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(next); + MyEditItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OpenItem(next); if (cbxReverse.Checked) - MyRTBItem.MyStepRTB.SelectionStart = MyRTBItem.MyStepRTB.Text.Length; + MyEditItem.PositionToEnd(); + } + if (MyEditItem.MyStepRTB != null && !MyEditItem.MyStepRTB.Visible) + { + MyEditItem.MyStepRTB.Visible = true; + MyEditItem.MyStepRTB.Focus(); } - MyRTBItem.MyStepRTB.Focus(); found = true; } - + private bool FindNextText(ItemInfo next) + { + if (next.MyContent.MyGrid!=null) return true; + return next.MyContent.Text.ToUpper().Contains(cmboFindText.Text.ToUpper()); + } private void AddToComboLists() { bool hastext = this.cmboFindText.Text.Length > 0; @@ -298,12 +292,12 @@ namespace Volian.Controls.Library IDataObject myDO = Clipboard.GetDataObject(); if (myDO.GetDataPresent(DataFormats.Rtf)) { - StepRTB stpRTB = new StepRTB(); - stpRTB.SelectedRtf = myDO.GetData(DataFormats.Rtf).ToString(); + RichTextBox rtb = new RichTextBox(); + rtb.SelectedRtf = ItemInfo.StripLinks(myDO.GetData(DataFormats.Rtf).ToString()); if (cmboReplaceText.Focused) - cmboReplaceText.SelectedText = stpRTB.Text; + cmboReplaceText.SelectedText = rtb.Text; else if (cmboFindText.Focused) - cmboFindText.SelectedText = stpRTB.Text; + cmboFindText.SelectedText = rtb.Text; } else if (myDO.GetDataPresent(DataFormats.Text)) if (cmboReplaceText.Focused) @@ -358,13 +352,10 @@ namespace Volian.Controls.Library private void FindReplace_Activated(object sender, EventArgs e) { - StepRTB srtb = MyRTBItem.MyStepRTB; - if (srtb.SelectionLength > 0 && !doingfind) + if (!doingfind) { - if (srtb.IsSelectionLinked(srtb.SelectionStart, srtb.SelectionLength)) - cmboFindText.Text = srtb.SelectedText.Substring(0, srtb.SelectedText.IndexOf("#Link")); - else - cmboFindText.Text = srtb.SelectedText; + string find = MyEditItem.SelectedTextForFind; + if (find != null) cmboFindText.Text = find; } } diff --git a/PROMS/Volian.Controls.Library/GridItem.Designer.cs b/PROMS/Volian.Controls.Library/GridItem.Designer.cs new file mode 100644 index 00000000..901c7d86 --- /dev/null +++ b/PROMS/Volian.Controls.Library/GridItem.Designer.cs @@ -0,0 +1,91 @@ +namespace Volian.Controls.Library +{ + partial class GridItem + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GridItem)); + this.lblTab = new System.Windows.Forms.Label(); + this._MyToolTip = new DevComponents.DotNetBar.SuperTooltip(); + this._MyFlexGrid = new Volian.Controls.Library.VlnFlexGrid(this.components); + ((System.ComponentModel.ISupportInitialize)(this._MyFlexGrid)).BeginInit(); + this.SuspendLayout(); + // + // lblTab + // + this.lblTab.BackColor = System.Drawing.Color.Transparent; + this.lblTab.Location = new System.Drawing.Point(0, 0); + this.lblTab.Name = "lblTab"; + this.lblTab.Size = new System.Drawing.Size(61, 23); + this.lblTab.TabIndex = 3; + this.lblTab.Visible = false; + this.lblTab.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblTab_MouseDown); + // + // _MyToolTip + // + this._MyToolTip.LicenseKey = "F962CEC7-CD8F-4911-A9E9-CAB39962FC1F"; + // + // _MyFlexGrid + // + this._MyFlexGrid.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom; + this._MyFlexGrid.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.Both; + this._MyFlexGrid.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); + this._MyFlexGrid.ColumnInfo = "3,0,0,0,0,40,Columns:"; + this._MyFlexGrid.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw; + this._MyFlexGrid.FocusRect = C1.Win.C1FlexGrid.FocusRectEnum.Solid; + this._MyFlexGrid.Location = new System.Drawing.Point(5, 5); + this._MyFlexGrid.Name = "_MyFlexGrid"; + this._MyFlexGrid.Rows.Count = 4; + this._MyFlexGrid.Rows.DefaultSize = 20; + this._MyFlexGrid.Rows.Fixed = 0; + this._MyFlexGrid.ScrollBars = System.Windows.Forms.ScrollBars.None; + this._MyFlexGrid.Size = new System.Drawing.Size(314, 66); + this._MyFlexGrid.StyleInfo = resources.GetString("_MyFlexGrid.StyleInfo"); + this._MyFlexGrid.TabIndex = 4; + // + // GridItem + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this._MyFlexGrid); + this.Controls.Add(this.lblTab); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "GridItem"; + this.Size = new System.Drawing.Size(320, 72); + ((System.ComponentModel.ISupportInitialize)(this._MyFlexGrid)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label lblTab; + private DevComponents.DotNetBar.SuperTooltip _MyToolTip; + private VlnFlexGrid _MyFlexGrid; + } +} diff --git a/PROMS/Volian.Controls.Library/GridItem.cs b/PROMS/Volian.Controls.Library/GridItem.cs new file mode 100644 index 00000000..aff95640 --- /dev/null +++ b/PROMS/Volian.Controls.Library/GridItem.cs @@ -0,0 +1,634 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Text; +using System.Windows.Forms; +using System.Xml; +using VEPROMS.CSLA.Library; +using Volian.Base.Library; +using C1.Win.C1FlexGrid; + +namespace Volian.Controls.Library +{ + public partial class GridItem : EditItem + { + /* + * TODO: (2/2/11) + * 1) KBR Need to include/handle StepRTB/EditItem Events: Add for grid items, the events that + * are handled by StepRTB/EditItem. Should these be abstract events within EditItem so + * that it 'tells' you which events you need. + * May Need yet: + * OnOpenContextMenu (grid and/or rtb) + * steprtb->OnCopystep ? + * OnCheckClipboard + * 3) KBR FindReplace.cs - had to check for Null rtbItem, so will need + * to support if GridItem. AND frmVEPROMS.cs line 1021, findreplace + * currently are set to need an RTBItem. Will need to be more general. + * 4) KBR ContextMenu for table. May want it to function in a similar way to spellcheck, with + * the contentmenu to support table options and a last item that supports existing + * contextmenu + * 5) RHM Copy step - including modifying SQL code to copy grid/image data. + * 6) RHM Selection is NOT selection, i.e. if merged cells, selection isn't selecting the 'merged' + * i.e. parent cell. + * 7) RHM Selecting a range can end up with uneven rows or uneven columns. We need to handle, + * some possible options are to not allow operations to occur if uneven selections; + * make selection even; etc. + * 8) KBR When data migration of tables, need to include the font if there is a symbol. Move + * AddFontTable from StepRTB.cs to a place accessible, such as volian.base. And then + * in data migration, will need to know if a font is fixed. + * 9) RHM Editting cell with Transition Panel enabled; click on Ro Panel and it is not enabled + */ + #region Fields + public VlnFlexGrid MyFlexGrid + { + get { return _MyFlexGrid; } + set { _MyFlexGrid = value; } + } + private int _GridMargin = 11; + /// + /// Margin between the EditItem and the VlnFlexGrid. Appears on the Right. + /// Will allow space to draw a Change Bar on the right side of the EditItem. + /// + public int GridMargin + { + get { return _GridMargin; } + set { _GridMargin = value; } + } + #endregion + + #region Event Handlers + /// + /// Raises an ItemClick event when the user clicks on the Tab + /// + /// + /// + private void lblTab_MouseDown(object sender, MouseEventArgs e) + { + MyStepPanel.OnItemClick(this, new StepPanelEventArgs(this, e)); + } + void MyFlexGrid_Resize(object sender, EventArgs e) + { + this.Size = new Size(MyFlexGrid.Width + GridMargin, MyFlexGrid.Height + GridMargin); + AdjustTableWidthAndLocation(); + AdjustLocation(); + } + void MyFlexGrid_Enter(object sender, EventArgs e) + { + if (MyStepPanel.DisplayItemChanging) return; + MyStepRTB.MyItemInfo = MyItemInfo; // should be in vlnFlexGrid + MyStepPanel.SelectedEditItem = this; + } + void MyFlexGrid_KeyDown(object sender, KeyEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Left: + if (e.Shift) return; + MyStepRTB.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlLeft : E_ArrowKeys.Left); + e.Handled = true; + break; + case Keys.Up: + if (e.Shift) return; + MyStepRTB.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlUp : E_ArrowKeys.Up); + e.Handled = true; + break; + case Keys.Right: + if (e.Shift) return; + MyStepRTB.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlRight : E_ArrowKeys.Right); + e.Handled = true; + break; + case Keys.Down: + if (e.Shift) return; + MyStepRTB.StepRTB_ArrowPressed(e.Control ? E_ArrowKeys.CtrlDown : E_ArrowKeys.Down); + e.Handled = true; + break; + } + } + void MyFlexGrid_CursorMovement(object sender, VlnFlexGridCursorMovementEventArgs args) + { + MyStepPanel.CursorMovement(this,new Point(0,0), args.Key); + } + void MyStepRTB_LinkModifyTran(object sender, StepPanelLinkEventArgs args) + { + MyStepPanel.OnLinkModifyTran(sender, args); + } + void MyStepRTB_LinkModifyRO(object sender, StepPanelLinkEventArgs args) + { + MyStepPanel.OnLinkModifyRO(sender, args); + } + void MyStepRTB_LinkGoTo(object sender, StepPanelLinkEventArgs args) + { + MyStepPanel.OnLinkClicked(sender, args); + } + void MyStepRTB_CursorKeyPress(object sender, KeyEventArgs args) + { + MyStepPanel.StepCursorKeys(this, args); + } + void MyStepRTB_SetMenu(object sender, StepRTBMenuEventArgs args) + { + if (args.MenuGroup == null) + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ClearContextMenu(); + else if (args.MenuGroup == "OpenContextMenu") + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.SetContextMenu(); + else + MyStepPanel.MyStepTabPanel.MyStepTabRibbon.SetShortCutContextMenu(args.MenuGroup); + } + void MyStepRTB_AdjustTableWidth(object sender, StepRTBTableWidthEventArgs args) + { + //if ((!_MyItemInfo.IsSection && !_MyItemInfo.IsProcedure) && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure)) + if (args.EditMode) + { + int colR = MyStepPanel.ToDisplay(MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode); + int widS = /* _WidthAdjust + borderWidth + */ MyStepPanel.ToDisplay(MyStepSectionLayoutData.WidSTableEdit, MyItemInfo.ColumnMode); + int wNew = 70 + widS + colR * MyItemInfo.ColumnMode; + if (wNew > ItemWidth) + { + ItemWidth = wNew; + ItemLocation = TableLocation(MyParentEditItem, MyStepSectionLayoutData, wNew); + } + } + else + { + int newwidth = MyFlexGrid.Width; + if (ItemWidth != newwidth) + { + ItemWidth = newwidth; + ItemLocation = TableLocation(MyParentEditItem, MyStepSectionLayoutData, newwidth); + } + } + } + bool MyStepRTB_IsNotCurrentSelection(object sender, EventArgs args) + { + return MyStepPanel.SelectedEditItem != this; + } + + void MyStepRTB_OpenAnnotations(object sender, EventArgs args) + { + OpenAnnotations(); + } + void MyFlexGrid_OpenAnnotations(object sender, EventArgs args) + { + OpenAnnotations(); + } + void MyStepRTB_DoMouseWheel(object sender, MouseEventArgs args) + { + DoMouseWheel(args); + } + void MyStepRTB_DoSaveContents(object sender, EventArgs args) + { + SaveContents(); + } + void MyStepRTB_VisibleChanged(object sender, EventArgs e) + { + MyStepRTB.EditMode = MyStepRTB.Visible; + Console.WriteLine("GridItem: EditMode = {0}", MyStepRTB.EditMode); + } + void MyStepRTB_ReturnToEditor(object sender, EventArgs args) + { + MyFlexGrid.Focus(); + MyFlexGrid.StartEditing(); + } + + void MyFlexGrid_Click(object sender, EventArgs e) + { + MyFlexGrid.Focus(); + } + + void MyStepRTB_EditModeChanged(object sender, EventArgs args) + { + if (MyStepRTB.EditMode) + MyFlexGrid.Styles["Focus"].BackColor = MyFlexGrid.Styles["Highlight"].BackColor = Color.SkyBlue; + else + MyFlexGrid.Styles["Focus"].BackColor = MyFlexGrid.Styles["Highlight"].BackColor = Color.LightCyan; + } + private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore + void MyFlexGrid_SelChange(object sender, EventArgs e) + { + if (MyFlexGrid.Selection.IsSingleCell) + _OrigRtf = MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col].ToString(); + } + void MyStepRTB_KeyDown(object sender, KeyEventArgs e) + { + if (!e.Control && !e.Shift && !e.Alt && e.KeyCode == Keys.Escape && MyStepRTB.EditMode) + { + MyStepRTB.Rtf = _OrigRtf; + MyFlexGrid.Select(MyFlexGrid.Selection); + } + } + #endregion // Event Handlers + #region Constructors + public GridItem() + { + InitializeComponent(); + } + public GridItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand) + { + InitializeComponent(); + SetupEventHandlers(); + SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, null); + //RefreshDisplay(true); //TODO: is the argument true? + } + public GridItem(ItemInfo itemInfo, StepPanel myStepPanel, EditItem myParentEditItem, ChildRelation myChildRelation, bool expand, EditItem nextEditItem) + { + InitializeComponent(); + SetupEventHandlers(); + SetupEditItem(itemInfo, myStepPanel, myParentEditItem, myChildRelation, expand, nextEditItem); + //RefreshDisplay(true); //TODO: is the argument true? + } + private void SetupEventHandlers() + { + this.MyFlexGrid.Resize += new EventHandler(MyFlexGrid_Resize); + this.MyFlexGrid.Enter += new EventHandler(MyFlexGrid_Enter); + //this.MyFlexGrid.KeyDown += new KeyEventHandler(MyFlexGrid_KeyDown); + this.MyFlexGrid.CursorMovement += new VlnFlexGridCursorMovementEvent(MyFlexGrid_CursorMovement); + this.MyFlexGrid.OpenAnnotations += new VlnFlexGridEvent(MyFlexGrid_OpenAnnotations); + this.MyStepRTB.LinkGoTo += new StepRTBLinkEvent(MyStepRTB_LinkGoTo); + this.MyStepRTB.LinkModifyRO += new StepRTBLinkEvent(MyStepRTB_LinkModifyRO); + this.MyStepRTB.LinkModifyTran += new StepRTBLinkEvent(MyStepRTB_LinkModifyTran); + this.MyStepRTB.CursorKeyPress += new StepRTBCursorKeysEvent(MyStepRTB_CursorKeyPress); + this.MyStepRTB.SetMenu += new StepRTBMenuEvent(MyStepRTB_SetMenu); + this.MyStepRTB.AdjustTableWidth += new StepRTBTableWidthEvent(MyStepRTB_AdjustTableWidth); + this.MyStepRTB.IsNotCurrentSelection += new StepRTBBooleanEvent(MyStepRTB_IsNotCurrentSelection); + this.MyStepRTB.OpenAnnotations += new StepRTBEvent(MyStepRTB_OpenAnnotations); + this.MyStepRTB.DoMouseWheel += new StepRTBMouseEvent(MyStepRTB_DoMouseWheel); + this.MyStepRTB.DoSaveContents += new StepRTBEvent(MyStepRTB_DoSaveContents); + this.MyStepRTB.VisibleChanged += new EventHandler(MyStepRTB_VisibleChanged); + this.MyStepRTB.ReturnToEditor += new StepRTBEvent(MyStepRTB_ReturnToEditor); + this.MyFlexGrid.Click += new EventHandler(MyFlexGrid_Click); + this.MyStepRTB.EditModeChanged += new StepRTBEvent(MyStepRTB_EditModeChanged); + this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown); + this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); + } + + #endregion + #region Override Method and Properties + public override int BorderWidth { get { return (MyFlexGrid.Width - MyFlexGrid.ClientRectangle.Width); } } + + public override Point ContentLocation + { + get { return new Point(Location.X + MyFlexGrid.Left, Location.Y); } + set { Location = new Point(value.X - MyFlexGrid.Left, value.Y); } + } + public override string TabFormat { get { return _TabFormat; } set { _TabFormat = value; } } + public override void AdjustTableWidthAndLocation() + { + //_MyStepRTB.Font = MyStepData.Font.WindowsFont; + //ItemWidth = (int)GetTableWidth(MyStepRTB.Font, MyItemInfo.MyContent.Text, true); + //ItemWidth = MyFlexGrid.Width; + ItemLocation = new Point(50, _MyParentEditItem.Bottom); + ItemLocation = TableLocation(_MyParentEditItem, MyStepSectionLayoutData, ItemWidth); + } + public override void SetToolTip(string tip) + { + DevComponents.DotNetBar.SuperTooltipInfo tpi = new DevComponents.DotNetBar.SuperTooltipInfo("", "", tip, null, null, DevComponents.DotNetBar.eTooltipColor.Lemon); + _MyToolTip.MinimumTooltipSize = new Size(0, 24); + _MyToolTip.TooltipDuration = 3; + _MyToolTip.SetSuperTooltip(MyStepRTB, tpi); + } + public override void RefreshContent() + { + // content, i.e. MyContent, of the grid has changed, refresh the grid + /* + * Need: + * 'RefreshDisplay': Something to display grid + * 'IdentifyMe': Something to highlight appropriately, i.e. copy step OR backgroun color (annotation or not) + * 'SetExpandAndExpander': Handles whether it is visible, i.e. if step is collapsed - this is not visible. + */ + } + public override int TableWidth { get { return 0; } } // DONE + public override int ItemLeft + { + get { return Left + lblTab.Left; } + set { Left = value - lblTab.Left; } + } + public override int ContentLeft { get { return Left + MyFlexGrid.Left; } } + public override int ContentWidth + { + get { return MyFlexGrid.Width; } + set + { + Width = value + lblTab.Left + lblTab.Width; + } + } + public override Point ItemLocation + { + get { return new Point(Location.X + lblTab.Left, Location.Y); } + set { Location = new Point(value.X - lblTab.Left, value.Y); } + } + public override int ItemWidth + { + get { return Width - lblTab.Left; } + set + { + Width = GridMargin + value + lblTab.Left; + } + } + public override void RefreshOrdinal() + { + TabFormat = null; // Reset Tab + } + public override bool Expanded + { + get {return !Colapsing;} + set {;} // Tables are always expanded. + } + public override void RefreshTab() { TabFormat = null;} + public override void SetFocus() { MyFlexGrid.Focus();} + public override void SaveContents() + { + MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col] = MyStepRTB.Rtf; + } + public override bool CanExpand { get { return false; } set { ;} } + public override void HandleResize() { ;} // DONE + public override void MatchExpanded() { ;} // DONE + public override void ItemSelect() + { + // Was getting an Error that _MyStepRTB was Disposed RHM 20101217 + if (!MyFlexGrid.Disposing) + { + MyFlexGrid.Focus(); + MyFlexGrid.Select(0, 0); + } + else + { + _MyLog.WarnFormat("Attempt to give Focus to Disposed Object {0}", MyID); + } + ScrollToCenter(); + } + public override void ItemShow() + { + MyFlexGrid.Focus(); + ScrollToCenter(); + } + public override StepRTB MyStepRTB { get { return MyFlexGrid.TableCellEditor; } } + public override DialogResult ReplaceText(string rpltxt, string fndstr, bool caseSensitive, bool matchWholeWord, bool reverse, bool prompt, IWin32Window fndrpldlg) + { + int r = MyFlexGrid.Row; + int c = MyFlexGrid.Col; + + if (!reverse) + { + int w = MyFlexGrid.Cols.Count; + int h = MyFlexGrid.Rows.Count; + while (r < h) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + int ss = MyStepRTB.SelectionStart; + int sl = MyStepRTB.SelectionLength; + MyFlexGrid.StartEditing(); + MyStepRTB.Select(ss, sl); // need to reset selection because startediting positions to end. + string oldRtf = MyStepRTB.Rtf; + DialogResult dr = MyStepRTB.ReplaceText(rpltxt, fndstr, caseSensitive, matchWholeWord, reverse, prompt, fndrpldlg); + if (oldRtf != MyStepRTB.Rtf) MyFlexGrid[r, c] = MyStepRTB.Rtf; + if (dr == DialogResult.Yes || dr == DialogResult.Cancel) return dr; + } + c = c + 1; + if (c == w) + { + c = 0; + r = r + 1; + } + if (r < h) + { + MyFlexGrid.Select(r, c); + MyStepRTB.Select(0, 0); + } + } + } + else // reverse + { + while (r >= 0) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + int ss = MyStepRTB.SelectionStart; + int sl = MyStepRTB.SelectionLength; + MyFlexGrid.StartEditing(); + MyStepRTB.Select(ss, sl); + string oldRtf = MyStepRTB.Rtf; + DialogResult dr = MyStepRTB.ReplaceText(rpltxt, fndstr, caseSensitive, matchWholeWord, reverse, prompt, fndrpldlg); + if (oldRtf != MyStepRTB.Rtf) MyFlexGrid[r, c] = MyStepRTB.Rtf; + if (dr == DialogResult.Yes || dr == DialogResult.Cancel) return dr; + } + c = c - 1; + if (c < 0) + { + c = MyFlexGrid.Cols.Count - 1; + r = r - 1; + } + cr = MyFlexGrid.GetMergedRange(r, c); + if (r >= 0 && cr.r1 == r && cr.c1 == c) + { + MyFlexGrid.Select(r, c); + MyFlexGrid.StartEditing(); + MyStepRTB.Select(MyStepRTB.Text.Length, 0); + } + } + } + return DialogResult.No; + } + public override bool FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse) + { + int r = MyFlexGrid.Row; + int c = MyFlexGrid.Col; + if (!reverse) + { + int w = MyFlexGrid.Cols.Count; + int h = MyFlexGrid.Rows.Count; + while (r < h) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + int ss = MyStepRTB.SelectionStart + MyStepRTB.SelectionLength; + MyFlexGrid.StartEditing(); + MyStepRTB.Select(ss, 0); // need to reset selection because startediting positions to end. + bool scn = MyStepRTB.FindText(str, caseSensitive, matchWholeWord, reverse); + if (scn) return true; + } + c = c + 1; + if (c == w) + { + c = 0; + r = r + 1; + } + if (r < h) + { + MyFlexGrid.Select(r, c); + MyStepRTB.Select(0, 0); + } + } + } + else + { + while (r >= 0) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + int ss = MyStepRTB.SelectionStart; + MyFlexGrid.StartEditing(); + MyStepRTB.Select(ss, 0); + bool scn = MyStepRTB.FindText(str, caseSensitive, matchWholeWord, reverse); + if (scn) return true; + } + c = c - 1; + if (c < 0) + { + c = MyFlexGrid.Cols.Count - 1; + r = r - 1; + } + cr = MyFlexGrid.GetMergedRange(r, c); + if (r >= 0 && cr.r1 == r && cr.c1 == c) + { + MyFlexGrid.Select(r, c); + MyFlexGrid.StartEditing(); + MyStepRTB.Select(MyStepRTB.Text.Length, 0); + } + } + } + return false; + } + public override void PositionToEnd() + { + int r = MyFlexGrid.Rows.Count - 1; + int c = MyFlexGrid.Cols.Count - 1; + MyFlexGrid.Select(r, c); + while (r >= 0) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + MyFlexGrid.StartEditing(); + return; + } + c = c - 1; + if (c < 0) + { + c = MyFlexGrid.Cols.Count - 1; + r = r - 1; + } + if (r >= 0) + { + MyFlexGrid.Select(r, c); + MyStepRTB.Select(MyStepRTB.Text.Length, 0); + } + } + } + public override string SelectedTextForFind + { + get + { + StepRTB srtb = MyStepRTB; + if (srtb.SelectionLength > 0) + { + if (srtb.IsSelectionLinked(srtb.SelectionStart, srtb.SelectionLength)) + return srtb.SelectedText.Substring(0, srtb.SelectedText.IndexOf("#Link")); + else + return srtb.SelectedText; + } + return null; + } + } + public override bool SpellCheckNext() + { + int r = MyFlexGrid.Row; + int c = MyFlexGrid.Col; + int w = MyFlexGrid.Cols.Count; + int h = MyFlexGrid.Rows.Count; + while (r < h) + { + CellRange cr = MyFlexGrid.GetMergedRange(r, c); + if (cr.r1 == r && cr.c1 == c) + { + MyFlexGrid.Select(r, c); + MyFlexGrid.StartEditing(); + string oldRtf = MyStepRTB.Rtf; + bool scn = MyStepRTB.SpellCheckNext(); + if (oldRtf != MyStepRTB.Rtf) MyFlexGrid[r, c] = MyStepRTB.Rtf; + if (!scn) return false; + } + c = c + 1; + if (c == w) + { + c = 0; + r = r + 1; + } + } + return true; + } + public override void IdentifyMe(bool highlight) + { + if (highlight) + MyFlexGrid.Styles["Alternate"].BackColor = MyFlexGrid.Styles["Normal"].BackColor = Color.Gray; + else + { + if (MyFlexGrid.Focused) // If active Set BackColor to the active color + SetActive(); + else // Otherwise Set the BackColor to either the InactiveColor or the AnnotationColor + { + MyFlexGrid.Styles["Alternate"].BackColor = MyFlexGrid.Styles["Normal"].BackColor = + MyItemInfo.ItemAnnotationCount == 0 ? MyStepPanel.InactiveColor : MyStepPanel.AnnotationColor; + // Turn-off Size adjustment + MyFlexGrid.Cols.Fixed = 0; + MyFlexGrid.Rows.Fixed = 0; + } + } + } + public override void SetActive() + { + MyFlexGrid.Styles["Focus"].BackColor = MyFlexGrid.Styles["Highlight"].BackColor = Color.LightCyan; + } + private bool _Empty = false; + public override bool Empty + { + get { return _Empty; } + set { _Empty = value; } + } + public override void RefreshDisplay(bool activeMode) + { + XmlDocument xd = new XmlDocument(); + xd.LoadXml(MyItemInfo.MyContent.MyGrid.Data.Replace("Courier New", "Times New Roman")); + //xd.LoadXml(MyItemInfo.MyContent.MyGrid.Data); + MyFlexGrid.Clear(); + MyFlexGrid.MergedRanges.Clear(); + MyFlexGrid.ReadXml(xd); + MyFlexGrid.AdjustGridControlSize(); + // When a grid is read from XML, all of the styles are updated to the values in the XML. + // Thus any specific settings need to be set after the grid is read. + MyFlexGrid.Styles["Highlight"].BackColor = Color.LightCyan; + MyFlexGrid.Styles["Focus"].BackColor = Color.LightCyan; + MyFlexGrid.HighLight = activeMode ? C1.Win.C1FlexGrid.HighLightEnum.Always : C1.Win.C1FlexGrid.HighLightEnum.WithFocus; + MyFlexGrid.VwMode = MyStepPanel.VwMode; + } + public override void ToggleEditView(E_ViewMode vwMode) + { + /* + * TODO: + * 1) SaveContents + */ + RefreshDisplay(false); + MyFlexGrid.VwMode = vwMode; + } + public override int TabLeft { get { return lblTab.Left; } set { lblTab.Left = value; } } + public override Font TabFont { get { return lblTab.Font; } set { lblTab.Font = value; } } + public override string TabText { get { return lblTab.Text; } } + public override Point TabLocation { get { return lblTab.Location; } } + public override Font ContentFont { get { return MyFlexGrid.Font; } set { MyFlexGrid.Font = value; } } // TODO how do we know what font tables are in? + public override float ContentTop { get { return MyFlexGrid.Top; } } + public override void SetupHeader(ItemInfo itemInfo) { ;} // tables do not have headers + public override void ShowExpanded() {;} + public override void SetText() + { + RefreshDisplay(false); + IdentifyMe(false); + } + public override void SetExpandAndExpander(ItemInfo itemInfo) { CanExpand = false; } // can't expand a table + #endregion + } +} diff --git a/PROMS/Volian.Controls.Library/GridItem.resx b/PROMS/Volian.Controls.Library/GridItem.resx new file mode 100644 index 00000000..f979290c --- /dev/null +++ b/PROMS/Volian.Controls.Library/GridItem.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Normal{Font:Microsoft Sans Serif, 7.8pt;BackColor:255, 255, 255;TextAlign:LeftCenter;Border:Flat,1,Black,Both;} Alternate{BackColor:255, 255, 255;} Fixed{BackColor:Control;ForeColor:ControlText;Border:Flat,1,ControlDark,Both;BackgroundImageLayout:Hide;} Highlight{BackColor:LightCyan;ForeColor:Black;} Focus{BackColor:LightCyan;} Editor{} Search{BackColor:Highlight;ForeColor:HighlightText;} Frozen{BackColor:Beige;} NewRow{ForeColor:GrayText;} EmptyArea{BackColor:Transparent;Border:None,1,Black,Both;} SelectedColumnHeader{} SelectedRowHeader{} GrandTotal{BackColor:Black;ForeColor:White;} Subtotal0{BackColor:ControlDarkDark;ForeColor:White;} Subtotal1{BackColor:ControlDarkDark;ForeColor:White;} Subtotal2{BackColor:ControlDarkDark;ForeColor:White;} Subtotal3{BackColor:ControlDarkDark;ForeColor:White;} Subtotal4{BackColor:ControlDarkDark;ForeColor:White;} Subtotal5{BackColor:ControlDarkDark;ForeColor:White;} + + \ No newline at end of file