This commit is contained in:
Kathy Ruffing 2011-02-08 11:32:53 +00:00
parent 989b5979a9
commit 7105a1cfb7
6 changed files with 1004 additions and 2581 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -19,21 +19,25 @@ namespace Volian.Controls.Library
/// Procedure Item Info - Top ItemInfo
/// </summary>
private ItemInfo _MyProcedureItemInfo;
private E_ViewMode _VwMode = E_ViewMode.Edit;
public E_ViewMode VwMode
{
get { return _VwMode; }
set { _VwMode = value; }
}
// TODO: This is not correct. There should be a dictionary of Section Layouts
/// <summary>
/// Lookup Table to convert ItemInfo.ItemID to RTBItem
/// Lookup Table to convert ItemInfo.ItemID to EditItem
/// </summary>
internal Dictionary<int, RTBItem> _LookupRTBItems;
public RTBItem FindItem(ItemInfo itemInfo)
internal Dictionary<int, EditItem> _LookupEditItems;
public EditItem FindItem(ItemInfo itemInfo)
{
if (itemInfo == null) return null;
if (!_LookupRTBItems.ContainsKey(itemInfo.ItemID)) return null;
return _LookupRTBItems[itemInfo.ItemID];
if (!_LookupEditItems.ContainsKey(itemInfo.ItemID)) return null;
return _LookupEditItems[itemInfo.ItemID];
}
/// <summary>
/// Currently selected RichTextBox
/// </summary>
private StepRTB _SelectedStepRTB = null;
/// <summary>
/// Currently selected ItemInfo
/// </summary>
@ -53,7 +57,7 @@ namespace Volian.Controls.Library
// Whether panel is in view or edit mode. Toggled from steprtb
// or set based on approval/multi-user (these two will be done
// later.
public E_ViewMode PanelViewEditMode = E_ViewMode.Edit;
//public E_ViewMode PanelViewEditMode = E_ViewMode.Edit;
internal string _LastAdjust="";
private bool _ShowLines = true;
private Graphics _MyGraphics = null;
@ -61,7 +65,7 @@ namespace Volian.Controls.Library
#endregion
#region Item Events
/// <summary>
/// Occurs when the user clicks tab of a RTBItem
/// Occurs when the user clicks tab of a EditItem
/// </summary>
public event StepPanelEvent ItemClick;
/// <summary>
@ -75,7 +79,7 @@ namespace Volian.Controls.Library
}
private bool ItemSelectionChangeShown = false; // This keeps OnItemSelectedChanged from being called twice when an item is selected.
/// <summary>
/// Occurs when the selected RTBItem changes
/// Occurs when the selected EditItem changes
/// </summary>
public event ItemSelectedChangedEvent ItemSelectedChanged;
/// <summary>
@ -101,16 +105,16 @@ namespace Volian.Controls.Library
internal void OnAttachmentClicked(object sender, StepPanelAttachmentEventArgs args)
{
if (AttachmentClicked != null) AttachmentClicked(sender, args);
else MessageBox.Show(args.MyRTBItem.MyItemInfo.MyContent.MyEntry.MyDocument.DocumentTitle, "Unhandled Attachment Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
else MessageBox.Show(args.MyEditItem.MyItemInfo.MyContent.MyEntry.MyDocument.DocumentTitle, "Unhandled Attachment Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
// Edit/View mode change
public event StepPanelModeChangeEvent ModeChange;
internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{
PanelViewEditMode = args.ViewMode;
ModeChange(sender, args);
}
//public event StepPanelModeChangeEvent ModeChange;
//internal void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
//{
// PanelViewEditMode = args.ViewMode;
// ModeChange(sender, args);
//}
// various selections from steptabribbon that need to filter up to frmveproms
// such as 'global search', 'bookmarks'
public event StepPanelTabDisplayEvent TabDisplay;
@ -262,10 +266,10 @@ namespace Volian.Controls.Library
InactiveColor = PanelColor = BackColor;
foreach (Control ctrl in Controls)
{
if (ctrl.GetType() == typeof(RTBItem))
if (ctrl is EditItem)
{
RTBItem rtb = (RTBItem)ctrl;
rtb.BackColor = BackColor;
EditItem ei = (EditItem)ctrl;
ei.BackColor = BackColor;
}
}
}
@ -278,11 +282,11 @@ namespace Volian.Controls.Library
private void ExpandAsNeeded(ItemInfo myItemInfo)
{
int id = myItemInfo.ItemID;
if (!_LookupRTBItems.ContainsKey(id)) // If the item is not currently displayed
if (!_LookupEditItems.ContainsKey(id)) // If the item is not currently displayed
ExpandAsNeeded((ItemInfo)myItemInfo.ActiveParent); // Expand it's parent
if (_LookupRTBItems.ContainsKey(id)) // Expanding Parent should have added it to _LookupRTBItems
if (_LookupEditItems.ContainsKey(id)) // Expanding Parent should have added it to _LookupEditItems
{
RTBItem itm = _LookupRTBItems[id];
EditItem itm = _LookupEditItems[id];
ItemInfo ii = myItemInfo.ActiveParent as ItemInfo;
if (itm.Visible == false && ii != null)
ExpandAsNeeded((ItemInfo)myItemInfo.ActiveParent);
@ -309,10 +313,10 @@ namespace Volian.Controls.Library
//this.Scroll += new ScrollEventHandler(DisplayPanel_Scroll);
//// TIMING: DisplayItem.TimeIt("pMyItem Scroll");
Controls.Clear();
_LookupRTBItems = new Dictionary<int, RTBItem>();
_LookupEditItems = new Dictionary<int, EditItem>();
//// TIMING: DisplayItem.TimeIt("pMyItem Clear");
//SuspendLayout();
RTBItem tmpRTBItem = new RTBItem(_MyProcedureItemInfo, this, null, ChildRelation.None, false);
new RTBItem(_MyProcedureItemInfo, this, null, ChildRelation.None, false);
//ResumeLayout();
//// TIMING: DisplayItem.TimeIt("pMyItem End");
}
@ -328,95 +332,14 @@ namespace Volian.Controls.Library
ExpandAsNeeded(SelectedItemInfo);
}
/// <summary>
/// Get or Set currently selected RichTextBox (StepRTB)
/// Currently selected StepRTB
/// </summary>
public StepRTB SelectedStepRTB
{
get { return _SelectedStepRTB; }
set
{
StepRTB lastRTB = _SelectedStepRTB;
if(value != null)
value.BackColor = ActiveColor; // Set the active color
if (lastRTB == value) return; // Same - No Change
//RHM ToDo: Why doesn't it have focus for copy Step/Paste
if (value != null) value.Focus();
if (lastRTB != null && lastRTB.BeingDisposed == false)
{
//_SelectedStepRTB.BackColor = InactiveColor;
//lastRTB.SetBackColor();
bool shouldDelete = !lastRTB.MyRTBItem.BeingRemoved && lastRTB.Text.Length == 0;
if (shouldDelete)
{
if (lastRTB.MyRTBItem.HasChildren)
{
if (value != null && value.MyItemInfo.HasAncestor(lastRTB.MyItemInfo))
{
shouldDelete = false;
}
else
{
DialogResult result = MessageBox.Show("This step does not have text but has substeps. Do you want to delete it and its substeps?", "Verify Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) shouldDelete = false;
}
}
}
if (shouldDelete)
{
float oldTop = lastRTB.MyRTBItem.Top;
RTBItem newFocus = lastRTB.MyRTBItem.DeleteItem();
float newTop = newFocus.Top;
lastRTB.MyRTBItem.Dispose();
newFocus.SetAllTabs();
// If the step being deleted appears above the step to recieve focus, find another step
// to use so that the steps are positioned properly (vertically)
if (oldTop < newTop)
{
if (newFocus.MyParentRTBItem != null)
{
if (newFocus.Top > newFocus.MyParentRTBItem.Top)
newFocus.MyParentRTBItem.AdjustLocation();
else if (newFocus.MyParentRTBItem.MyPreviousRTBItem != null &&
newFocus.Top > newFocus.MyParentRTBItem.MyPreviousRTBItem.Top)
newFocus.MyParentRTBItem.MyPreviousRTBItem.AdjustLocation();
else if (newFocus.MyParentRTBItem.MyParentRTBItem != null &&
newFocus.Top > newFocus.MyParentRTBItem.MyParentRTBItem.Top)
newFocus.MyParentRTBItem.MyParentRTBItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else if (newFocus.MyPreviousRTBItem != null)
newFocus.MyPreviousRTBItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else
newFocus.AdjustLocation();
}
else
{
lastRTB.SaveText(); // Save any changes to the text
lastRTB.SaveConfig(); // This may be redundant
//int selst = _SelectedStepRTB.SelectionStart;
lastRTB.RTBFillIn(false);
//_SelectedStepRTB.SetSelection(selst, 0);
//_SelectedStepRTB.SelectionStart=selst;
lastRTB.ViewRTB = true;
}
}
_SelectedStepRTB = value;
if (value != null)
{
_SelectedStepRTB.ViewRTB = PanelViewEditMode == E_ViewMode.View;
_SelectedStepRTB.RTBFillIn(PanelViewEditMode != E_ViewMode.View);
if (_SelectedItemInfo.ItemID != value.MyItemInfo.ItemID)
SelectedItemInfo = value.MyItemInfo;
}
if(lastRTB != null)
lastRTB.SetBackColor();
//vlnStackTrace.ShowStack("_DisplayRTB = {0}", _DisplayRTB.MyItem.ItemID);// Show StackTrace
}
}
//private StepRTB _SelectedStepRTB = null;
//public StepRTB SelectedStepRTB
//{
// get { return _SelectedStepRTB; }
// set { _SelectedStepRTB=value;}
//}
/// <summary>
/// Gets or Sets the SelectedItemInfo
/// Activates and Expands as necessary
@ -431,8 +354,8 @@ namespace Volian.Controls.Library
int id = value.ItemID;
ExpandAsNeeded(value);
// reset the entire step panel if the item isn't found.
if (!_LookupRTBItems.ContainsKey(id)) Reset();
RTBItem itm = _LookupRTBItems[id];
if (!_LookupEditItems.ContainsKey(id)) Reset();
EditItem itm = _LookupEditItems[id];
ItemSelectionChangeShown = false;//OnItemSelectedChanged has not run yet.
itm.ItemSelect();
if (!ItemSelectionChangeShown) OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(itm));
@ -446,21 +369,100 @@ namespace Volian.Controls.Library
set { _DisplayItemChanging = value; }
}
/// <summary>
/// Returns the SelectedRTBItem
/// Returns the SelectedEditItem
/// </summary>
public RTBItem SelectedRTBItem
private EditItem _SelectedEditItem;
public EditItem SelectedEditItem
{
get { return (_SelectedItemInfo != null) ? _LookupRTBItems[_SelectedItemInfo.ItemID] : null; }
get
{
return _SelectedEditItem;
//return (_SelectedItemInfo != null) ? _LookupEditItems[_SelectedItemInfo.ItemID] : null;
}
set
{
EditItem lastEI = _SelectedEditItem;
if (value != null) value.SetActive(); // Set the active color
if (lastEI == value) return; // Same - No Change
//RHM ToDo: Why doesn't it have focus for copy Step/Paste
if (value != null) value.SetFocus();
if (lastEI != null && lastEI.BeingDisposed == false)
{
bool shouldDelete = !lastEI.BeingRemoved && lastEI.Empty;
if (shouldDelete)
{
if (lastEI.HasChildren)
{
if (value != null && value.MyItemInfo.HasAncestor(lastEI.MyItemInfo))
{
shouldDelete = false;
}
else
{
DialogResult result = MessageBox.Show("This step does not have text but has substeps. Do you want to delete it and its substeps?", "Verify Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) shouldDelete = false;
}
}
}
if (shouldDelete)
{
float oldTop = lastEI.Top;
EditItem newFocus = lastEI.DeleteItem();
float newTop = newFocus.Top;
lastEI.Dispose();
newFocus.SetAllTabs();
// If the step being deleted appears above the step to recieve focus, find another step
// to use so that the steps are positioned properly (vertically)
if (oldTop < newTop)
{
if (newFocus.MyParentEditItem != null)
{
if (newFocus.Top > newFocus.MyParentEditItem.Top)
newFocus.MyParentEditItem.AdjustLocation();
else if (newFocus.MyParentEditItem.MyPreviousEditItem != null &&
newFocus.Top > newFocus.MyParentEditItem.MyPreviousEditItem.Top)
newFocus.MyParentEditItem.MyPreviousEditItem.AdjustLocation();
else if (newFocus.MyParentEditItem.MyParentEditItem != null &&
newFocus.Top > newFocus.MyParentEditItem.MyParentEditItem.Top)
newFocus.MyParentEditItem.MyParentEditItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else if (newFocus.MyPreviousEditItem != null)
newFocus.MyPreviousEditItem.AdjustLocation();
else
newFocus.AdjustLocation();
}
else
newFocus.AdjustLocation();
}
else
{
lastEI.SaveContents();
lastEI.RefreshDisplay(false);
}
}
_SelectedEditItem = value;
if (value != null)
{
_SelectedEditItem.RefreshDisplay(true);
if (_SelectedItemInfo.ItemID != value.MyItemInfo.ItemID)
SelectedItemInfo = value.MyItemInfo;
}
if (lastEI != null)
lastEI.IdentifyMe(false);
}
}
/// <summary>
/// Displays the selected RTBItem
/// Displays the selected EditItem
/// </summary>
public void ItemShow()
{
if (_SelectedItemInfo != null && SelectedRTBItem.MyStepRTB.BeingDisposed == false)
if (_SelectedItemInfo != null && SelectedEditItem.BeingDisposed == false)
{
SelectedRTBItem.ItemShow();
OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedRTBItem));
SelectedEditItem.ItemShow();
OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedEditItem));
}
}
public new void MouseWheel(MouseEventArgs e)
@ -675,18 +677,18 @@ namespace Volian.Controls.Library
}
}
/// <summary>
/// Output all of the RTBItem controls to the log
/// Output all of the EditItem controls to the log
/// </summary>
private void ListControls()
{
// Walk through the controls and find the next control for each
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("'Item','Next'");
foreach (Control control in Controls)
if (control.GetType() == typeof(RTBItem))
if (control is EditItem)
{
RTBItem rtb = (RTBItem)control;
RTBItem nxt = rtb.NextDownRTBItem;
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("{0},{1}", rtb.MyID, nxt == null ? 0 : nxt.MyID);
EditItem ei = (EditItem)control;
EditItem nxt = ei.NextDownEditItem;
if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("{0},{1}", ei.MyID, nxt == null ? 0 : nxt.MyID);
}
}
#endregion
@ -724,7 +726,7 @@ namespace Volian.Controls.Library
/// <param name="rtb">StepRTB</param>
/// <param name="position">Point</param>
/// <param name="arrow">E_ArrowKeys</param>
public void CursorMovement(StepRTB rtb, Point position, E_ArrowKeys arrow)
public void CursorMovement(EditItem ei, Point position, E_ArrowKeys arrow)
{
ItemInfo ii = null;
// The following lines are debug to check that the results of moving down and moving up are the same
@ -733,40 +735,40 @@ namespace Volian.Controls.Library
{
case E_ArrowKeys.Up:
case E_ArrowKeys.CtrlUp:
ii = ArrowUp(rtb.MyItemInfo);
ii = ArrowUp(ei.MyItemInfo);
// The following lines are debug to check that the results of moving down and moving up are the same
//ix = ArrowDown(ii);
//Console.WriteLine("'Up',{0},{1},{2},{3}", rtb.MyItemInfo.ItemID, rtb.MyItemInfo.DBSequence, ii.DBSequence, ix.DBSequence);
if (ii != null) SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
if (ii != null) SelectedEditItem = _LookupEditItems[ii.ItemID];
break;
case E_ArrowKeys.Down:
case E_ArrowKeys.CtrlDown:
ii = MoveDown(rtb, ii);
ii = MoveDown(ei, ii);
break;
case E_ArrowKeys.Right:
case E_ArrowKeys.CtrlRight:
if (rtb.MyItemInfo.RNOs != null)
SelectedStepRTB = _LookupRTBItems[rtb.MyItemInfo.RNOs[0].ItemID].MyStepRTB;
if (ei.MyItemInfo.RNOs != null)
SelectedEditItem = _LookupEditItems[ei.MyItemInfo.RNOs[0].ItemID];
else
ii = MoveDown(rtb, ii);
ii = MoveDown(ei, ii);
break;
case E_ArrowKeys.Left:
case E_ArrowKeys.CtrlLeft:
if (!rtb.MyItemInfo.IsProcedure)
SelectedStepRTB = _LookupRTBItems[rtb.MyItemInfo.MyParent.ItemID].MyStepRTB;
if (!ei.MyItemInfo.IsProcedure)
SelectedEditItem = _LookupEditItems[ei.MyItemInfo.MyParent.ItemID];
break;
default:
break;
}
}
private ItemInfo MoveDown(StepRTB rtb, ItemInfo ii)
private ItemInfo MoveDown(EditItem ei, ItemInfo ii)
{
ii = ArrowDown(rtb.MyItemInfo);
ii = ArrowDown(ei.MyItemInfo);
// The following lines are debug to check that the results of moving down and moving up are the same
//ix = ArrowUp(ii);
//Console.WriteLine("'Down',{0},{1},{2},{3}", rtb.MyItemInfo.ItemID, rtb.MyItemInfo.DBSequence, ii.DBSequence, ix.DBSequence);
if (ii != null) SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
if (ii != null) SelectedEditItem = _LookupEditItems[ii.ItemID];
return ii;
}
private ItemInfo ArrowUp(ItemInfo ii)
@ -831,9 +833,9 @@ namespace Volian.Controls.Library
}
return null;
}
internal void StepCursorKeys(StepRTB rtb, KeyEventArgs keyargs)
internal void StepCursorKeys(EditItem ei, KeyEventArgs keyargs)
{
ItemInfo ii = rtb.MyItemInfo;
ItemInfo ii = ei.MyItemInfo;
if (ii.IsSection || ii.IsProcedure) return;
while (!ii.IsHigh)
{
@ -857,7 +859,7 @@ namespace Volian.Controls.Library
break;
}
if (ii == null) return;
SelectedStepRTB = _LookupRTBItems[ii.ItemID].MyStepRTB;
SelectedEditItem = _LookupEditItems[ii.ItemID];
}
#endregion
}
@ -1019,11 +1021,11 @@ namespace Volian.Controls.Library
}
public partial class StepPanelEventArgs
{
private RTBItem _MyRTBItem;
public RTBItem MyRTBItem
private EditItem _MyEditItem;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
private MouseEventArgs _MyMouseEventArgs;
public MouseEventArgs MyMouseEventArgs
@ -1032,9 +1034,9 @@ namespace Volian.Controls.Library
set { _MyMouseEventArgs = value; }
}
public StepPanelEventArgs(RTBItem myRTBItem, MouseEventArgs myMouseEventArgs)
public StepPanelEventArgs(EditItem myEditItem, MouseEventArgs myMouseEventArgs)
{
_MyRTBItem = myRTBItem;
_MyEditItem = myEditItem;
_MyMouseEventArgs = myMouseEventArgs;
}
}
@ -1046,45 +1048,44 @@ namespace Volian.Controls.Library
get { return _MyItemInfo; }
set { _MyItemInfo = value; }
}
private RTBItem _MyRTBItem = null;
public RTBItem MyRTBItem
private EditItem _MyEditItem = null;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
public ItemSelectedChangedEventArgs(ItemInfo myItemInfo)
{
_MyItemInfo = myItemInfo;
}
public ItemSelectedChangedEventArgs(RTBItem myRTBItem)
public ItemSelectedChangedEventArgs(EditItem myEditItem)
{
_MyItemInfo = myRTBItem.MyItemInfo;
_MyRTBItem = myRTBItem;
_MyItemInfo = myEditItem.MyItemInfo;
_MyEditItem = myEditItem;
}
}
public partial class StepPanelAttachmentEventArgs
{
private RTBItem _MyRTBItem;
public RTBItem MyRTBItem
private EditItem _MyEditItem;
public EditItem MyEditItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
get { return _MyEditItem; }
set { _MyEditItem = value; }
}
public StepPanelAttachmentEventArgs(RTBItem myRTBItem)
public StepPanelAttachmentEventArgs(EditItem myEditItem)
{
_MyRTBItem = myRTBItem;
_MyEditItem = myEditItem;
}
}
public partial class StepPanelLinkEventArgs : EventArgs
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private RTBItem _LinkedRTBItem;
public RTBItem LinkedRTBItem
{
get { return _LinkedRTBItem; }
//set { _LinkedRTBItem = value; }
}
//private EditItem _LinkedEditItem;
//public EditItem LinkedEditItem
//{
// get { return _LinkedEditItem; }
//}
private string _LinkInfoText;
public string LinkInfoText
{
@ -1095,9 +1096,9 @@ namespace Volian.Controls.Library
{
get { return _MyLinkText;}
}
public StepPanelLinkEventArgs(RTBItem linkedRTBItem, string linkInfoText)
public StepPanelLinkEventArgs(string linkInfoText)
{
_LinkedRTBItem = linkedRTBItem;
//_LinkedEditItem = linkedEditItem;
_LinkInfoText = linkInfoText;
_MyLinkText = new LinkText(_LinkInfoText);
//if(_MyLog.IsInfoEnabled)_MyLog.InfoFormat("\r\n LinkInfo '{0}'\r\n", linkInfo.LinkText);

View File

@ -15,11 +15,11 @@ namespace Volian.Controls.Library
{
if (disposing && (components != null))
{
SelectedStepRTB = null; // Save Changes
foreach (RTBItem RTBItem in _LookupRTBItems.Values)
SelectedEditItem = null; // Save Changes
foreach (EditItem EditItem in _LookupEditItems.Values)
{
RTBItem.MyItemInfo.ResetParts();
RTBItem.MyItemInfo.MyContent.RefreshContentParts();
EditItem.MyItemInfo.ResetParts();
EditItem.MyItemInfo.MyContent.RefreshContentParts();
}
components.Dispose();
}

View File

@ -17,10 +17,82 @@ namespace Volian.Controls.Library
public delegate void StepRTBCursorKeysEvent(object sender, KeyEventArgs args);
public delegate void StepRTBCursorMovementEvent(object sender, StepRTBCursorMovementEventArgs args);
public delegate void StepRTBModeChangeEvent(object sender, StepRTBModeChangeEventArgs args);
public delegate void StepRTBMenuEvent(object sender, StepRTBMenuEventArgs args);
public delegate void StepRTBTableWidthEvent(object sender, StepRTBTableWidthEventArgs args);
public delegate bool StepRTBBooleanEvent(object sender, EventArgs args);
public delegate void StepRTBLocationEvent(object sender, StepRTBLocationEventArgs args);
public delegate void StepRTBMouseEvent(object sender, MouseEventArgs args);
//public delegate void StepRTBMouseWheelEvent(object sender, MouseEventArgs args);
public partial class StepRTB : RichTextBox , IStepRTB
public partial class StepRTB : RichTextBox // , IStepRTB
{
#region Events
public event StepRTBEvent ReturnToEditor;
public void OnReturnToEditor(object sender, EventArgs args)
{
if (ReturnToEditor != null) ReturnToEditor(sender, args);
}
public event StepRTBEvent EditModeChanged;
public void OnEditModeChanged(object sender, EventArgs args)
{
if (EditModeChanged != null) EditModeChanged(sender, args);
}
public event StepRTBEvent DoSaveContents;
public void OnDoSaveContents(object sender, EventArgs args)
{
if (DoSaveContents != null) DoSaveContents(sender, args);
}
public event StepRTBMouseEvent DoMouseWheel;
public void OnDoMouseWheel(object sender, MouseEventArgs args)
{
if (DoMouseWheel != null) DoMouseWheel(sender, args);
}
public event StepRTBLocationEvent OpenContextMenu;
public void OnOpenContextMenu(object sender, StepRTBLocationEventArgs args)
{
if (OpenContextMenu != null) OpenContextMenu(sender, args);
}
public event StepRTBEvent CopyStep;
public void OnCopyStep(object sender, EventArgs args)
{
if (CopyStep != null) CopyStep(sender, args);
}
public event StepRTBBooleanEvent CheckClipboard;
public bool OnCheckClipboard(object sender, EventArgs args)
{
if (CheckClipboard != null) return CheckClipboard(sender, args);
return false;
}
public event StepRTBCursorKeysEvent EnterKeyPressed;
public void OnEnterKeyPressed(object sender, KeyEventArgs args)
{
if (EnterKeyPressed != null) EnterKeyPressed(sender, args);
}
public event StepRTBEvent InsertPgBrk;
public void OnInsertPgBrk(object sender, EventArgs args)
{
if (InsertPgBrk != null) InsertPgBrk(sender, args);
}
public event StepRTBEvent OpenAnnotations;
public void OnOpenAnnotations(object sender, EventArgs args)
{
if (OpenAnnotations != null) OpenAnnotations(sender, args);
}
public event StepRTBBooleanEvent IsNotCurrentSelection;
public bool OnIsNotCurrentSelection(object sender, EventArgs args)
{
if (IsNotCurrentSelection != null) return IsNotCurrentSelection(sender, args);
return false;
}
public event StepRTBTableWidthEvent AdjustTableWidth;
public void OnAdjustTableWidth(object sender, StepRTBTableWidthEventArgs args)
{
if (AdjustTableWidth != null) AdjustTableWidth(sender, args);
}
public event StepRTBMenuEvent SetMenu;
private void OnSetMenu(object sender, StepRTBMenuEventArgs args)
{
if (SetMenu != null) SetMenu(sender, args);
}
public event StepRTBEvent RTBSelectionChanged;
private void OnRTBSelectionChanged(object sender, EventArgs args)
{
@ -46,13 +118,13 @@ namespace Volian.Controls.Library
{
if (CursorMovement != null) CursorMovement(sender, args);
}
public event StepRTBModeChangeEvent ModeChange;
private void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
{
//_MyModeChangeEventArgs = args;
if (ModeChange != null) ModeChange(sender, args);
else MessageBox.Show("StepRTB - no mode change defined");
}
//public event StepRTBModeChangeEvent ModeChange;
//private void OnModeChange(object sender, StepRTBModeChangeEventArgs args)
//{
// //_MyModeChangeEventArgs = args;
// if (ModeChange != null) ModeChange(sender, args);
// else MessageBox.Show("StepRTB - no mode change defined");
//}
//public event StepRTBMouseWheelEvent MouseWheel;
//private void OnMouseWheel(object sender, MouseEventArgs args)
//{
@ -69,6 +141,19 @@ namespace Volian.Controls.Library
}
#endregion
#region Properties and Variables
private bool _EditMode = true;
/// <summary>
/// Allows insert of links. If false, don't allow selection of links.
/// </summary>
public bool EditMode
{
get { return _EditMode; }
set
{
_EditMode = value;
OnEditModeChanged(this, new EventArgs());
}
}
private static FontFamily _MyFontFamily = null;
public static FontFamily MyFontFamily
{
@ -103,15 +188,15 @@ namespace Volian.Controls.Library
{
get
{
return _RtfPrefix + @"\f1\fs" + this.Font.SizeInPoints * 2 + " ";
if (_RtfPrefix == null)
{
StringBuilder selectedRtfSB = new StringBuilder();
AddFontTable(selectedRtfSB, FormatFont, FontIsFixed(FormatFont));
_RtfPrefix = selectedRtfSB.ToString();
}
return _RtfPrefix + @"\f1\fs" + FormatFont.SizeInPoints * 2 + " ";
}
}
private RTBItem _MyRTBItem;
public RTBItem MyRTBItem
{
get { return _MyRTBItem; }
set { _MyRTBItem = value; }
}
// August 5, 2009 - KBR & RHM:
// Insert/Overwrite will be developed later if needed. various issues
// were found during initial development that made its scope larger than
@ -124,9 +209,9 @@ namespace Volian.Controls.Library
// private bool _OverWrite;
// _IsDirty compares the original rtf to the current rtf from the
// richtextbox to see if a change was made.
private bool _IsDirty
public bool IsDirty
{
get { return _origRTF != Rtf; }
get { return OrigRTF != Rtf; }
}
private bool _InitializingRTB;
private IContainer _Container = null;
@ -136,12 +221,14 @@ namespace Volian.Controls.Library
get { if (_MyClassName == string.Empty)_MyClassName = CreateParams.ClassName; return _MyClassName; }
set { _MyClassName = value; }
}
private E_EditPrintMode _epMode = E_EditPrintMode.Edit;
public E_EditPrintMode EpMode
{
get { return _epMode; }
set { _epMode = value; }
}
//private E_EditPrintMode _epMode = E_EditPrintMode.Edit;
//public E_EditPrintMode EpMode
//{
// get { return _epMode; }
// set {
// if (value == E_EditPrintMode.Print) Console.WriteLine("");
// _epMode = value; }
//}
private E_ViewMode _vwMode = E_ViewMode.Edit;
public E_ViewMode VwMode
{
@ -151,76 +238,73 @@ namespace Volian.Controls.Library
private VE_Font _MyStyleFont;
public VE_Font MyStyleFont
{
get { return _origDisplayText.TextFont; }
get
{
if (_MyStyleFont == null) _MyStyleFont = MyItemInfo.GetItemFont();
return _MyStyleFont;
}
}
private bool _ActiveMode = false;
public bool ActiveMode
{
get { return _ActiveMode; }
set { _ActiveMode = value; }
}
public bool ViewRTB = true;
private ItemInfo _MyItemInfo;
public ItemInfo MyItemInfo
{
get { return _MyItemInfo; }
set
set { _MyItemInfo = value; }
}
private string _OrigRTF;
public string OrigRTF
{
get { return _OrigRTF; }
set { _OrigRTF = value; }
}
private Font _FormatFont;
public Font FormatFont
{
get
{
_MyItemInfo = value;
if (value != null)
if (_FormatFont == null)
{
RTBFillIn(!ViewRTB);
SetBackColor();
//ViewRTB = MyRTBItem.MyStepPanel.PanelViewEditMode == E_ViewMode.View;
Font formatFont = MyItemInfo.GetItemFont().WindowsFont; // OrigDisplayText.TextFont.WindowsFont;
if (MyItemInfo.IsTable || MyItemInfo.IsFigure)
_FormatFont = formatFont;
else
{
if (VlnSettings.DebugMode || VlnSettings.ProductionMode)
_FormatFont = new Font(_MyFontFamily == null ? formatFont.FontFamily : _MyFontFamily, formatFont.Size, formatFont.Style);
else
_FormatFont = new Font("Bookman Old Style", formatFont.Size, formatFont.Style);
// TODO: Release Mode
//Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format
}
}
return _FormatFont;
}
}
public void SetBackColor()
public void RefreshDisplay()
{
if (MyRTBItem == null || MyRTBItem.MyStepPanel == null) return;
if (Focused) // If active Set BackColor to the active color
BackColor = MyRTBItem.MyStepPanel.ActiveColor;
else // Otherwise Set the BackColor to either the InactiveColor or the AnnotationColor
BackColor = _MyItemInfo.ItemAnnotationCount == 0 ? MyRTBItem.MyStepPanel.InactiveColor : MyRTBItem.MyStepPanel.AnnotationColor;
RefreshDisplay(ActiveMode);
}
public void HighlightBackColor()
// RefreshDisplay is used to update the rtb for an entire Item as defined by MyItemInfo.
public void RefreshDisplay(bool activeMode)
{
// Don't try to highlight if this rtb is used on property pages.
if (MyRTBItem == null || MyRTBItem.MyStepPanel == null) return;
BackColor = Color.Gray;
}
private string _origRTF;
public void RTBFillIn(bool edit)
{
if (edit && _MyRTBItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure))
{
// First get ColR
int colR = MyRTBItem.MyStepPanel.ToDisplay(MyRTBItem.MyStepSectionLayoutData.ColRTable, MyItemInfo.ColumnMode);
// Second get WidS
int widS = /* _WidthAdjust + borderWidth + */ MyRTBItem.MyStepPanel.ToDisplay(MyRTBItem.MyStepSectionLayoutData.WidSTableEdit, MyItemInfo.ColumnMode);
//int wNew = _MyRTBItem.MyStepPanel.ToDisplay(_MyRTBItem.MyStepSectionLayoutData.WidT);
int wNew = 70 + widS + colR * MyItemInfo.ColumnMode;
if (wNew > _MyRTBItem.ItemWidth)
{
_MyRTBItem.ItemWidth = wNew;
_MyRTBItem.ItemLocation = _MyRTBItem.TableLocation(_MyRTBItem.MyParentRTBItem, _MyRTBItem.MyStepSectionLayoutData, wNew);
}
}
ActiveMode = activeMode;
OnAdjustTableWidth(this, new StepRTBTableWidthEventArgs(true));
_InitializingRTB = true;
DisplayText vlntxt = new DisplayText(_MyItemInfo, EpMode, VwMode, !edit, FieldToEdit, true);
DisplayText vlntxt = new DisplayText(MyItemInfo, E_EditPrintMode.Edit, VwMode, !ActiveMode, FieldToEdit, true);
//if (_origDisplayText != null && vlntxt.StartText == _origDisplayText.StartText)
//{
// ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit);
// if (!ReadOnly && !edit) ReadOnly = true;
// return;
//}
_origDisplayText = vlntxt;
Font formatFont = _origDisplayText.TextFont.WindowsFont;
if (_MyItemInfo.IsTable || _MyItemInfo.IsFigure)
Font = formatFont;
else
{
if (VlnSettings.DebugMode || VlnSettings.ProductionMode)
Font = new Font(_MyFontFamily == null ? formatFont.FontFamily : _MyFontFamily, formatFont.Size, formatFont.Style);
else
Font = new Font("Bookman Old Style", formatFont.Size, formatFont.Style);
// TODO: Release Mode
//Font = _origDisplayText.TextFont.WindowsFont; // font defined in plant's format
}
OrigDisplayText = vlntxt;
// RHM 20101201 - Don't reset the text. Calculate the text and compare it with the existing text in AddRTFText
//Text = ""; // Initialize text before add text
// IMPORTANT: SetLineSpacing must be set before Links, otherwise it
@ -228,7 +312,7 @@ namespace Volian.Controls.Library
//Console.WriteLine("'font',{0}", Font);
//if(Text == "")SelectionFont = Font; // Initialize SelectionFont
RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT);
ReadOnly = EpMode == E_EditPrintMode.Print || VwMode == E_ViewMode.View || edit == false;
ReadOnly = VwMode == E_ViewMode.View || ActiveMode == false;
AddRtfText(vlntxt.StartText);
//AddRtfStyles();
// set readonly based on initial modes, however, these may change if
@ -252,23 +336,14 @@ namespace Volian.Controls.Library
// the text within the RichTextBox.
RightMargin = Width > 0 ? Width - 1 : 0;
// figure out if needs outlined, depends on table/figure type
if (!edit)
if (!ActiveMode)
{
RemoveEventHandlers();
if ((!_MyItemInfo.IsSection && !_MyItemInfo.IsProcedure) && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure))
{
int newwidth = (int)_MyRTBItem.TableWidth(Font, Text, false);
if (_MyRTBItem.ItemWidth != newwidth)
{
_MyRTBItem.ItemWidth = newwidth;
_MyRTBItem.ItemLocation = _MyRTBItem.TableLocation(_MyRTBItem.MyParentRTBItem, _MyRTBItem.MyStepSectionLayoutData, newwidth);
}
}
OnAdjustTableWidth(this, new StepRTBTableWidthEventArgs(false));// View Mode
SelectAll();
if (SelectionHangingIndent !=0) SelectionHangingIndent = 0;
int indchar = 0;
string indentToken = _MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IndentToken;
string indentToken = MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IndentToken;
if (indentToken == null) indentToken = "\x5";
while ((indchar = Find(indentToken, indchar, RichTextBoxFinds.None)) >= 0)
{
@ -280,17 +355,16 @@ namespace Volian.Controls.Library
}
//else
//{
// if (_MyRTBItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure))
// if (MyRTBItem != null && (_MyItemInfo.IsTable || _MyItemInfo.IsFigure))
// {
// //_MyRTBItem.ItemWidth = (int)_MyRTBItem.TableWidth(Font, Text,false);
// _MyRTBItem.ItemWidth = _MyRTBItem.MyStepPanel.ToDisplay(_MyRTBItem.MyStepSectionLayoutData.WidT);
// //MyRTBItem.ItemWidth = (int)MyRTBItem.TableWidth(Font, Text,false);
// MyRTBItem.ItemWidth = MyRTBItem.MyStepPanel.ToDisplay(MyRTBItem.MyStepSectionLayoutData.WidT);
// }
//}
_origRTF = Rtf;
OrigRTF = Rtf;
_InitializingRTB = false;
_MyItemInfo.MyConfig.PropertyChanged += new PropertyChangedEventHandler(MyConfig_PropertyChanged);
AdjustSizeForContents(!edit); // TODO: this is not quite right yet.
if (MyRTBItem != null) MyRTBItem.ChangeBar = MyRTBItem.MyItemInfo.HasChangeBar;
AdjustSizeForContents(!ActiveMode); // TODO: this is not quite right yet.
}
private bool _ProcessKeystrokes = true;
public bool ProcessKeystrokes
@ -352,7 +426,13 @@ namespace Volian.Controls.Library
}
}
public System.Windows.Forms.AutoScaleMode AutoScaleMode;
private DisplayText _origDisplayText;
private DisplayText _OrigDisplayText;
public DisplayText OrigDisplayText
{
get { return _OrigDisplayText; }
set { _OrigDisplayText = value; }
}
private RichTextBox _rtbTemp = new RichTextBox();
private string _MyLinkText;
public string MyLinkText
@ -365,7 +445,7 @@ namespace Volian.Controls.Library
// updates to the info panel were not always occurring when the previous two
// lines were active
_MyLinkText = value;
OnLinkChanged(this, new StepPanelLinkEventArgs(_MyRTBItem, _MyLinkText));
OnLinkChanged(this, new StepPanelLinkEventArgs(_MyLinkText));
//}
}
}
@ -387,7 +467,8 @@ namespace Volian.Controls.Library
}
protected override void OnMouseWheel(MouseEventArgs e)
{
_MyRTBItem.MyStepPanel.MouseWheel(e);
OnDoMouseWheel(this, e);
//MyRTBItem.MyStepPanel.MouseWheel(e);
//base.OnMouseWheel(e);
}
private void RemoveEventHandlers()
@ -435,7 +516,7 @@ namespace Volian.Controls.Library
try
{
//Console.WriteLine("{0}", ContextMenuStrip.GetType().FullName);
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ClearContextMenu();
OnSetMenu(this, new StepRTBMenuEventArgs(null));
sublocation = 1;
_ContextMenuStripChanged = true;
sublocation = 2;
@ -465,10 +546,10 @@ namespace Volian.Controls.Library
{
_MouseDown = false;
}
void MyConfig_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
SaveConfig();
}
//void MyConfig_PropertyChanged(object sender, PropertyChangedEventArgs e)
//{
// SaveConfig();
//}
private void StepRTB_Click(object sender, EventArgs e)
{
if (ReadOnly) return;
@ -486,8 +567,8 @@ namespace Volian.Controls.Library
{
_MouseDown = true;
//Console.WriteLine("vvvvvvvvvv StepRTB Mouse Down id= {0}",MyItemInfo.ItemID);
if (!_ContextMenuStripChanged && this.MyRTBItem != null)
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.SetContextMenu();
if (!_ContextMenuStripChanged)
OnSetMenu(this, new StepRTBMenuEventArgs("OpenContextMenu"));
_ContextMenuStripChanged = false;
CorrectSelectionAtEndOfLine();
}
@ -505,22 +586,24 @@ namespace Volian.Controls.Library
}
#endregion
#region ApplicationSupport
public void ToggleEditView()
{
SaveText();
//ItemInfo tmp = MyItemInfo;
//MyItemInfo = null;
ReadOnly = !ReadOnly;
EpMode = ReadOnly ? E_EditPrintMode.Print : E_EditPrintMode.Edit;
VwMode = ReadOnly ? E_ViewMode.View : E_ViewMode.Edit;
ViewRTB = ReadOnly;
Clear();
RTBFillIn(!ViewRTB);
//MyItemInfo = tmp;
SelectionStart = 0;
SelectionLength = 0;
OnModeChange(this, new StepRTBModeChangeEventArgs(ViewRTB?E_ViewMode.View:E_ViewMode.Edit));
}
// Used in StepTabRibbon:
//public void ToggleEditView(E_ViewMode vwMode)
//{
// OnDoSaveContents(this, new EventArgs()); // SaveText();
// //ItemInfo tmp = MyItemInfo;
// //MyItemInfo = null;
// //ReadOnly = !ReadOnly;
// //EpMode = ReadOnly ? E_EditPrintMode.Print : E_EditPrintMode.Edit;
// VwMode = vwMode;
// ReadOnly = VwMode == E_ViewMode.View;
// ViewRTB = ReadOnly;
// Clear();
// RefreshDisplay(!ViewRTB);
// //MyItemInfo = tmp;
// SelectionStart = 0;
// SelectionLength = 0;
// //OnModeChange(this, new StepRTBModeChangeEventArgs(ViewRTB?E_ViewMode.View:E_ViewMode.Edit));
//}
public void InsertRO(string value, string link)
{
AddRtfLink(value, link);
@ -541,9 +624,8 @@ namespace Volian.Controls.Library
{
AddSymbol(symbol);
}
public void InsertIndent()
public void InsertIndent(string indentToken)
{
string indentToken = _MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.IndentToken;
if (indentToken == null) indentToken = "\x5";
AddText(indentToken);
}
@ -675,44 +757,6 @@ namespace Volian.Controls.Library
SelectionLength = olen;
}
#endregion
#region SaveData
public void SaveText(bool force)
{
if (ReadOnly) return;
if (ViewRTB) return;
if (!force && !_IsDirty && Text.Contains("(Resolved Transition Text)") == false) return;
bool success = _origDisplayText.Save((RichTextBox)this);
if (success)
{
FindAllLinks();
_origRTF = Rtf;
ClearUndo();
}
}
public void SaveText()
{
if (ReadOnly) return;
if (ViewRTB) return;
if (!_IsDirty && Text.Contains("(Resolved Transition Text)") == false) return;
bool success = _origDisplayText.Save((RichTextBox)this);
if (success)
{
FindAllLinks();
_origRTF = Rtf;
ClearUndo();
}
}
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;
}
#endregion
#region AddRtfTextAndStyles
private string _LastRtf = "";
private bool _lastReadOnly = false;
@ -722,7 +766,7 @@ namespace Volian.Controls.Library
//if(MyItemInfo.ItemID==10256)
// Volian.Base.Library.vlnStackTrace.ShowStackLocal("ItemID:{0}", MyItemInfo.ItemID.ToString());
StringBuilder selectedRtfSB = new StringBuilder();
AddFontTable(selectedRtfSB);
AddFontTable(selectedRtfSB, FormatFont, FontIsFixed(FormatFont));
_RtfPrefix = selectedRtfSB.ToString();
selectedRtfSB.Append(txt);
string newRtf = selectedRtfSB.ToString() + "}";
@ -737,40 +781,40 @@ namespace Volian.Controls.Library
}
FindAllLinks();
}
private void AddFontTable(StringBuilder selectedRtfSB)
private static void AddFontTable(StringBuilder selectedRtfSB, Font myFont, bool isFixed)
{
StringBuilder sbbeg = new StringBuilder();
StringBuilder sbend = new StringBuilder();
if (Font.Bold)
if (myFont.Bold)
{
sbbeg.Append(@"\b");
sbend.Append(@"\b0");
}
if (Font.Underline)
if (myFont.Underline)
{
sbbeg.Append(@"\ul");
sbend.Insert(0, @"\ulnone");
}
if (Font.Italic)
if (myFont.Italic)
{
sbbeg.Append(@"\i");
sbend.Insert(0, @"\i0");
}
selectedRtfSB.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 " + this.Font.FontFamily.Name + @";}"); //}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}";
if (!FontIsFixed())
selectedRtfSB.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 " + myFont.FontFamily.Name + @";}"); //}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}";
if (!isFixed)
selectedRtfSB.Append(@"{\f1\fnil\fcharset0 Arial Unicode MS;}}{\colortbl ;\red255\green0\blue0;}");
else
selectedRtfSB.Append(@"{\f1\fnil\fcharset0 VESymbFix;}}{\colortbl ;\red255\green0\blue0;}");
selectedRtfSB.Append("\r\n");
// use styles to construct rtf commands to insert into next line (where \b, etc is)
selectedRtfSB.Append(@"\viewkind4\uc1\pard\sl-240\slmult0" + sbbeg.ToString() + @"\fs" + Convert.ToInt32(this.Font.SizeInPoints * 2).ToString() + @" "); // \f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}";
selectedRtfSB.Append(@"\viewkind4\uc1\pard\sl-240\slmult0" + sbbeg.ToString() + @"\fs" + Convert.ToInt32(myFont.SizeInPoints * 2).ToString() + @" "); // \f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}";
}
private bool FontIsFixed()
private bool FontIsFixed(Font myFont)
{
Graphics grph = Graphics.FromHwnd(this.Handle);
SizeF sfW = grph.MeasureString("W", this.Font);
SizeF sfE = grph.MeasureString("!", this.Font);
SizeF sfW = grph.MeasureString("W", myFont);
SizeF sfE = grph.MeasureString("!", myFont);
if (sfW.Width == sfE.Width) return true;
return false;
}
@ -805,11 +849,11 @@ namespace Volian.Controls.Library
// See comments in AddRtf(string str) to explain the font style setting
RTBAPI.E_FontStyle fs = RTBAPI.GetFontStyle(this);
int position = SelectionStart;
SelectedRtf = _RtfPrefix + @"\f1\fs" + this.Font.SizeInPoints * 2 + @" " + str + @"}";
SelectedRtf = RtfPrefix + str + @"}";
Select(position, 1);
RTBAPI.SetFontStyle(this, fs);
Select(position + 1, 0);
SelectionFont = _origDisplayText.TextFont.WindowsFont;
SelectionFont = MyItemInfo.GetItemFont().WindowsFont;
}
private string GetAddSymbolText(string symtxt)
{
@ -829,7 +873,7 @@ namespace Volian.Controls.Library
{
StringBuilder sb = new StringBuilder();
sb.Append(@"{\fonttbl{\f0\fnil\fcharset2 " + this.Font.FontFamily.Name + @";}");
if (!FontIsFixed())
if (!FontIsFixed(this.Font))
sb.Append(@"{\f1\fnil\fcharset0 Arial Unicode MS;}}");
else
sb.Append(@"{\f1\fnil\fcharset0 VESymbFix;}}");
@ -850,14 +894,11 @@ namespace Volian.Controls.Library
string fonttab = FontTable;
string fontsize = FontSize;
this.DetectUrls = false;
//if (SelectionLength > 0) DeleteCurrentSelection(null);
if (SelectionLength > 0)HandleDeleteKeyWithSelectedText(new KeyEventArgs(Keys.None), null);
int position = SelectionStart;
SelectionLength = 0;
//Console.WriteLine(this.Rtf);
linkValue = linkValue.Replace("\\u8209?", "\\f1\\u8209?\\f0 ");
SelectedRtf = @"{\rtf1\ansi"+FontTable+@"{\colortbl ;\red255\green0\blue0;}\v"+FontSize+@" <START]\v0\cf1 " + linkValue + @"\cf0\v " + linkUrl + @"[END>\v0 }";
//Console.WriteLine(this.Rtf);
this.SelectionLength = 0;
this.SelectionStart = position;
FindAllLinks();
@ -873,7 +914,7 @@ namespace Volian.Controls.Library
}
private void AddRtfStyles()
{
if ((_origDisplayText.TextFont.Style & E_Style.Bold) > 0)
if ((OrigDisplayText.TextFont.Style & E_Style.Bold) > 0)
{
this.SelectAll();
RTBAPI.ToggleBold(true, this, RTBAPI.RTBSelection.SCF_SELECTION);
@ -884,7 +925,7 @@ namespace Volian.Controls.Library
// apply the underlining to the selected text, because if the
// the underlining was applied to RTBAPI.RTBSelection.SCF_ALL
// the Links were changed so that they were no longer hidden.
if ((_origDisplayText.TextFont.Style & E_Style.Underline) > 0)
if ((OrigDisplayText.TextFont.Style & E_Style.Underline) > 0)
// RTBAPI.ToggleUnderline(true, this, RTBAPI.RTBSelection.SCF_ALL);
{
this.SelectAll();
@ -896,7 +937,7 @@ namespace Volian.Controls.Library
// apply the italics to the selected text, because if the
// the italics was applied to RTBAPI.RTBSelection.SCF_ALL
// the Links were changed so that they were no longer hidden.
if ((_origDisplayText.TextFont.Style & E_Style.Italics) > 0)
if ((OrigDisplayText.TextFont.Style & E_Style.Italics) > 0)
// RTBAPI.ToggleItalic(true, this, RTBAPI.RTBSelection.SCF_ALL);
{
this.SelectAll();
@ -1027,22 +1068,22 @@ namespace Volian.Controls.Library
}
#endregion
#region ColorSupport - Not currently used.
private void SetBackGroundColor(ItemInfo itemInfo)
{
string backcolor = null;
int type = (int)itemInfo.MyContent.Type;
FormatInfo formatinfo = itemInfo.ActiveFormat;
if (type == (int)E_FromType.Procedure)
backcolor = formatinfo.PlantFormat.FormatData.ProcData.BackColor;
else if (type == (int)E_FromType.Section)
backcolor = formatinfo.PlantFormat.FormatData.SectData.BackColor;
else
{
int typindx = (int)itemInfo.MyContent.Type - 20000; // what to do for other types rather than steps
backcolor = formatinfo.PlantFormat.FormatData.StepDataList[typindx].StepLayoutData.BackColor;
}
BackColor = Color.FromName(backcolor);
}
//private void SetBackGroundColor(ItemInfo itemInfo)
//{
// string backcolor = null;
// int type = (int)itemInfo.MyContent.Type;
// FormatInfo formatinfo = itemInfo.ActiveFormat;
// if (type == (int)E_FromType.Procedure)
// backcolor = formatinfo.PlantFormat.FormatData.ProcData.BackColor;
// else if (type == (int)E_FromType.Section)
// backcolor = formatinfo.PlantFormat.FormatData.SectData.BackColor;
// else
// {
// int typindx = (int)itemInfo.MyContent.Type - 20000; // what to do for other types rather than steps
// backcolor = formatinfo.PlantFormat.FormatData.StepDataList[typindx].StepLayoutData.BackColor;
// }
// BackColor = Color.FromName(backcolor);
//}
#endregion
#region EventSupport
#region LinkEvents
@ -1093,7 +1134,8 @@ namespace Volian.Controls.Library
private bool _HandlingCtrlA = false;
private void HandleLocalSelectionChange()
{
if (MyRTBItem != null && MyRTBItem.MyStepPanel.SelectedStepRTB != this)
//if (MyRTBItem != null && MyRTBItem.MyStepPanel.SelectedStepRTB != this)
if (OnIsNotCurrentSelection(this, new EventArgs()))
return;
HandleSelectionChange();
@ -1339,9 +1381,10 @@ namespace Volian.Controls.Library
public bool WasXDelete = false;
private void DeleteCurrentSelection(string keys)
{
DebugPrint("vvvvvvvvvvvvxxxxxxxxxxxx>");
DebugSelection("Before X");
DebugPrint(keys == null ? "NULL" : "NOT NULL");
SelectedText = keys==null?"X":keys; // replace text with X
WasXDelete = (keys == null);
DebugSelection("After X");
@ -1418,53 +1461,50 @@ namespace Volian.Controls.Library
{
if (e.Control)
{
if (this.MyRTBItem != null)
if (e.Alt)
{
if (e.Alt)
switch (e.KeyCode)
{
switch (e.KeyCode)
{
case Keys.M:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnAnnots_Click(sender, e);
e.Handled = true;
break;
default:
break;
}
case Keys.M:
OnOpenAnnotations(this, new EventArgs());
e.Handled = true;
break;
default:
break;
}
if (e.Shift)
}
if (e.Shift)
{
switch (e.KeyCode)
{
switch (e.KeyCode)
{
case Keys.F:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsFigure");
e.Handled = true;
break;
case Keys.T:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsTable");
e.Handled = true;
break;
case Keys.N:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsNote");
e.Handled = true;
break;
case Keys.C:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsCaution");
e.Handled = true;
break;
case Keys.S:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsSubStps");
e.Handled = true;
break;
case Keys.H:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsHLS");
e.Handled = true;
break;
case Keys.R:
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("InsRNO");
e.Handled = true;
break;
}
case Keys.F:
OnSetMenu(this, new StepRTBMenuEventArgs("InsFigure"));
e.Handled = true;
break;
case Keys.T:
OnSetMenu(this, new StepRTBMenuEventArgs("InsTable"));
e.Handled = true;
break;
case Keys.N:
OnSetMenu(this, new StepRTBMenuEventArgs("InsNote"));
e.Handled = true;
break;
case Keys.C:
OnSetMenu(this, new StepRTBMenuEventArgs("InsCaution"));
e.Handled = true;
break;
case Keys.S:
OnSetMenu(this, new StepRTBMenuEventArgs("InsSubStps"));
e.Handled = true;
break;
case Keys.H:
OnSetMenu(this, new StepRTBMenuEventArgs("InsHLS"));
e.Handled = true;
break;
case Keys.R:
OnSetMenu(this, new StepRTBMenuEventArgs("InsRNO"));
e.Handled = true;
break;
}
}
}
@ -1567,11 +1607,8 @@ namespace Volian.Controls.Library
e.Handled = true;
break;
case Keys.Enter:
if (this.MyRTBItem != null)
{
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.btnInsPgBrk_Click(sender, e);
e.Handled = true;
}
OnInsertPgBrk(this, new EventArgs());
e.Handled = true;
break;
}
}
@ -1626,7 +1663,7 @@ namespace Volian.Controls.Library
// because selection is first character or link without any other selection. Don't
// need to write code to handle link at beginning of box in Shift Right code because
// it's handled in HandleSelectionChange.
if (e.Shift && ((SelectionStart > 0) || (SelectionStart==0 && _LinkLocations.Count>0 && _LinkLocations[0].Start!=7)))
if (e.Shift && ((SelectionStart > 0) || (SelectionStart == 0 && _LinkLocations.Count > 0 && _LinkLocations[0].Start != 7)))
{
int newlen = FindEnd();
int len = SelectionLength + newlen;
@ -1658,13 +1695,13 @@ namespace Volian.Controls.Library
if (!e.Shift) HandleLocalSelectionChange();
// if shift-down & on link at beginning of box - do special processing (regular processing
// didn't handle it correctly.
if (e.Shift && lastLine > 0 && SelectionStart==0 && _LinkLocations.Count>0 && _LinkLocations[0].Start==7)
if (e.Shift && lastLine > 0 && SelectionStart == 0 && _LinkLocations.Count > 0 && _LinkLocations[0].Start == 7)
{
Point cpos = GetPositionFromCharIndex(SelectionStart);
int addon = ClientRectangle.Height / (lastLine + 1);
cpos.Y = cpos.Y + addon;
int selend = GetCharIndexFromPosition(cpos);
Select(7, selend-7);
Select(7, selend - 7);
e.Handled = true;
}
break;
@ -1735,19 +1772,16 @@ namespace Volian.Controls.Library
e.Handled = true;
break;
case Keys.F5:
if (this.MyRTBItem != null)
if (e.Shift)
{
if (e.Shift)
{
e.Handled = true;
if (MyRTBItem.MyStepPanel.MyStepTabPanel.MyDisplayTabControl.MyCopyStep == null) return;
MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ShortCutContextMenu("StepPaste");
}
else if (!e.Control && !e.Alt)
{
e.Handled = true;
this.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.DoCopyStep();
}
e.Handled = true;
if (!OnCheckClipboard(this, new EventArgs())) return; // check if 'clipboard' contains a step.
OnSetMenu(this, new StepRTBMenuEventArgs("StepPaste"));
}
else if (!e.Control && !e.Alt)
{
e.Handled = true;
OnCopyStep(this, new EventArgs());
}
break;
case Keys.F6:
@ -1755,52 +1789,44 @@ namespace Volian.Controls.Library
SendKeys.Send("%H{ESC}");
break;
case Keys.Tab:
e.SuppressKeyPress = true;
e.Handled = true;
if (MyRTBItem == null)
{
Form frm = ParentForm(this);
if (frm != null)
frm.SelectNextControl(this, true, true, true, true);
}
e.SuppressKeyPress = true;
e.Handled = true;
Form frm = ParentForm(this);
if (frm != null)
frm.SelectNextControl(this, true, true, true, true);
break;
case Keys.Enter:
if (!e.Control && !e.Shift && !e.Alt)
{
if (MyRTBItem != null && !MyRTBItem.MyItemInfo.IsTablePart)
{
e.Handled = true;
MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.ProcessEnterKey();
}
OnEnterKeyPressed(sender, e);
}
break;
}
}
private static Form ParentForm(Control ctrl)
{
while (!(ctrl.Parent is Form)) ctrl = ctrl.Parent;
while (!(ctrl.Parent is Form || ctrl.Parent is EditItem))
ctrl = ctrl.Parent;
return ctrl.Parent as Form;
}
private void StepRTB_HomeEndPressed(KeyEventArgs keyargs)
{
if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) return;
// Cursor moves out of box only if control is pressed too - otherwise key is
// handled in rtb.
//if (keyargs.Control)_MyRTBItem.MyStepPanel.StepCursorKeys(this, keyargs); // Replaced with an event
//if (keyargs.Control)MyRTBItem.MyStepPanel.StepCursorKeys(this, keyargs); // Replaced with an event
if (keyargs.Control) OnCursorKeyPress(this, keyargs);
}
private void StepRTB_PageKeyPressed(KeyEventArgs keyargs)
{
if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) return;
//_MyRTBItem.MyStepPanel.StepCursorKeys(this, keyargs); Replaced with an event
//MyRTBItem.MyStepPanel.StepCursorKeys(this, keyargs); Replaced with an event
OnCursorKeyPress(this, keyargs);
}
public void StepRTB_ArrowPressed(E_ArrowKeys key)
{
Point cp = PointToClient(Cursor.Position);
//_MyRTBItem.MyStepPanel.CursorMovement(this, cp, key); Replaced with an event
//MyRTBItem.MyStepPanel.CursorMovement(this, cp, key); Replaced with an event
OnCursorMovement(this, new StepRTBCursorMovementEventArgs(cp, key));
}
private void StepRTB_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
@ -2607,7 +2633,8 @@ namespace Volian.Controls.Library
static void tsi_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
_ContextMenuStepRTB.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.OpenContextMenu(tsmi.Owner.Location);
//_ContextMenuStepRTB.MyRTBItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.OpenContextMenu(tsmi.Owner.Location);
_ContextMenuStepRTB.OnOpenContextMenu(sender, new StepRTBLocationEventArgs(tsmi.Owner.Location));
}
// This is our customized Spell Check dialog
@ -2681,6 +2708,32 @@ namespace Volian.Controls.Library
_ViewMode = vmode;
}
}
public partial class StepRTBMenuEventArgs
{
private string _MenuGroup;
public string MenuGroup
{
get { return _MenuGroup; }
set { _MenuGroup = value; }
}
public StepRTBMenuEventArgs(string menuGroup)
{
_MenuGroup = menuGroup;
}
}
public partial class StepRTBTableWidthEventArgs
{
bool _EditMode;
public bool EditMode
{
get { return _EditMode; }
set { _EditMode = value; }
}
public StepRTBTableWidthEventArgs(bool editMode)
{
_EditMode = editMode;
}
}
public class StepRTBCursorMovementEventArgs
{
private Point _CursorLocation;
@ -2701,6 +2754,19 @@ namespace Volian.Controls.Library
_Key = key;
}
}
public class StepRTBLocationEventArgs:EventArgs
{
private Point _Location;
public Point Location
{
get { return _Location; }
set { _Location = value; }
}
public StepRTBLocationEventArgs(Point location)
{
_Location = location;
}
}
#region LinkLocation Class
public class LinkLocation
{

View File

@ -6,20 +6,13 @@ namespace Volian.Controls.Library
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private bool _BeingDisposed = false;
public bool BeingDisposed
{
get { return _BeingDisposed; }
set { _BeingDisposed = value; }
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
_BeingDisposed = true;
if (disposing && (components != null))
{
components.Dispose();