2425 lines
80 KiB
C#
2425 lines
80 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
using System.Text.RegularExpressions;
|
|
using Volian.Base.Library;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
#region Enums
|
|
public enum ChildRelation : int
|
|
{
|
|
None = 0,
|
|
After = 1,
|
|
Before = 2,
|
|
RNO = 3
|
|
}
|
|
public enum ExpandingStatus : int
|
|
{
|
|
No = 0,
|
|
Expanding = 1,
|
|
Colapsing = 2,
|
|
Hiding = 4,
|
|
Showing = 8,
|
|
Done = 16
|
|
}
|
|
public enum E_ChangeBarPosition : int
|
|
{
|
|
Left = 0,
|
|
Right = 1
|
|
}
|
|
#endregion
|
|
public partial class RTBItem : UserControl
|
|
{
|
|
//private static int _RTBItemUnique = 0;
|
|
//private static int RTBItemUnique
|
|
//{
|
|
// get
|
|
// {
|
|
// if (_RTBItemUnique == 3)
|
|
// Console.WriteLine("here");
|
|
// return ++_RTBItemUnique;
|
|
// }
|
|
//}
|
|
//private int _MyRTBItemUnique = RTBItemUnique;
|
|
|
|
//public int MyRTBItemUnique
|
|
//{
|
|
// get {return _MyRTBItemUnique; }
|
|
//}
|
|
|
|
#region Private Fields
|
|
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
private StepPanel _MyStepPanel;
|
|
|
|
public StepPanel MyStepPanel
|
|
{
|
|
get { return _MyStepPanel; }
|
|
set { _MyStepPanel = value; }
|
|
}
|
|
private ChildRelation _MyChildRelation;
|
|
private RTBItem _MyParentRTBItem = null;
|
|
private RTBItem _MySectionRTBItem;
|
|
private RTBItem _MyPreviousRTBItem = null;
|
|
private RTBItem _MyNextRTBItem = null;
|
|
private bool _ChildrenLoaded = false;
|
|
public bool HasChildren
|
|
{
|
|
get {return _MyBeforeRTBItems != null || _MyRNORTBItems != null || _MyAfterRTBItems != null;}
|
|
}
|
|
private List<RTBItem> _MyBeforeRTBItems;
|
|
|
|
public List<RTBItem> MyBeforeRTBItems
|
|
{
|
|
get { return _MyBeforeRTBItems; }
|
|
set { _MyBeforeRTBItems = value; }
|
|
}
|
|
private List<RTBItem> _MyAfterRTBItems;
|
|
|
|
public List<RTBItem> MyAfterRTBItems
|
|
{
|
|
get { return _MyAfterRTBItems; }
|
|
set { _MyAfterRTBItems = value; }
|
|
}
|
|
private List<RTBItem> _MyRNORTBItems;
|
|
|
|
public List<RTBItem> MyRNORTBItems
|
|
{
|
|
get { return _MyRNORTBItems; }
|
|
set { _MyRNORTBItems = value; }
|
|
}
|
|
public Label MyLabel
|
|
{ get { return lblTab; } }
|
|
private StepSectionLayoutData _MyStepSectionLayoutData;
|
|
public StepSectionLayoutData MyStepSectionLayoutData
|
|
{
|
|
get { return _MyStepSectionLayoutData; }
|
|
set { _MyStepSectionLayoutData = value; }
|
|
}
|
|
private bool _Loading = true;
|
|
private StepData _MyStepData;
|
|
public StepData MyStepData
|
|
{
|
|
get { return _MyStepData; }
|
|
set { _MyStepData = value; }
|
|
}
|
|
private ItemInfo _MyItemInfo;
|
|
private static int _WidthAdjust = 3;
|
|
|
|
private int _ExpandPrefix = 0;
|
|
private int _ExpandSuffix = 0;
|
|
private ExpandingStatus _MyExpandingStatus = ExpandingStatus.No;
|
|
private bool _Colapsing = false;
|
|
private bool _Moving = false;
|
|
private int _RNOLevel = 0;
|
|
private int _SeqLevel = 0;
|
|
private int _Type;
|
|
private bool _Circle = false;
|
|
private bool _CheckOff = false;
|
|
private bool _ChangeBar = false;
|
|
|
|
#endregion
|
|
#region Properties
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
public RTBItem MySectionRTBItem
|
|
{
|
|
get
|
|
{
|
|
if (_MySectionRTBItem == null)
|
|
{
|
|
if (MyItemInfo.IsSection || MyItemInfo.IsProcedure) _MySectionRTBItem = this;
|
|
else _MySectionRTBItem = _MyParentRTBItem.MySectionRTBItem;
|
|
}
|
|
return _MySectionRTBItem;
|
|
}
|
|
set { _MySectionRTBItem = value; }
|
|
}
|
|
/// <summary>
|
|
/// Gets or Sets ItemInfo
|
|
/// </summary>
|
|
public ItemInfo MyItemInfo
|
|
{
|
|
get { return _MyItemInfo; }
|
|
set
|
|
{
|
|
_MyItemInfo = value;
|
|
if (VlnSettings.StepTypeToolType)SetToolTip(_MyItemInfo.ToolTip);
|
|
ChangeBar = _MyItemInfo.HasChangeBar;
|
|
value.MyContent.Changed += new ContentInfoEvent(MyContent_Changed);
|
|
value.OrdinalChanged += new ItemInfoEvent(value_OrdinalChanged);
|
|
}
|
|
}
|
|
void value_OrdinalChanged(object sender)
|
|
{
|
|
TabFormat = null; // Reset Tab
|
|
}
|
|
private 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 RTBItem ActiveParent
|
|
{
|
|
get { return _MyParentRTBItem!=null ? _MyParentRTBItem : _MyPreviousRTBItem.ActiveParent; }
|
|
}
|
|
void MyContent_Changed(object sender)
|
|
{
|
|
// Update the text to reflect the content change
|
|
MyStepRTB.MyItemInfo.RefreshItemAnnotations();
|
|
MyStepRTB.MyItemInfo=MyStepRTB.MyItemInfo; // Reset Text
|
|
SetExpandAndExpander(MyItemInfo);
|
|
// TODO: Need code to update tabs ? not sure what this is - maybe for
|
|
// transitions?
|
|
}
|
|
/// <summary>
|
|
/// Used to connect the RichTextBox with the menus and toolbars
|
|
/// </summary>
|
|
public StepRTB MyStepRTB
|
|
{
|
|
get { return _MyStepRTB; }
|
|
}
|
|
/// <summary>
|
|
/// Return the Parent RTBItem
|
|
/// </summary>
|
|
private RTBItem UpOneRTBItem
|
|
{
|
|
get
|
|
{
|
|
RTBItem tmp = this;
|
|
while (tmp != null && tmp.MyParentRTBItem == null) tmp = tmp.MyPreviousRTBItem;
|
|
if (tmp != null) return tmp.MyParentRTBItem;
|
|
return null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Sets the parent and postions the item with respect to the parent
|
|
/// </summary>
|
|
public RTBItem MyParentRTBItem
|
|
{
|
|
get { return _MyParentRTBItem; }
|
|
set
|
|
{
|
|
LastMethodsPush("set_MyParentRTBItem");
|
|
_MyParentRTBItem = value;
|
|
if (_MyParentRTBItem != 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)_MyParentRTBItem._Type;
|
|
|
|
switch (iType / 10000)
|
|
{
|
|
case 0: // Procedure
|
|
ItemLocation = new Point(_MyParentRTBItem.ItemLocation.X + 20, _MyParentRTBItem.Bottom);
|
|
ItemWidth = _MyStepPanel.ToDisplay(_MyStepSectionLayoutData.ColT) + _MyStepPanel.ToDisplay(_MyStepSectionLayoutData.WidT);
|
|
break;
|
|
case 1: // Section
|
|
if(this == TopMostRTBItem)
|
|
ItemLocation = new Point(_MyParentRTBItem.ItemLocation.X + 20, _MyParentRTBItem.Bottom);
|
|
else
|
|
TopMostRTBItem.ItemLocation = new Point(TopMostRTBItem.ItemLocation.X, _MyParentRTBItem.Bottom);
|
|
int borderWidth = _MyStepRTB.Width - _MyStepRTB.ClientRectangle.Width;
|
|
//TextWidth = _WidthAdjust + borderWidth + _MyStepPanel.ToDisplay(_MyStepSectionLayoutData.WidSTableEdit, Convert.ToInt32(_MyStepSectionLayoutData.PMode) - 1);
|
|
TextWidth = _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")
|
|
{
|
|
_MyStepRTB.Font = _MyStepData.Font.WindowsFont;
|
|
ItemWidth = (int)TableWidth(_MyStepRTB.Font, _MyItemInfo.MyContent.Text, true);
|
|
ItemLocation = new Point(50, _MyParentRTBItem.Bottom);
|
|
ItemLocation = TableLocation(_MyParentRTBItem, _MyStepSectionLayoutData, ItemWidth);
|
|
}
|
|
else
|
|
{
|
|
ItemLocation = new Point(_MyParentRTBItem.TextLeft, _MyParentRTBItem.Bottom);
|
|
ItemWidth = _MyParentRTBItem.TextWidth;
|
|
}
|
|
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;
|
|
TextWidth = _MyParentRTBItem.TextWidth;
|
|
_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 - _MyParentRTBItem.Width < 0) colR = _MyParentRTBItem.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(_MyParentRTBItem.ItemLeft + RNOLevel * colR, _MyParentRTBItem.Top);
|
|
int top = _MyParentRTBItem.FindTop(_MyParentRTBItem.Top);
|
|
if (top != _MyParentRTBItem.Top)
|
|
{
|
|
_MyParentRTBItem.LastMethodsPush(string.Format("set_MyParentRTBItem RNO Right {0}", MyID));
|
|
_MyParentRTBItem.Top = top;
|
|
_MyParentRTBItem.LastMethodsPop();
|
|
Top = top;
|
|
}
|
|
LastMethodsPop();
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
else
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
LastMethodsPush(string.Format("set_MyParentRTBItem RNO Below {0} {1} {2}", MyID, _MyParentRTBItem.BottomMostRTBItem.MyID, _MyParentRTBItem.BottomMostRTBItem.Bottom));
|
|
TextLocation = new Point(_MyParentRTBItem.TextLeft, _MyParentRTBItem.BottomMostRTBItem.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 = MyNextRTBItem == null ? _MyParentRTBItem.Top : MyNextRTBItem.Top;
|
|
Location = new Point(_MyParentRTBItem.Left + 20, FindTop(myTop));
|
|
_MyStepPanel.ItemMoving--;
|
|
//_MyParentRTBItem.Top = Bottom;
|
|
// Could be a Caution or Note - Need to get WidT
|
|
break;
|
|
}
|
|
}
|
|
LastMethodsPop();
|
|
}
|
|
}
|
|
private Stack<string> _LastMethods= new Stack<string>();
|
|
//private string _LastMethod = "";
|
|
private void LastMethodsPush(string str)
|
|
{
|
|
_MyStepPanel._LastAdjust = str;
|
|
_LastMethods.Push(str);
|
|
}
|
|
private string LastMethodsPop()
|
|
{
|
|
//_MyStepPanel._LastAdjust = "";
|
|
return _LastMethods.Pop();
|
|
}
|
|
private bool LastMethodsEmpty
|
|
{
|
|
get { return _LastMethods.Count == 0; }
|
|
}
|
|
/// <summary>
|
|
/// This should find the item that precedes the current item vertically
|
|
/// and then return the Bottom of that item.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private int FindTop(int bottom)
|
|
{
|
|
int lastBottomPrev = bottom; // This is necessary if the value of bottom can be negative.
|
|
if (_MyPreviousRTBItem != null)
|
|
lastBottomPrev = _MyPreviousRTBItem.BottomMostRTBItem.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);
|
|
}
|
|
/// <summary>
|
|
/// The left edge of the Tab
|
|
/// </summary>
|
|
public int ItemLeft
|
|
{
|
|
get { return Left + lblTab.Left; }
|
|
set { Left = value - lblTab.Left; }
|
|
}
|
|
/// <summary>
|
|
/// The Top of the RTBItem
|
|
/// </summary>
|
|
public int ItemTop
|
|
{
|
|
get { return Top; }
|
|
set
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
Top = value;
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// The Location of the Tab
|
|
/// </summary>
|
|
public Point ItemLocation
|
|
{
|
|
get { return new Point(Location.X + lblTab.Left, Location.Y); }
|
|
set { Location = new Point(value.X - lblTab.Left, value.Y); }
|
|
}
|
|
private int _RTBMargin = 3;
|
|
/// <summary>
|
|
/// Margin between the RTBItem and the StepRTB. Appears on the Right.
|
|
/// Will allow space to draw a Change Bar on the right side of the RTBItem.
|
|
/// </summary>
|
|
public int RTBMargin
|
|
{
|
|
get { return _RTBMargin; }
|
|
set { _RTBMargin = value; }
|
|
}
|
|
/// <summary>
|
|
/// Width of the Tab and RTB
|
|
/// </summary>
|
|
public int ItemWidth
|
|
{
|
|
get { return Width - lblTab.Left; }
|
|
set
|
|
{
|
|
Width = RTBMargin + value + lblTab.Left;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Width of the RichTextBox
|
|
/// </summary>
|
|
public int TextWidth
|
|
{
|
|
get { return _MyStepRTB.Width; }
|
|
set
|
|
{
|
|
Width = value + lblTab.Left + lblTab.Width;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Location of the RichTextBox
|
|
/// </summary>
|
|
public Point TextLocation
|
|
{
|
|
get { return new Point(Location.X + _MyStepRTB.Left, Location.Y); }
|
|
set { Location = new Point(value.X - _MyStepRTB.Left, value.Y); }
|
|
}
|
|
/// <summary>
|
|
/// Left edge of the RichTextBox
|
|
/// </summary>
|
|
public int TextLeft
|
|
{
|
|
get { return Left + _MyStepRTB.Left; }
|
|
}
|
|
/// <summary>
|
|
/// Tab Format used for outputing the Tab
|
|
/// </summary>
|
|
private string _TabFormat;
|
|
public string TabFormat
|
|
{
|
|
get
|
|
{
|
|
if (_TabFormat == null) TabFormat = null; // execute 'set' code.
|
|
return _TabFormat;
|
|
}
|
|
set
|
|
{
|
|
if (_MyItemInfo != null)
|
|
{
|
|
ItemInfo.ResetTabString(MyID);
|
|
string tabString = _MyItemInfo.MyTab.CleanText;
|
|
lblTab.Text = tabString;
|
|
lblTab.Width = tabString.Length * 8 * MyStepPanel.DPI / 96;// Adjust width for DPI
|
|
Invalidate();
|
|
_MyStepRTB.Left = lblTab.Left + lblTab.Width;// +2;
|
|
_MyStepRTB.Width = Width - _MyStepRTB.Left - RTBMargin;
|
|
_TabFormat = value; // tabString;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// This is the "number" of the item (1, 2, 3 etc.) for Substeps
|
|
/// </summary>
|
|
public int Ordinal
|
|
{
|
|
get
|
|
{
|
|
int count = 1;
|
|
for (RTBItem tmp = this; tmp.MyPreviousRTBItem != null; tmp = tmp.MyPreviousRTBItem) count++;
|
|
return count;
|
|
}
|
|
}
|
|
// hardcode to right for HLP. The change bar location from the format will need to be used to set this.
|
|
private E_ChangeBarPosition _ChangeBarPosition = E_ChangeBarPosition.Right;
|
|
public E_ChangeBarPosition ChangeBarPosition
|
|
{
|
|
get { return _ChangeBarPosition; }
|
|
set { _ChangeBarPosition = value; }
|
|
}
|
|
/// <summary>
|
|
/// Sets the previous item and adjusts locations
|
|
/// </summary>
|
|
public RTBItem MyPreviousRTBItem
|
|
{
|
|
get { return _MyPreviousRTBItem; }
|
|
set
|
|
{
|
|
LastMethodsPush("set_MyPreviousRTBItem");
|
|
_MyPreviousRTBItem = value;
|
|
if (_MyPreviousRTBItem != null)
|
|
{
|
|
_IgnoreResize=true;
|
|
if (_MyStepData != null && (_MyStepData.Type.ToLower().Contains("table") || _MyStepData.ParentType.ToLower().Contains("table")))
|
|
{
|
|
ItemWidth = (int)TableWidth(_MyStepRTB.Font, _MyItemInfo.MyContent.Text, true);
|
|
Location = new Point(_MyPreviousRTBItem.Left, FindTop(_MyPreviousRTBItem.BottomMostRTBItem.Bottom));
|
|
}
|
|
else if (value.MyItemInfo.IsTablePart)
|
|
{
|
|
ItemLocation = new Point(value.MyParentRTBItem.TextLeft, value.MyParentRTBItem.Bottom);
|
|
ItemWidth = value.MyParentRTBItem.TextWidth;
|
|
}
|
|
else
|
|
{
|
|
Width = MyPreviousRTBItem.Width;
|
|
if (TopMostRTBItem == this)
|
|
Location = new Point(_MyPreviousRTBItem.Left, FindTop(_MyPreviousRTBItem.BottomMostRTBItem.Bottom));
|
|
else
|
|
TopMostRTBItem.Location = new Point(TopMostRTBItem.Left, FindTop(_MyPreviousRTBItem.BottomMostRTBItem.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 (_MyPreviousRTBItem.MyNextRTBItem != this) _MyPreviousRTBItem.MyNextRTBItem = this;
|
|
}
|
|
LastMethodsPop();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Sets the next item and adjusts the location,
|
|
/// This also sets the previous for the "next" item
|
|
/// which adjusts other locations.
|
|
/// </summary>
|
|
public RTBItem MyNextRTBItem
|
|
{
|
|
get { return _MyNextRTBItem; }
|
|
set
|
|
{
|
|
_MyNextRTBItem = value;
|
|
if (_MyNextRTBItem != null)
|
|
{
|
|
if (_MyNextRTBItem.MyPreviousRTBItem != this)
|
|
{
|
|
_MyNextRTBItem.MyPreviousRTBItem = this;
|
|
MyNextRTBItem.Location = new Point(Left, Bottom);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// returns the TopMostChild
|
|
/// </summary>
|
|
public RTBItem TopMostRTBItem
|
|
{
|
|
get
|
|
{
|
|
if (Expanded && _MyBeforeRTBItems != null) return _MyBeforeRTBItems[0].TopMostRTBItem;
|
|
return this;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Returns the bottom location (Top + Height)
|
|
/// </summary>
|
|
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; }
|
|
}
|
|
/// <summary>
|
|
/// Bottom most child
|
|
/// </summary>
|
|
public RTBItem BottomMostRTBItem
|
|
{
|
|
get
|
|
{
|
|
RTBItem tmpr = null; // BottomMost RNO
|
|
//int rnoOffset = 0;
|
|
if ((MyExpandingStatus != ExpandingStatus.No || Expanded) && _MyRNORTBItems != null)
|
|
{
|
|
//rnoOffset = this.Top - _MyRNORTBItems[0].Top;
|
|
tmpr = _MyRNORTBItems[_MyRNORTBItems.Count - 1].BottomMostRTBItem;
|
|
}
|
|
RTBItem tmpa = this; // BottomMost After
|
|
if ((MyExpandingStatus != ExpandingStatus.No || Expanded) & _MyAfterRTBItems != null)
|
|
tmpa = _MyAfterRTBItems[_MyAfterRTBItems.Count - 1].BottomMostRTBItem;
|
|
// 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;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Bottom most child excluding RNOs
|
|
/// </summary>
|
|
public RTBItem BottomMostRTBItemNoRNOs
|
|
{
|
|
get
|
|
{
|
|
RTBItem tmpa = this; // BottomMost After
|
|
if ((MyExpandingStatus != ExpandingStatus.No || Expanded) & _MyAfterRTBItems != null)
|
|
tmpa = _MyAfterRTBItems[_MyAfterRTBItems.Count - 1].BottomMostRTBItem;
|
|
// return the bottom most
|
|
return tmpa;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// First sibling
|
|
/// </summary>
|
|
private RTBItem FirstSiblingRTBItem
|
|
{
|
|
get
|
|
{
|
|
RTBItem tmp = this;
|
|
while (tmp.MyPreviousRTBItem != null)
|
|
tmp = tmp.MyPreviousRTBItem;
|
|
return tmp;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Last sibling
|
|
/// </summary>
|
|
private RTBItem LastSiblingRTBItem
|
|
{
|
|
get
|
|
{
|
|
RTBItem tmp = this;
|
|
while (tmp.MyNextRTBItem != null)
|
|
tmp = tmp.MyNextRTBItem;
|
|
return tmp;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Returns the status of the vlnExpander unless it is in the process of expanding or collapsing
|
|
/// If it is colapsing it returns false
|
|
/// If it is expanding it returns true
|
|
/// </summary>
|
|
public bool Expanded
|
|
{
|
|
get
|
|
{
|
|
return !_Colapsing && (MyExpandingStatus != ExpandingStatus.No || _MyvlnExpander.Expanded);
|
|
}
|
|
set
|
|
{
|
|
_MyvlnExpander.Expanded = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Sets or Gets expanding status
|
|
/// </summary>
|
|
public ExpandingStatus MyExpandingStatus
|
|
{
|
|
get { return _MyExpandingStatus; }
|
|
set { _MyExpandingStatus = value; }
|
|
}
|
|
/// <summary>
|
|
/// Gets or sets colapsing
|
|
/// </summary>
|
|
public bool Colapsing
|
|
{
|
|
get { return _Colapsing; }
|
|
set { _Colapsing = value; }
|
|
}
|
|
/// <summary>
|
|
/// Gets or Sets the ability to expand
|
|
/// </summary>
|
|
public bool CanExpand
|
|
{
|
|
get { return _MyvlnExpander.Visible; }
|
|
set { _MyvlnExpander.Visible = value; }
|
|
}
|
|
/// <summary>
|
|
/// Gets the text from the content
|
|
/// </summary>
|
|
public string MyText
|
|
{
|
|
get { return _MyItemInfo == null ? null : _MyItemInfo.MyContent.Text; }
|
|
}
|
|
/// <summary>
|
|
/// Gets the ItemID from the ItemInfo
|
|
/// </summary>
|
|
public int MyID
|
|
{
|
|
get { return _MyItemInfo == null ? 0 : _MyItemInfo.ItemID; }
|
|
}
|
|
/// <summary>
|
|
/// Tracks when a RTBItem is moving
|
|
/// </summary>
|
|
public bool Moving
|
|
{
|
|
get { return _Moving; }
|
|
set { _Moving = value; }
|
|
}
|
|
/// <summary>
|
|
/// The RNO (Contingency) Level
|
|
/// </summary>
|
|
public int RNOLevel
|
|
{
|
|
get { return _RNOLevel; }
|
|
set { _RNOLevel = value; }
|
|
}
|
|
/// <summary>
|
|
/// Sequential Level - Only counts levels of Sequential substeps
|
|
/// </summary>
|
|
public int SeqLevel
|
|
{
|
|
get { return _SeqLevel; }
|
|
set { _SeqLevel = value; }
|
|
}
|
|
// TODO: This should be changed to get the Circle format from the data
|
|
/// <summary>
|
|
/// Show a circle or not
|
|
/// </summary>
|
|
public bool Circle
|
|
{
|
|
get { return _Circle; }
|
|
set { _Circle = value; }
|
|
}
|
|
// TODO: This should be changed to get the Checkoff status from the data
|
|
/// <summary>
|
|
/// Has a check-off or not
|
|
/// </summary>
|
|
public bool CheckOff
|
|
{
|
|
get { return _CheckOff; }
|
|
set { _CheckOff = value; }
|
|
}
|
|
// TODO: This should be changed to get the ChangeBar status from the data
|
|
/// <summary>
|
|
/// Has a changebar or not
|
|
/// </summary>
|
|
public bool ChangeBar
|
|
{
|
|
get { return _ChangeBar; }
|
|
set
|
|
{
|
|
_ChangeBar = value;
|
|
this.Invalidate();
|
|
}
|
|
}
|
|
#endregion // Properties
|
|
#region Constructors
|
|
public RTBItem(ItemInfo itemInfo, StepPanel myStepPanel, RTBItem myParentRTBItem, ChildRelation myChildRelation, bool expand)
|
|
{
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB Top");
|
|
InitializeComponent();// TODO: Performance 25%
|
|
SetupRTBItem(itemInfo, myStepPanel, myParentRTBItem, myChildRelation, expand, null);
|
|
}
|
|
public RTBItem(ItemInfo itemInfo, StepPanel myStepPanel, RTBItem myParentRTBItem, ChildRelation myChildRelation, bool expand, RTBItem nextRTBItem)
|
|
{
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB Top");
|
|
InitializeComponent();// TODO: Performance 25%
|
|
SetupRTBItem(itemInfo, myStepPanel, myParentRTBItem, myChildRelation, expand, nextRTBItem);
|
|
}
|
|
private void SetupRTBItem(ItemInfo itemInfo, StepPanel myStepPanel, RTBItem myParentRTBItem, ChildRelation myChildRelation, bool expand, RTBItem nextRTBItem)
|
|
{
|
|
//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
|
|
lblTab.Left = 20;
|
|
SetupHeader(itemInfo);
|
|
this.Paint += new PaintEventHandler(RTBItem_Paint);
|
|
this.BackColorChanged += new EventHandler(RTBItem_BackColorChanged);
|
|
if (itemInfo != null)
|
|
{
|
|
_Type = (int)itemInfo.MyContent.Type;
|
|
switch (_Type / 10000)
|
|
{
|
|
case 0: // Procedure
|
|
_MyStepRTB.Font = myStepPanel.ProcFont;// lblTab.Font = myStepPanel.ProcFont;
|
|
lblTab.Font = itemInfo.MyTab.MyFont.WindowsFont;
|
|
break;
|
|
case 1: // Section
|
|
_MyStepRTB.Font = myStepPanel.SectFont;// lblTab.Font = myStepPanel.SectFont;
|
|
lblTab.Font = itemInfo.MyTab.MyFont.WindowsFont;
|
|
break;
|
|
case 2: // Steps
|
|
_MyStepRTB.Font = myStepPanel.StepFont;//lblTab.Font = myStepPanel.StepFont;
|
|
lblTab.Font = itemInfo.MyTab.MyFont.WindowsFont;
|
|
_MyStepData = itemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList[_Type % 10000];
|
|
break;
|
|
}
|
|
//this.Move += new EventHandler(DisplayItem_Move);
|
|
}
|
|
else
|
|
{
|
|
if (myStepPanel.MyFont != null) _MyStepRTB.Font = lblTab.Font = myStepPanel.MyFont;
|
|
}
|
|
if (expand) _MyvlnExpander.ShowExpanded();
|
|
_MyStepPanel = myStepPanel;
|
|
if (itemInfo != null) myStepPanel._LookupRTBItems.Add(itemInfo.ItemID, this);
|
|
_MyChildRelation = myChildRelation;
|
|
if (myParentRTBItem != null) RNOLevel = myParentRTBItem.RNOLevel;
|
|
if (itemInfo != null)
|
|
{
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB before _Layout");
|
|
_MyStepSectionLayoutData = itemInfo.ActiveFormat.MyStepSectionLayoutData;
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB _Layout");
|
|
if (myParentRTBItem != null)
|
|
SeqLevel = myParentRTBItem.SeqLevel + ((myChildRelation == ChildRelation.After || myChildRelation == ChildRelation.Before) && itemInfo.IsSequential ? 1 : 0);
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB seqLevel");
|
|
MyItemInfo = itemInfo;
|
|
}
|
|
//// TIMING: DisplayItem.TimeIt("CSLARTB MyItem");
|
|
myStepPanel.Controls.Add(this);
|
|
|
|
switch (myChildRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
AddItem(myParentRTBItem, ref myParentRTBItem._MyAfterRTBItems,nextRTBItem);
|
|
break;
|
|
case ChildRelation.Before:
|
|
AddItem(myParentRTBItem, ref myParentRTBItem._MyBeforeRTBItems, nextRTBItem);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
RNOLevel = myParentRTBItem.RNOLevel + 1;
|
|
AddItem(myParentRTBItem, ref myParentRTBItem._MyRNORTBItems, nextRTBItem);
|
|
break;
|
|
case ChildRelation.None:
|
|
break;
|
|
}
|
|
if (itemInfo != null)
|
|
{
|
|
if (myChildRelation == ChildRelation.None)
|
|
{
|
|
if (_Type == 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 (myParentRTBItem == null)// If it is the top node
|
|
if (_Type >= 20000) // and it is a step - fully expand
|
|
Expand(true);
|
|
else // otherwise only expand one level
|
|
Expand(false);
|
|
}
|
|
//// 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");
|
|
}
|
|
private void SetExpandAndExpander(ItemInfo itemInfo)
|
|
{
|
|
// Don't allow substeps to expand
|
|
switch (_Type / 10000)
|
|
{
|
|
case 1: // Section can expand
|
|
CanExpand = true;
|
|
// If a word document set the expander to attachment
|
|
_MyvlnExpander.Attachment = !(itemInfo.IsStepSection);
|
|
//OLD: _MyvlnExpander.Attachment = (itemInfo.MyContent.ContentPartCount == 0);
|
|
break;
|
|
case 2: // High level steps with children can expand
|
|
CanExpand = itemInfo.IsHigh && itemInfo.HasChildren; // TemporaryFormat.IsHigh(item); ;
|
|
break;
|
|
default://Procedures cannot expand, because they automatically expand
|
|
CanExpand = false;
|
|
break;
|
|
}
|
|
}
|
|
private void SetupHeader(ItemInfo itemInfo)
|
|
{
|
|
lblTab.Top = 3 + ((itemInfo.HasHeader) ? 23 : 0);
|
|
_MyStepRTB.Top = lblTab.Top; // 3 + ((itemInfo.HasHeader) ? 23 : 0);
|
|
//lblTab.Move += new EventHandler(lblTab_Move);
|
|
if (itemInfo.HasHeader)
|
|
SetupHeaderFooter(ref lblHeader, "Header", itemInfo.MyHeader);
|
|
else
|
|
{
|
|
// remove header from screen if it exists:
|
|
this.Controls.Remove(lblHeader);
|
|
lblHeader = null;
|
|
}
|
|
}
|
|
private void SetupHeader()
|
|
{
|
|
SetupHeader(MyItemInfo);
|
|
LastMethodsPush("SetupHeader");
|
|
Height = _MyStepRTB.Height + _MyStepRTB.Top + 7;
|
|
LastMethodsPop();
|
|
}
|
|
void _MyStepRTB_Resize(object sender, EventArgs e)
|
|
{
|
|
// Console.WriteLine("Left {0} Width {1}", Left, Width);
|
|
}
|
|
|
|
private Label lblHeader = null;
|
|
private Label lblFooter = null;
|
|
private void SetupHeaderFooter(ref Label lbl, string name, MetaTag mTag)
|
|
{
|
|
if (lbl==null)lbl = new Label();
|
|
lbl.BackColor = System.Drawing.Color.Transparent;
|
|
lbl.Location = new System.Drawing.Point(0, 0);
|
|
lbl.Name = name;
|
|
lbl.Size = new System.Drawing.Size(this.Width, 23);
|
|
lbl.Visible = true;
|
|
lbl.Font = mTag.MyFont.WindowsFont;
|
|
lbl.Text = mTag.CleanText;
|
|
lbl.TextAlign = mTag.Justify;
|
|
this.Controls.Add(lbl);
|
|
}
|
|
#endregion
|
|
#region AddItem
|
|
/// <summary>
|
|
/// Adds an item to a list
|
|
/// </summary>
|
|
/// <param name="parentRTBItem">Parent Container</param>
|
|
/// <param name="siblingRTBItems">RTBItem List</param>
|
|
public void AddItem(RTBItem parentRTBItem, ref List<RTBItem> siblingRTBItems, RTBItem nextRTBItem)
|
|
{
|
|
if (siblingRTBItems == null) // Create a list of siblings
|
|
{
|
|
siblingRTBItems = new List<RTBItem>();
|
|
siblingRTBItems.Add(this);
|
|
MyParentRTBItem = parentRTBItem;
|
|
}
|
|
else // Add to the existing list
|
|
{
|
|
if (nextRTBItem == null) // Add to the end of the list
|
|
{
|
|
RTBItem lastChild = LastChild(siblingRTBItems);
|
|
siblingRTBItems.Add(this);
|
|
MyPreviousRTBItem = lastChild;
|
|
}
|
|
else // Add to the middle of the list before a particular item
|
|
{
|
|
RTBItem prevChild = nextRTBItem.MyPreviousRTBItem;
|
|
RTBItem parent = nextRTBItem.MyParentRTBItem;
|
|
siblingRTBItems.Insert(siblingRTBItems.IndexOf(nextRTBItem), this);
|
|
MyStepPanel.ItemMoving++;
|
|
_MyNextRTBItem = nextRTBItem;
|
|
nextRTBItem._MyPreviousRTBItem = this;
|
|
MyPreviousRTBItem = prevChild;// If a previous exists - this will adjust the location and width of the RTBItem
|
|
nextRTBItem.MyParentRTBItem = null;
|
|
MyParentRTBItem = parent; // If a parent exists - this will adjust the location and width of the RTBItem
|
|
//nextRTBItem.MyPreviousRTBItem = this;
|
|
MyStepPanel.ItemMoving--;
|
|
}
|
|
}
|
|
if (MyItemInfo.IsCaution || MyItemInfo.IsNote)
|
|
{
|
|
RTBItem prev = this;
|
|
while (prev.MyPreviousRTBItem != null) prev = prev.MyPreviousRTBItem;
|
|
prev.SetAllTabs();
|
|
}
|
|
else
|
|
SetAllTabs();
|
|
}
|
|
// clear tabs, clears then all so that next 'get' will calculate new.
|
|
public void SetAllTabs()
|
|
{
|
|
TabFormat = null; // reset TabFormat
|
|
SetupHeader();
|
|
if (_MyAfterRTBItems != null) foreach (RTBItem chld in _MyAfterRTBItems) chld.SetAllTabs();
|
|
if (_MyNextRTBItem != null) _MyNextRTBItem.SetAllTabs();
|
|
// Update the RNO tab if it exists - RHM 20100106
|
|
if (_MyRNORTBItems != null) foreach (RTBItem chld in _MyRNORTBItems) chld.SetAllTabs();
|
|
}
|
|
/// <summary>
|
|
/// Add the next item to a list
|
|
/// </summary>
|
|
/// <param name="myItemInfo"></param>
|
|
/// <param name="expand"></param>
|
|
/// <returns></returns>
|
|
//public RTBItem AddNext(ItemInfo myItemInfo, bool expand)
|
|
//{
|
|
// RTBItem tmp = new RTBItem(myItemInfo, _MyStepPanel, MyParentRTBItem, ChildRelation.None, expand);
|
|
// MyNextRTBItem = tmp;
|
|
// return tmp;
|
|
//}
|
|
#endregion
|
|
#region RemoveItem
|
|
protected void ShowTops(string title)
|
|
{
|
|
int TopMostY = TopMostRTBItem.Top;
|
|
int? TopMostParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.TopMostRTBItem.Top));
|
|
int? ParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.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.SelectedStepRTB = null; // Unselect the item to be deleted
|
|
//ShowTops("\r\n");
|
|
int TopMostYBefore = TopMostRTBItem.Top;
|
|
RTBItem newFocus = DeleteItem();
|
|
if (newFocus == null) return;
|
|
newFocus.MyStepRTB.Focus();
|
|
Dispose();
|
|
newFocus.SetAllTabs();
|
|
int TopMostYAfter = newFocus.TopMostRTBItem.Top;
|
|
if (TopMostYAfter > TopMostYBefore)
|
|
newFocus.TopMostRTBItem.Top = TopMostYBefore;
|
|
newFocus.AdjustLocation();
|
|
//newFocus.ShowTops("");
|
|
}
|
|
public RTBItem DeleteItem()
|
|
{
|
|
RTBItem newFocus = null;
|
|
int? TopMostParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.TopMostRTBItem.Top));
|
|
int? ParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.Top));
|
|
try
|
|
{
|
|
Item.DeleteItemAndChildren(MyItemInfo);
|
|
}
|
|
catch (System.Data.SqlClient.SqlException ex)
|
|
{
|
|
HandleSqlExceptionOnDelete(ex);
|
|
return null;
|
|
}
|
|
// Remove RTBItems
|
|
RemoveFromParentsChildList();
|
|
if (MyNextRTBItem != null)
|
|
{
|
|
if (MyPreviousRTBItem != null)
|
|
{
|
|
MyNextRTBItem.MyPreviousRTBItem = MyPreviousRTBItem;
|
|
MyPreviousRTBItem = null;
|
|
newFocus = MyNextRTBItem;
|
|
}
|
|
else
|
|
{
|
|
MyNextRTBItem.MyParentRTBItem = MyParentRTBItem;
|
|
MyParentRTBItem = null;
|
|
MyNextRTBItem.MyPreviousRTBItem = null;
|
|
newFocus = MyNextRTBItem;
|
|
}
|
|
// Adjust the vertical locations of all of the items below the item deleted
|
|
MyNextRTBItem.TopMostRTBItem.AdjustLocation();
|
|
MyNextRTBItem = null;
|
|
}
|
|
else if (MyPreviousRTBItem != null)
|
|
{
|
|
MyPreviousRTBItem.MyNextRTBItem = null;
|
|
newFocus = MyPreviousRTBItem;
|
|
MyPreviousRTBItem = null;
|
|
//Console.Write(",\"Previous\",");
|
|
}
|
|
else
|
|
{
|
|
newFocus = MyParentRTBItem;
|
|
MyParentRTBItem = 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
|
|
this.MyStepRTB.Focus();
|
|
}
|
|
}
|
|
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()
|
|
{
|
|
RTBItem top = this;
|
|
while (top.MyPreviousRTBItem != null) top = top.MyPreviousRTBItem;
|
|
RTBItem parentRTBItem = top.MyParentRTBItem;
|
|
if (parentRTBItem == null) return; // No parent, nothing to remove.
|
|
if (parentRTBItem.MyAfterRTBItems != null && parentRTBItem.MyAfterRTBItems.Contains(this))
|
|
{
|
|
parentRTBItem.MyAfterRTBItems.Remove(this);
|
|
if (parentRTBItem.MyAfterRTBItems.Count == 0)
|
|
parentRTBItem.MyAfterRTBItems = null;
|
|
}
|
|
else if (parentRTBItem.MyBeforeRTBItems != null && parentRTBItem.MyBeforeRTBItems.Contains(this))
|
|
{
|
|
parentRTBItem.MyBeforeRTBItems.Remove(this);
|
|
if(parentRTBItem.MyBeforeRTBItems.Count == 0)
|
|
parentRTBItem.MyBeforeRTBItems = null;
|
|
}
|
|
else if (parentRTBItem.MyRNORTBItems != null && parentRTBItem.MyRNORTBItems.Contains(this))
|
|
{
|
|
parentRTBItem.MyRNORTBItems.Remove(this);
|
|
if(parentRTBItem.MyRNORTBItems.Count == 0)
|
|
parentRTBItem.MyRNORTBItems = null;
|
|
}
|
|
if (parentRTBItem.MyAfterRTBItems == null && parentRTBItem.MyBeforeRTBItems == null && parentRTBItem.MyRNORTBItems == null)
|
|
parentRTBItem.CanExpand = false;
|
|
}
|
|
//private void ShowSiblings(string title)
|
|
//{
|
|
// Console.WriteLine("---{0} {1}---",title,MyID);
|
|
// RTBItem top = this;
|
|
// while (top.MyPreviousRTBItem != null) top = top.MyPreviousRTBItem;
|
|
// do
|
|
// {
|
|
// Console.WriteLine("{0} RTBItem - {1} {2}", top.MyID == MyID ? "*" : " ", top.MyID, top.MyItemInfo.MyContent.Text);
|
|
// top = top.MyNextRTBItem;
|
|
// } while (top != null);
|
|
//}
|
|
#endregion
|
|
#region Add Children
|
|
/// <summary>
|
|
/// Add a child before (Notes, Cautions, etc.)
|
|
/// </summary>
|
|
/// <param name="myItemInfo"></param>
|
|
/// <param name="expand"></param>
|
|
public void AddChildBefore(ItemInfo myItemInfo, bool expand)
|
|
{
|
|
RTBItem child = new RTBItem(myItemInfo, _MyStepPanel, this, ChildRelation.Before, expand);
|
|
}
|
|
/// <summary>
|
|
/// Add a list of children before
|
|
/// </summary>
|
|
/// <param name="myItemInfoList"></param>
|
|
/// <param name="expand"></param>
|
|
public void AddChildBefore(ItemInfoList myItemInfoList, bool expand)
|
|
{
|
|
if (myItemInfoList != null)
|
|
foreach (ItemInfo item in myItemInfoList)
|
|
AddChildBefore(item, expand);
|
|
}
|
|
/// <summary>
|
|
/// Add an RNO (Contingency) child
|
|
/// </summary>
|
|
/// <param name="myItemInfo"></param>
|
|
/// <param name="expand"></param>
|
|
public void AddChildRNO(ItemInfo myItemInfo, bool expand)
|
|
{
|
|
RTBItem child = new RTBItem(myItemInfo, _MyStepPanel, this, ChildRelation.RNO, expand);
|
|
}
|
|
/// <summary>
|
|
/// Add a list of RNO (Contingency) children
|
|
/// </summary>
|
|
/// <param name="myItemInfoList"></param>
|
|
/// <param name="expand"></param>
|
|
public void AddChildRNO(ItemInfoList myItemInfoList, bool expand)
|
|
{
|
|
if (myItemInfoList != null)
|
|
foreach (ItemInfo item in myItemInfoList)
|
|
AddChildRNO(item, expand);
|
|
}
|
|
/// <summary>
|
|
/// Add a child after
|
|
/// </summary>
|
|
/// <param name="MyItemInfo"></param>
|
|
/// <param name="expand"></param>
|
|
public RTBItem AddChildAfter(ItemInfo MyItemInfo, bool expand)
|
|
{
|
|
RTBItem child = new RTBItem(MyItemInfo, _MyStepPanel, this, ChildRelation.After, expand);
|
|
return child;
|
|
}
|
|
public RTBItem AddChildAfter(ItemInfo MyItemInfo, RTBItem nextRTBItem)
|
|
{
|
|
RTBItem child = new RTBItem(MyItemInfo, _MyStepPanel, this, ChildRelation.After, true, nextRTBItem);
|
|
return child;
|
|
}
|
|
public RTBItem AddChildBefore(ItemInfo MyItemInfo, RTBItem nextRTBItem)
|
|
{
|
|
RTBItem child = new RTBItem(MyItemInfo, _MyStepPanel, this, ChildRelation.Before, true, nextRTBItem);
|
|
return child;
|
|
}
|
|
public RTBItem AddChildRNO(ItemInfo MyItemInfo, RTBItem nextRTBItem)
|
|
{
|
|
RTBItem child = new RTBItem(MyItemInfo, _MyStepPanel, this, ChildRelation.RNO, true, nextRTBItem);
|
|
return child;
|
|
}
|
|
/// <summary>
|
|
/// Adds a sibling after the current RTBItem
|
|
/// </summary>
|
|
public void AddSiblingAfter()
|
|
{
|
|
AddSiblingAfter("",true);
|
|
}
|
|
public void AddSiblingAfter(string text,bool updateStatus)
|
|
{
|
|
MyStepRTB.SaveText();
|
|
ItemInfo newItemInfo = MyItemInfo.InsertSiblingAfter(text);
|
|
DoAddSiblingAfter(newItemInfo, updateStatus);
|
|
}
|
|
public void AddSiblingAfter(int? type, bool updateStatus)
|
|
{
|
|
MyStepRTB.SaveText();
|
|
ItemInfo newItemInfo = MyItemInfo.InsertSiblingAfter("","",type);
|
|
DoAddSiblingAfter(newItemInfo,updateStatus);
|
|
}
|
|
private void DoAddSiblingAfter(ItemInfo newItemInfo, bool updateStatus)
|
|
{
|
|
RTBItem newRTBItem = null;
|
|
switch (_MyChildRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
newRTBItem = ActiveParent.AddChildAfter(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
case ChildRelation.Before:
|
|
newRTBItem = ActiveParent.AddChildBefore(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
newRTBItem = ActiveParent.AddChildRNO(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
default: // Need debug
|
|
break;
|
|
}
|
|
//RTBItem newRTBItem = ActiveParent.AddChildAfter(newItemInfo, );
|
|
if(updateStatus)
|
|
_MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//Update Screen
|
|
}
|
|
private 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.
|
|
_MyStepRTB.SaveText();
|
|
ItemInfo newItemInfo = MyItemInfo.InsertSiblingBefore(text);
|
|
RTBItem newRTBItem=null;
|
|
switch (_MyChildRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
newRTBItem = ActiveParent.AddChildAfter(newItemInfo, this);
|
|
break;
|
|
case ChildRelation.Before:
|
|
newRTBItem = ActiveParent.AddChildBefore(newItemInfo, this);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
newRTBItem = ActiveParent.AddChildRNO(newItemInfo, this);
|
|
break;
|
|
default: // Need debug
|
|
break;
|
|
}
|
|
if(updateSelection)
|
|
_MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//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)
|
|
this.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
|
|
RTBItem nextItem = null;
|
|
if (newItemInfo.NextItem != null)
|
|
nextItem = MyStepPanel.FindItem(newItemInfo.NextItem);
|
|
else if (fromType == E_FromType.Table && MyAfterRTBItems != null)
|
|
nextItem = MyAfterRTBItems[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]);
|
|
RTBItem newRTBItem;
|
|
switch (fromType)
|
|
{
|
|
case E_FromType.Caution:
|
|
newRTBItem = this.AddChildBefore(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.Note:
|
|
newRTBItem = this.AddChildBefore(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.Procedure:
|
|
newRTBItem = this.AddChildAfter(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.RNO:
|
|
newRTBItem = this.AddChildRNO(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.Section:
|
|
newRTBItem = this.AddChildAfter(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.Step:
|
|
newRTBItem = this.AddChildAfter(newItemInfo, nextItem);
|
|
break;
|
|
case E_FromType.Table:
|
|
newRTBItem = this.AddChildAfter(newItemInfo, nextItem);
|
|
break;
|
|
default:
|
|
newRTBItem = this.AddChildAfter(newItemInfo, nextItem);
|
|
break;
|
|
}
|
|
_MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//Update Screen
|
|
}
|
|
/// <summary>
|
|
/// Add a list of children after
|
|
/// </summary>
|
|
/// <param name="myItemInfoList"></param>
|
|
/// <param name="expand"></param>
|
|
public RTBItem AddChildAfter(ItemInfoList myItemInfoList, bool expand)
|
|
{
|
|
RTBItem 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);
|
|
RTBItem newRTBItem = null;
|
|
switch (_MyChildRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
newRTBItem = ActiveParent.AddChildAfter(newItemInfo, this);
|
|
break;
|
|
case ChildRelation.Before:
|
|
newRTBItem = ActiveParent.AddChildBefore(newItemInfo, this);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
newRTBItem = ActiveParent.AddChildRNO(newItemInfo, this);
|
|
break;
|
|
default: // Need debug
|
|
break;
|
|
}
|
|
if (newRTBItem != null) _MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//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);
|
|
RTBItem newRTBItem = null;
|
|
switch (_MyChildRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
newRTBItem = ActiveParent.AddChildAfter(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
case ChildRelation.Before:
|
|
newRTBItem = ActiveParent.AddChildBefore(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
newRTBItem = ActiveParent.AddChildRNO(newItemInfo, MyNextRTBItem);
|
|
break;
|
|
default: // Need debug
|
|
break;
|
|
}
|
|
_MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//Update Screen
|
|
_MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.After, newItemInfo.MyContent.Type));
|
|
|
|
}
|
|
public RTBItem 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.SelectedStepRTB.Text == "")
|
|
MyStepPanel.SelectedStepRTB.Text = " ";
|
|
MyStepPanel.SelectedStepRTB = null; // Unselect the item to be deleted
|
|
ChildRelation childRelation = _MyChildRelation;
|
|
RTBItem newFocus = null;
|
|
RTBItem nextRTBItem = MyNextRTBItem;
|
|
RTBItem prevRTBItem = MyPreviousRTBItem;
|
|
RTBItem parentRTBItem = ActiveParent;
|
|
|
|
int TopMostYBefore = TopMostRTBItem.Top;
|
|
int? TopMostParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.TopMostRTBItem.Top));
|
|
int? ParentY = (MyParentRTBItem == null ? null : (int?)(MyParentRTBItem.Top));
|
|
ItemInfo newItemInfo = null;
|
|
try
|
|
{
|
|
newItemInfo = Item.PasteReplace(MyItemInfo, copyStartID);
|
|
}
|
|
catch (System.Data.SqlClient.SqlException ex)
|
|
{
|
|
HandleSqlExceptionOnDelete(ex);
|
|
return this;
|
|
}
|
|
// Remove the RTBItem that was the replaced item.
|
|
RemoveFromParentsChildList();
|
|
|
|
if (MyNextRTBItem != null)
|
|
{
|
|
if (MyPreviousRTBItem != null)
|
|
{
|
|
MyNextRTBItem.MyPreviousRTBItem = MyPreviousRTBItem;
|
|
MyPreviousRTBItem = null;
|
|
}
|
|
else
|
|
{
|
|
MyNextRTBItem.MyParentRTBItem = MyParentRTBItem;
|
|
MyParentRTBItem = null;
|
|
MyNextRTBItem.MyPreviousRTBItem = null;
|
|
}
|
|
MyNextRTBItem = null;
|
|
}
|
|
else if (MyPreviousRTBItem != null)
|
|
{
|
|
MyPreviousRTBItem.MyNextRTBItem = null;
|
|
newFocus = MyPreviousRTBItem;
|
|
MyPreviousRTBItem = null;
|
|
}
|
|
else
|
|
{
|
|
newFocus = MyParentRTBItem;
|
|
MyParentRTBItem = null;
|
|
}
|
|
|
|
// add copied item to ui where the replaced item was.
|
|
RTBItem newRTBItem = null;
|
|
switch (childRelation)
|
|
{
|
|
case ChildRelation.After:
|
|
newRTBItem = parentRTBItem.AddChildAfter(newItemInfo, nextRTBItem);
|
|
break;
|
|
case ChildRelation.Before:
|
|
newRTBItem = parentRTBItem.AddChildBefore(newItemInfo, nextRTBItem);
|
|
break;
|
|
case ChildRelation.RNO:
|
|
newRTBItem = parentRTBItem.AddChildRNO(newItemInfo, nextRTBItem);
|
|
break;
|
|
default: // Need debug
|
|
break;
|
|
}
|
|
_MyStepPanel.SelectedStepRTB = newRTBItem.MyStepRTB;//Update Screen
|
|
_MyStepPanel.MyStepTabPanel.MyDisplayTabControl.OnItemPaste(this, new vlnTreeItemInfoPasteEventArgs(newItemInfo, copyStartID, ItemInfo.EAddpingPart.Replace, newItemInfo.MyContent.Type));
|
|
return newRTBItem;
|
|
}
|
|
public void HighlightBackColor()
|
|
{
|
|
// Highlight all of the rtb's within this RTBItem:
|
|
if (MyAfterRTBItems != null)
|
|
{
|
|
foreach (RTBItem sia in MyAfterRTBItems)
|
|
{
|
|
sia.MyStepRTB.HighlightBackColor();
|
|
sia.HighlightBackColor();
|
|
}
|
|
}
|
|
if (MyBeforeRTBItems != null)
|
|
{
|
|
foreach (RTBItem sib in MyBeforeRTBItems)
|
|
{
|
|
sib.MyStepRTB.HighlightBackColor();
|
|
sib.HighlightBackColor();
|
|
}
|
|
}
|
|
if (MyRNORTBItems != null)
|
|
{
|
|
foreach (RTBItem sir in MyRNORTBItems)
|
|
{
|
|
sir.MyStepRTB.HighlightBackColor();
|
|
sir.HighlightBackColor();
|
|
}
|
|
}
|
|
}
|
|
public void SetBackColor()
|
|
{
|
|
// Set (removing highlighting) all of the rtb's within this RTBItem:
|
|
if (MyAfterRTBItems != null)
|
|
{
|
|
foreach (RTBItem sia in MyAfterRTBItems)
|
|
{
|
|
sia.MyStepRTB.SetBackColor();
|
|
sia.SetBackColor();
|
|
}
|
|
}
|
|
if (MyBeforeRTBItems != null)
|
|
{
|
|
foreach (RTBItem sib in MyBeforeRTBItems)
|
|
{
|
|
sib.MyStepRTB.SetBackColor();
|
|
sib.SetBackColor();
|
|
}
|
|
}
|
|
if (MyRNORTBItems != null)
|
|
{
|
|
foreach (RTBItem sir in MyRNORTBItems)
|
|
{
|
|
sir.MyStepRTB.SetBackColor();
|
|
sir.SetBackColor();
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region Event Handlers
|
|
/// <summary>
|
|
/// If the background changes, change the background of the RichTextBox
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void RTBItem_BackColorChanged(object sender, EventArgs e)
|
|
{
|
|
//_MyStepRTB.BackColor = BackColor;
|
|
_MyStepRTB.SetBackColor();
|
|
}
|
|
/// <summary>
|
|
/// When the RichTextBox height changes, change the height of the control to match
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void _StepRTB_HeightChanged(object sender, EventArgs args)
|
|
{
|
|
if (this.Height != _MyStepRTB.Height+_MyStepRTB.Top+7) // add in 7 to make it look good // + 10)
|
|
{
|
|
//if (MyID == 2131 || MyID == 2132)
|
|
// Console.WriteLine("oops!");
|
|
LastMethodsPush(string.Format("_StepRTB_HeightChanged {0}", _MyStepRTB.Height));
|
|
this.Height = _MyStepRTB.Height + _MyStepRTB.Top + 7;
|
|
LastMethodsPop();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Handle the colape event
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void vlnExp_BeforeColapse(object sender, vlnExpanderEventArgs args)
|
|
{
|
|
Cursor tmp = Cursor.Current;
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
int top = TopMostRTBItem.Top;// This does'nt work - this is since the last time it was expanded.
|
|
_Colapsing = true;
|
|
// Hide Children
|
|
HideChildren();
|
|
// Adjust Positions
|
|
_ExpandPrefix = Top - top;
|
|
_ExpandSuffix = BottomMostRTBItem.Bottom - Bottom;
|
|
if (Top != top)
|
|
{
|
|
LastMethodsPush(string.Format("Colapse {0}", MyID));
|
|
_MyStepPanel.ItemMoving++;
|
|
Top = top;
|
|
_MyStepPanel.ItemMoving--;
|
|
LastMethodsPop();
|
|
}
|
|
else
|
|
AdjustLocation();
|
|
BottomMostRTBItem.AdjustLocation();
|
|
_Colapsing = false;
|
|
Cursor.Current = tmp;
|
|
}
|
|
/// <summary>
|
|
/// Handle the expand event
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void vlnExp_BeforeExpand(object sender, vlnExpanderEventArgs args)
|
|
{
|
|
Cursor tmp = Cursor.Current;
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
if (!_Loading && MyExpandingStatus == ExpandingStatus.No)
|
|
Expand(_Type >= 20000);
|
|
Cursor.Current = tmp;
|
|
}
|
|
bool _IgnoreResize = false;
|
|
/// <summary>
|
|
/// Adjust the locations when the RTBItem is resized
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void RTBItem_Resize(object sender, EventArgs e)
|
|
{
|
|
if (_MyItemInfo == null) return;
|
|
if (_IgnoreResize) return;
|
|
AdjustLocation();
|
|
if (lblHeader != null) lblHeader.Width = this.Width;
|
|
}
|
|
private string WatchThisIndent
|
|
{
|
|
get { return "".PadLeft(_WatchThis, '\t'); }
|
|
}
|
|
/// <summary>
|
|
/// Handles movement of the RTBItems
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void RTBItem_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;
|
|
RTBItem tmp = (RTBItem)sender;
|
|
if (tmp._MyPreviousRTBItem == null && tmp._MyParentRTBItem == 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;
|
|
RTBItem btm = BottomMostRTBItem;
|
|
if(this != btm)
|
|
btm.AdjustLocation();
|
|
//if (_WatchThis > 0 && MyID > _StartingID)
|
|
//{
|
|
// Console.WriteLine("{0}Finish Move {1},{2}",WatchThisIndent, MyID, this);
|
|
//}
|
|
_WatchThis=watchThis;
|
|
}
|
|
private bool RNOBelow
|
|
{
|
|
get
|
|
{
|
|
if (_MyRNORTBItems != null)
|
|
{
|
|
return _MyRNORTBItems[0].RNOLevel > _MyItemInfo.ColumnMode;
|
|
//return _MyRNORTBItems[0].Left == Left;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
private bool RNORight
|
|
{
|
|
get
|
|
{
|
|
if (_MyRNORTBItems != null)
|
|
{
|
|
return _MyRNORTBItems[0].RNOLevel <= _MyItemInfo.ColumnMode;
|
|
//return _MyRNORTBItems[0].Left != Left;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
private void MoveRNO()
|
|
{
|
|
if (_MyRNORTBItems != null)
|
|
{
|
|
if (_MyRNORTBItems[0].TopMostRTBItem.Top != Top)
|
|
{
|
|
//if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("\r\n'Adjust RNO',{0},'Move',{1}", MyID, _RNO[0].MyID);
|
|
RTBItem rnoTop = _MyRNORTBItems[0].TopMostRTBItem;
|
|
if (rnoTop.RNOLevel <= _MyItemInfo.ColumnMode)
|
|
{
|
|
//RTBItem tmpBottom = this;
|
|
//if (_MyAfterRTBItems != null) tmpBottom = _MyAfterRTBItems[_MyAfterRTBItems.Count - 1].BottomMostRTBItem;
|
|
_MyStepPanel.ItemMoving++;
|
|
rnoTop.LastMethodsPush(string.Format("RTBItem_Move RNO Right {0}", rnoTop.MyID));
|
|
//rnoTop.Top = tmpBottom.Bottom;
|
|
rnoTop.Top = Top;
|
|
rnoTop.LastMethodsPop();
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
else
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
rnoTop.LastMethodsPush(string.Format("RTBItem_Move RNO Below {0} {1} {2}", rnoTop.MyID, BottomMostRTBItemNoRNOs.MyID, BottomMostRTBItemNoRNOs.Bottom));
|
|
rnoTop.Top = BottomMostRTBItemNoRNOs.Bottom;
|
|
rnoTop.LastMethodsPop();
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Handle the LinkGoTO event
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void _StepRTB_LinkGoTo(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
_MyLog.DebugFormat("_DisplayRTB_LinkGoTo " + args.LinkInfoText);
|
|
_MyStepPanel.OnLinkClicked(sender, args);
|
|
}
|
|
/// <summary>
|
|
/// Raises an ItemClick event when the user clicks on the Tab
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void lblTab_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
_MyStepPanel.OnItemClick(this, new StepPanelEventArgs(this, e));
|
|
}
|
|
/// <summary>
|
|
/// When a RichTextBox is entered, the selected StepRTB is set
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void _StepRTB_Enter(object sender, EventArgs e)
|
|
{
|
|
if (_MyStepPanel.DisplayItemChanging) return;
|
|
//vlnStackTrace.ShowStack("_StepRTB_Enter {0}",this.MyID);
|
|
_MyStepPanel.SelectedStepRTB = _MyStepRTB;
|
|
}
|
|
/// <summary>
|
|
/// Raise a OnLinkModifyTran event, when the user chooses to Modify a transition
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void _StepRTB_LinkModifyTran(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
_MyStepPanel.OnLinkModifyTran(sender, args);
|
|
}
|
|
/// <summary>
|
|
/// Raise a OnLinkModifyRO event, when the user chooses to modify an RO
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void _StepRTB_LinkModifyRO(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
_MyStepPanel.OnLinkModifyRO(sender, args);
|
|
}
|
|
/// <summary>
|
|
/// Pass the AttachmentClick event to the StepPanel control.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private void vlnExp_AttachmentClick(object sender, vlnExpanderEventArgs args)
|
|
{
|
|
_MyStepPanel.OnAttachmentClicked(sender, new StepPanelAttachmentEventArgs(this));
|
|
}
|
|
private void _MyStepRTB_CursorKeyPress(object sender, KeyEventArgs args)
|
|
{
|
|
_MyStepPanel.StepCursorKeys(sender as StepRTB, args);
|
|
}
|
|
private void _MyStepRTB_CursorMovement(object sender, StepRTBCursorMovementEventArgs args)
|
|
{
|
|
_MyStepPanel.CursorMovement(sender as StepRTB, args.CursorLocation, args.Key);
|
|
}
|
|
private void _MyStepRTB_ModeChange(object sender, StepRTBModeChangeEventArgs args)
|
|
{
|
|
_MyStepPanel.OnModeChange(sender as StepRTB, args);
|
|
}
|
|
#endregion // Event Handlers
|
|
#region Private Methods
|
|
/// <summary>
|
|
/// Finds the last child in a list
|
|
/// </summary>
|
|
/// <param name="childRTBItems"></param>
|
|
/// <returns></returns>
|
|
private static RTBItem LastChild(List<RTBItem> childRTBItems)
|
|
{
|
|
return childRTBItems[childRTBItems.Count - 1];
|
|
}
|
|
/// <summary>
|
|
/// Calculate TableWidth based upon the the contents
|
|
/// </summary>
|
|
/// <param name="myFont"></param>
|
|
/// <param name="txt"></param>
|
|
/// <param name="addBorder"></param>
|
|
/// <returns></returns>
|
|
public float TableWidth(Font myFont, string txt, bool addBorder)
|
|
{
|
|
string[] lines = txt.Split("\n".ToCharArray());
|
|
float max = 0;
|
|
using (Graphics g = this.CreateGraphics())
|
|
{
|
|
PointF pnt = new PointF(0, 0);
|
|
foreach (string line in lines)
|
|
{
|
|
string lineAdj = Regex.Replace(line, @"\\u....\?", "X"); // Replace Special characters
|
|
//line2 = Regex.Replace(line2, @"\\.*? ", ""); // Remove RTF Commands - Really should not be any
|
|
lineAdj = StepRTB.RemoveLinkComments(lineAdj);
|
|
// MeasureString doesn't work properly if the line include graphics characters.
|
|
// So, Measure a string of the same length with 'M's.
|
|
SizeF siz = g.MeasureString("".PadLeft(lineAdj.Length + (addBorder ? 2 : 0), 'M'), myFont, pnt, StringFormat.GenericTypographic);
|
|
float wid = siz.Width;
|
|
if (wid > max)
|
|
{
|
|
max = wid;
|
|
}
|
|
}
|
|
}
|
|
float widLimit = (float) _MyStepPanel.ToDisplay(_MyStepSectionLayoutData.WidSTableEdit, MyItemInfo.ColumnMode);
|
|
widLimit += (float)_MyStepPanel.ToDisplay(_MyStepSectionLayoutData.ColS);
|
|
widLimit += (float) _MyStepPanel.ToDisplay(_MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode);
|
|
max += _MyStepPanel.MyStepPanelSettings.TableWidthAdjust;
|
|
return Math.Min(max,widLimit);
|
|
}
|
|
/// <summary>
|
|
/// Calculates the table location
|
|
/// </summary>
|
|
/// <param name="myParentRTBItem"></param>
|
|
/// <param name="myStepSectionLayoutData"></param>
|
|
/// <param name="width"></param>
|
|
/// <returns></returns>
|
|
public Point TableLocation(RTBItem myParentRTBItem, StepSectionLayoutData myStepSectionLayoutData, int width)
|
|
{
|
|
// Should center on parent unless it is a centered table in the AER column
|
|
int center = myParentRTBItem.TextLeft + myParentRTBItem.TextWidth / 2;
|
|
int rightLimit = myParentRTBItem.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 -= (myParentRTBItem.TextLeft - (int)MyItemInfo.MyDocStyle.Layout.LeftMargin) / 2;
|
|
}
|
|
|
|
// Calulate the x location
|
|
//int x = myParentRTBItem.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(myParentRTBItem.Bottom);
|
|
return new Point(x, y);
|
|
}
|
|
/// <summary>
|
|
/// Sets the Item and as a result the text for the RichTextBox
|
|
/// </summary>
|
|
private void SetText()
|
|
{
|
|
LastMethodsPush("SetText");
|
|
if (_MyItemInfo != null)
|
|
this._MyStepRTB.MyItemInfo = _MyItemInfo;
|
|
LastMethodsPop();
|
|
}
|
|
/// <summary>
|
|
/// If the selected RTBItem is within the window leave it as it is.
|
|
/// If not, scroll so that the selected window is centered.
|
|
/// </summary>
|
|
private 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
|
|
}
|
|
// TODO: the format of the circles, Checkoffs and Changebars should come from the format file
|
|
/// <summary>
|
|
/// This adds drawing items to the RTBItem as needed including
|
|
/// Circle around the Tab Number
|
|
/// Check-Offs
|
|
/// Change Bars
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void RTBItem_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(lblTab.Text, MyItemInfo.MyTab.MyFont.WindowsFont, Brushes.Black, new RectangleF(new PointF(Convert.ToSingle(lblTab.Location.X), Convert.ToSingle(lblTab.Location.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, lblTab.Left + 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, _MyStepRTB.Top, 0, Height); // left, top, right, bottom.
|
|
else
|
|
{
|
|
g.DrawLine(penCB, Width-2, _MyStepRTB.Top, Width-2, Height);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Hide a Items Children - Part of colapsing
|
|
/// </summary>
|
|
protected void HideChildren()
|
|
{
|
|
HideChildren(_MyBeforeRTBItems);
|
|
HideChildren(_MyRNORTBItems);
|
|
HideChildren(_MyAfterRTBItems);
|
|
}
|
|
/// <summary>
|
|
/// Hide a list of children - Part of colapsing
|
|
/// </summary>
|
|
/// <param name="childRTBItems"></param>
|
|
private void HideChildren(List<RTBItem> childRTBItems)
|
|
{
|
|
if (childRTBItems != null)
|
|
{
|
|
foreach (RTBItem child in childRTBItems)
|
|
{
|
|
if (child.Expanded) child.HideChildren();
|
|
child.Hidden = true;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Unhide an items Children - Part of expanding
|
|
/// </summary>
|
|
/// <param name="expand"></param>
|
|
protected void UnhideChildren(bool expand)
|
|
{
|
|
UnhideChildren(_MyBeforeRTBItems, expand);
|
|
UnhideChildren(_MyRNORTBItems, expand);
|
|
UnhideChildren(_MyAfterRTBItems, expand);
|
|
if (!_MyvlnExpander.Expanded)
|
|
_MyvlnExpander.ShowExpanded();
|
|
}
|
|
/// <summary>
|
|
/// Unhide a list of children - part of expanding
|
|
/// </summary>
|
|
/// <param name="childRTBItems"></param>
|
|
/// <param name="expand"></param>
|
|
private void UnhideChildren(List<RTBItem> childRTBItems, bool expand)
|
|
{
|
|
if (childRTBItems != null)
|
|
{
|
|
foreach (RTBItem child in childRTBItems)
|
|
{
|
|
if (child.Expanded)
|
|
child.UnhideChildren(expand);
|
|
else if (expand)
|
|
child.Expand(expand);
|
|
child.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Move children as necessary
|
|
/// </summary>
|
|
protected void AdjustChildren()
|
|
{
|
|
AdjustChildren(_MyBeforeRTBItems);
|
|
AdjustChildren(_MyRNORTBItems);
|
|
AdjustChildren(_MyAfterRTBItems);
|
|
}
|
|
/// <summary>
|
|
/// Move a list of children
|
|
/// </summary>
|
|
/// <param name="childRTBItems"></param>
|
|
private void AdjustChildren(List<RTBItem> childRTBItems)
|
|
{
|
|
if (childRTBItems != null)
|
|
{
|
|
foreach (RTBItem child in childRTBItems)
|
|
{
|
|
child.AdjustLocation();
|
|
if (child.Expanded) child.AdjustChildren();
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Expand a list of children
|
|
/// </summary>
|
|
/// <param name="childRTBItems"></param>
|
|
private void ExpandChildren(List<RTBItem> childRTBItems)
|
|
{
|
|
if (childRTBItems != null)
|
|
{
|
|
foreach (RTBItem child in childRTBItems)
|
|
{
|
|
if (child.CanExpand)
|
|
{
|
|
child.Expand(true);
|
|
}
|
|
child.Hidden = false;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Expand children
|
|
/// </summary>
|
|
private void ExpandChildren()
|
|
{
|
|
// Walk though Children performing Expand
|
|
ExpandChildren(_MyBeforeRTBItems);
|
|
ExpandChildren(_MyRNORTBItems);
|
|
ExpandChildren(_MyAfterRTBItems);
|
|
}
|
|
private string MyPath
|
|
{
|
|
get
|
|
{
|
|
if (MyItemInfo.MyContent.Type >= 20000)
|
|
return MyItemInfo.Path.Substring(MyItemInfo.ActiveSection.Path.Length);
|
|
return MyItemInfo.MyContent.ToString();
|
|
}
|
|
}
|
|
private RTBItem AERRTBItem
|
|
{
|
|
get
|
|
{
|
|
if(RNOLevel == 0)return null;
|
|
if (MyParentRTBItem != null)
|
|
{
|
|
if (MyParentRTBItem.RNOLevel < RNOLevel)
|
|
return MyParentRTBItem;
|
|
else
|
|
return MyParentRTBItem.AERRTBItem;
|
|
}
|
|
else if (MyPreviousRTBItem != null)
|
|
{
|
|
return MyPreviousRTBItem.AERRTBItem;
|
|
}
|
|
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("'AERRTBItem',{0},{1}", MyID, MyItemInfo.DBSequence);
|
|
return null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Adjust the Location of all items below the current item.
|
|
/// </summary>
|
|
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 && AERRTBItem != null)
|
|
AERRTBItem.AdjustLocation();
|
|
RTBItem nextRTBItem = NextDownRTBItem;
|
|
//if (MyID == 2138)
|
|
// Console.WriteLine("2138");
|
|
//if (_WatchThis > 0 && MyID > _StartingID)
|
|
//if((nextRTBItem == null ? 0 : nextRTBItem.MyID) == MyID)
|
|
//if(_LookForID.Contains(MyID))
|
|
// Console.WriteLine("{0}AdjustLocation {1},{2},{3} -> {4},{5} ({6}) {7}", WatchThisIndent, MyID, MyItemInfo.Ordinal, MyPath,
|
|
// nextRTBItem == null ? 0 : nextRTBItem.MyID, nextRTBItem == null ? 0 : nextRTBItem.MyItemInfo.Ordinal, nextRTBItem == null ? "Null" : nextRTBItem.MyPath,
|
|
// _NextDownRTBItemPath);
|
|
//if (_WatchThis && MyID == 2119)
|
|
// Console.WriteLine("I'm here");
|
|
//if (MyID > 2120)
|
|
// Console.WriteLine("{0}\t{1}", MyID, nextRTBItem == null ? 0 : nextRTBItem.MyID);
|
|
if (nextRTBItem != null)
|
|
{
|
|
//int bottom = BottomMostRTBItem.Bottom;
|
|
if (nextRTBItem != null)
|
|
{
|
|
//if (MyID == 2123)
|
|
// _LookForID = 2123;
|
|
int bottom = nextRTBItem.FindTop(Bottom);
|
|
if (nextRTBItem.Top != bottom)
|
|
// if (nextRTBItem != null && !nextRTBItem.Moving && nextRTBItem.Top != bottom)
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
nextRTBItem.LastMethodsPush(string.Format("AdjustLocation {0}",MyID));
|
|
nextRTBItem._NextDownRTBItemPath = _NextDownRTBItemPath;
|
|
nextRTBItem.Top = bottom;
|
|
nextRTBItem.LastMethodsPop();
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("{0}** No Adjustment next = {1}, moving = {2}", WatchThisIndent, nextRTBItem, nextRTBItem == null ? false : nextRTBItem.Moving);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Automatically expands Steps if not currently expanded
|
|
/// </summary>
|
|
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(_Type >= 20000);
|
|
//Console.WriteLine("<AutoExpand ID {0} - Can {1} Expanded {2}",_MyItem.ItemID, CanExpand, Expanded);
|
|
}
|
|
}
|
|
#endregion // Private Methods
|
|
#region Public Methods
|
|
/// <summary>
|
|
/// Sets the focus to this RTBItem and positions the cursor to the begining of the string
|
|
/// </summary>
|
|
public void ItemSelect()
|
|
{
|
|
// Was getting an Error that _MyStepRTB was Disposed RHM 20101217
|
|
if (!_MyStepRTB.Disposing)
|
|
{
|
|
_MyStepRTB.Focus();
|
|
_MyStepRTB.Select(0, 0);
|
|
}
|
|
else
|
|
{
|
|
_MyLog.WarnFormat("Attempt to give Focus to Disposed Object {0}", MyID);
|
|
}
|
|
// if (CanExpand) AutoExpand(); // Expand the item if you can
|
|
ScrollToCenter();
|
|
}
|
|
/// <summary>
|
|
/// Sets the focus to this RTBItem
|
|
/// </summary>
|
|
public void ItemShow()
|
|
{
|
|
_MyStepRTB.Focus();
|
|
ScrollToCenter();
|
|
}
|
|
/// <summary>
|
|
/// Expand an item and it's children
|
|
/// <para/>If the children have been loaded then just expand them
|
|
/// <para/>If not, load the children and expand their children etc.
|
|
/// </summary>
|
|
/// <param name="expand">normally equal to _Type > = 20000 (Step)</param>
|
|
public void Expand(bool expand)
|
|
{
|
|
//// TIMING: DisplayItem.TimeIt("Expand Start");
|
|
if (_ChildrenLoaded)
|
|
{
|
|
// Unhide Children
|
|
MyExpandingStatus = ExpandingStatus.Showing;
|
|
UnhideChildren(expand);
|
|
if (_ExpandPrefix != 0)
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
TopMostRTBItem.Top = Top;
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
else
|
|
TopMostRTBItem.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);
|
|
if (!_MyvlnExpander.Expanded)
|
|
_MyvlnExpander.ShowExpanded();
|
|
}
|
|
MyExpandingStatus = ExpandingStatus.Done;
|
|
BottomMostRTBItem.AdjustLocation();
|
|
MyExpandingStatus = ExpandingStatus.No;
|
|
//// TIMING: DisplayItem.TimeIt("Expand End");
|
|
}
|
|
public RTBItem BeforeItem
|
|
{
|
|
get
|
|
{
|
|
if (_MyAfterRTBItems != null)
|
|
{
|
|
foreach (RTBItem RTBItem in _MyAfterRTBItems)
|
|
{
|
|
if (RTBItem._MyBeforeRTBItems != null)
|
|
return RTBItem.TopMostRTBItem;
|
|
RTBItem beforeItem = RTBItem.BeforeItem;
|
|
if (beforeItem != null) return beforeItem;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
public RTBItem ItemAbove
|
|
{
|
|
get
|
|
{
|
|
if (_MyChildRelation == ChildRelation.Before) return _MyParentRTBItem.ItemAbove;
|
|
if (_MyPreviousRTBItem != null) return _MyPreviousRTBItem.BottomMostRTBItem;
|
|
if (_MyChildRelation == ChildRelation.After) return _MyParentRTBItem;
|
|
if (_MyChildRelation == ChildRelation.RNO) return _MyParentRTBItem;
|
|
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 _MyRNORTBItems[0].FindRight();
|
|
}
|
|
public int? BottomOfParentRNO()
|
|
{
|
|
int? bottom = null;
|
|
RTBItem RTBItem = this;
|
|
if (!MyItemInfo.IsTablePart)
|
|
{
|
|
if (RTBItem._MyChildRelation == ChildRelation.None)
|
|
return null;
|
|
if (RTBItem._MyChildRelation == ChildRelation.After && !RNORight)
|
|
return null;
|
|
}
|
|
while (RTBItem != null && RTBItem._MyChildRelation != ChildRelation.None && RTBItem._MyChildRelation != ChildRelation.After)
|
|
RTBItem = RTBItem.UpOneRTBItem;
|
|
if (RTBItem == null || RTBItem._MyChildRelation == ChildRelation.None)
|
|
return null;
|
|
RTBItem parent = RTBItem.UpOneRTBItem;
|
|
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._MyRNORTBItems != null)
|
|
{
|
|
if (centeredTable || right > parent._MyRNORTBItems[0].Left)
|
|
{
|
|
if(parent._MyRNORTBItems[0].BottomMostRTBItem.RNOLevel > RNOLevel && RNOLevel < _MyItemInfo.ColumnMode)
|
|
bottom = max(bottom, parent._MyRNORTBItems[0].BottomMostRTBItem.Bottom);
|
|
}
|
|
}
|
|
parent = parent.UpOneRTBItem;
|
|
}
|
|
return bottom;
|
|
}
|
|
private string _NextDownRTBItemPath = "None";
|
|
/// <summary>
|
|
/// This finds the next RTBItem down.
|
|
/// </summary>
|
|
public RTBItem NextDownRTBItem
|
|
{
|
|
get
|
|
{
|
|
RTBItem RTBItem = this;
|
|
_NextDownRTBItemPath = "Path 1";
|
|
// If this item appears before it's parent, and it doesn't have anything below it, return the parent
|
|
if (MyNextRTBItem == null && MyAfterRTBItems == null && FirstSiblingRTBItem._MyChildRelation == ChildRelation.Before)
|
|
return UpOneRTBItem;
|
|
_NextDownRTBItemPath = "Path 2";
|
|
if (Expanded && _MyAfterRTBItems != null)// check to see if there is a _After
|
|
return MyAfterRTBItems[0].TopMostRTBItem;// if there is, go that way
|
|
_NextDownRTBItemPath = "Path 3";
|
|
if (Expanded && MyRNORTBItems != null && MyItemInfo.RNOLevel >= MyItemInfo.ColumnMode)// check to see if there is a _After
|
|
return MyRNORTBItems[0].TopMostRTBItem;// if there is, go that way
|
|
while (RTBItem != null && RTBItem.MyNextRTBItem == null) // if no Next walk up the parent path
|
|
{
|
|
bool lastWasRNO = (RTBItem._MyChildRelation == ChildRelation.RNO);
|
|
RTBItem = RTBItem.UpOneRTBItem;
|
|
_NextDownRTBItemPath = "Path 4";
|
|
if (RTBItem == null) // No Parent
|
|
return null;
|
|
_NextDownRTBItemPath = string.Format("Path 5 {0}, {1}",RTBItem.MyExpandingStatus,RTBItem.Moving);
|
|
if (RTBItem.MyExpandingStatus == ExpandingStatus.Expanding || RTBItem.Moving) // Parent Expanding or Moving - Wait
|
|
return null;
|
|
_NextDownRTBItemPath = "Path 5 RNO";
|
|
if (RTBItem.RNOBelow && !Ancestor(RTBItem.MyRNORTBItems[0]))
|
|
return RTBItem.MyRNORTBItems[0];
|
|
_NextDownRTBItemPath = "Path 6";
|
|
if (RTBItem.MyNextRTBItem == null && RTBItem.FirstSiblingRTBItem._MyChildRelation == ChildRelation.Before)
|
|
return RTBItem.UpOneRTBItem;
|
|
RTBItem btm = RTBItem.BottomMostRTBItem; // Find the Bottom RTBItem of this ancestor
|
|
RTBItem beforeItem = RTBItem.BeforeItem;
|
|
if (lastWasRNO && beforeItem != null)
|
|
{
|
|
_NextDownRTBItemPath = "Path 7";
|
|
if (beforeItem.ItemAbove.Bottom > this.Bottom) return null;
|
|
_NextDownRTBItemPath = "Path 8";
|
|
return beforeItem;
|
|
}
|
|
if (this != btm) // If this is not the bottom, then just adjust things with respect to the bottom
|
|
{
|
|
RTBItem btmNext = btm.NextDownRTBItem;
|
|
//if (RTBItem.MyNextRTBItem != null && RTBItem.MyNextRTBItem.TopMostRTBItem.Top != btm.Bottom)
|
|
if (btmNext != null)
|
|
{
|
|
int bottom = btmNext.FindTop(btm.Bottom);
|
|
if(btmNext.Top != bottom)
|
|
{
|
|
_MyStepPanel.ItemMoving++;
|
|
//RTBItem.MyNextRTBItem.TopMostRTBItem.Top = btm.Bottom;
|
|
//Console.WriteLine("{0}***Move in NextDownRTBItem {1},{2} From {3} To {4}",WatchThisIndent, btmNext.MyID, btmNext, btmNext.Top, btm.Bottom);
|
|
btmNext.LastMethodsPush(string.Format("NextDownRTBItem {0} {1}", MyID, RTBItem.MyID));
|
|
//ShowMe(string.Format("FindTop = {0}", btmNext.FindTop(btm.Bottom)));
|
|
btmNext.Top = bottom;
|
|
btmNext.LastMethodsPop();
|
|
_MyStepPanel.ItemMoving--;
|
|
}
|
|
}
|
|
_NextDownRTBItemPath = string.Format("Path 9 {0}",btm);
|
|
return null; // Not the bottom - don't adjust anything else
|
|
}
|
|
//else
|
|
//{
|
|
//}
|
|
}
|
|
if (RTBItem != null)
|
|
{
|
|
// Need to verify that the bottom of the parents RNO does not excede the bottom of this item.
|
|
RTBItem next = RTBItem.MyNextRTBItem.TopMostRTBItem;
|
|
_NextDownRTBItemPath = "Path A";
|
|
//if (Bottom >= (BottomOfParentRNO(next) ?? Bottom))
|
|
return next;// if no _After - check to see if there is a Next
|
|
//_NextDownRTBItemPath = "Path B";
|
|
//return null;
|
|
}
|
|
_NextDownRTBItemPath = "Path C";
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private bool Ancestor(RTBItem RTBItem)
|
|
{
|
|
if (MyID == RTBItem.MyID) return true;
|
|
if (MyItemInfo.IsHigh) return false;
|
|
return UpOneRTBItem.Ancestor(RTBItem);
|
|
}
|
|
public override string ToString()
|
|
{
|
|
return _MyItemInfo == null ? base.ToString() : string.Format("{0},'{1}'", MyID, MyPath); // + "-" + MyItemInfo.MyContent.Text;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|