diff --git a/PROMS/Volian.Controls.Library/DisplayTabControl.cs b/PROMS/Volian.Controls.Library/DisplayTabControl.cs index de262deb..8e85eb09 100644 --- a/PROMS/Volian.Controls.Library/DisplayTabControl.cs +++ b/PROMS/Volian.Controls.Library/DisplayTabControl.cs @@ -489,31 +489,44 @@ namespace Volian.Controls.Library { get { return _PnlCaret; } } + private Color _OldForeColor = Color.Empty; + private Color _OldBackColor = Color.Empty; public void ShowCaret() { if (_MyStepRTB != null) { - if (!_MyStepRTB.Visible) - _MyStepRTB.Visible = true; - if (_MyStepRTB.SelectionLength == 0) + if (_MyEditItem.RTBLastFocus) { - Point pt = _MyStepRTB.GetPositionFromCharIndex(_MyStepRTB.SelectionStart); - pt = _MyStepRTB.PointToScreen(pt); - pt = this.PointToClient(pt); - PnlCaret.Location = pt; - PnlCaret.BackColor = _MyStepRTB.ForeColor; - using (Graphics gr = this.CreateGraphics()) + if (!_MyStepRTB.Visible) + _MyStepRTB.Visible = true; + if (_MyStepRTB.SelectionLength == 0) { - SizeF sf = gr.MeasureString("Mg", _MyStepRTB.SelectionFont); - sf.Width = 1; - PnlCaret.Size = sf.ToSize(); + Point pt = _MyStepRTB.GetPositionFromCharIndex(_MyStepRTB.SelectionStart); + pt = _MyStepRTB.PointToScreen(pt); + pt = this.PointToClient(pt); + PnlCaret.Location = pt; + PnlCaret.BackColor = _MyStepRTB.ForeColor; + using (Graphics gr = this.CreateGraphics()) + { + SizeF sf = gr.MeasureString("Mg", _MyStepRTB.SelectionFont); + sf.Width = 1; + PnlCaret.Size = sf.ToSize(); + } + tmrCaret.Enabled = true; + } + else + { + if (_MyStepRTB.SelectionColor != Color.Empty && _OldForeColor == Color.Empty) + { + _OldForeColor = _MyStepRTB.SelectionColor; + _MyStepRTB.SelectionColor = Color.White; + } + if (_MyStepRTB.SelectionBackColor != Color.Empty && _OldBackColor == Color.Empty) + { + _OldBackColor = _MyStepRTB.SelectionBackColor; + _MyStepRTB.SelectionBackColor = Color.FromName("Highlight"); + } } - tmrCaret.Enabled = true; - } - else - { - _MyStepRTB.SelectionColor = Color.White; - _MyStepRTB.SelectionBackColor = Color.FromName("Highlight"); } } } @@ -528,11 +541,23 @@ namespace Volian.Controls.Library } else { - _MyStepRTB.SelectionColor = _MyStepRTB.ForeColor; - _MyStepRTB.SelectionBackColor = _MyStepRTB.BackColor; + if (_OldForeColor != Color.Empty) + { + _MyStepRTB.SelectionColor = _OldForeColor; + _OldForeColor = Color.Empty; + } + if (_OldBackColor != Color.Empty) + { + _MyStepRTB.SelectionBackColor = _OldBackColor; + _OldBackColor = Color.Empty; + } } } } + private void tmrCaret_Tick(object sender, EventArgs e) + { + PnlCaret.Visible = !PnlCaret.Visible; + } #endregion #region Private Methods ///// @@ -748,9 +773,5 @@ namespace Volian.Controls.Library myDisplayTabItem.Dispose(); } #endregion - private void tmrCaret_Tick(object sender, EventArgs e) - { - PnlCaret.Visible = !PnlCaret.Visible; - } } } diff --git a/PROMS/Volian.Controls.Library/EditItem.cs b/PROMS/Volian.Controls.Library/EditItem.cs index 2a3977ad..a5376f0d 100644 --- a/PROMS/Volian.Controls.Library/EditItem.cs +++ b/PROMS/Volian.Controls.Library/EditItem.cs @@ -58,6 +58,12 @@ namespace Volian.Controls.Library } #endregion #region Properties + private bool _RTBLastFocus = true; + public bool RTBLastFocus + { + get { return _RTBLastFocus; } + set { _RTBLastFocus = value; } + } protected static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); protected ChildRelation _MyChildRelation; protected bool _Loading = true; diff --git a/PROMS/Volian.Controls.Library/GridItem.cs b/PROMS/Volian.Controls.Library/GridItem.cs index a5a3c289..5ba91ede 100644 --- a/PROMS/Volian.Controls.Library/GridItem.cs +++ b/PROMS/Volian.Controls.Library/GridItem.cs @@ -36,9 +36,6 @@ namespace Volian.Controls.Library * 5) KBR Fix the grid (xml stored in Data) when a step is inserted so that transition text is changed, * or when an ROvalue is changed. In ItemInsertExt.cs, UpdateTransitionText & * UpdatePastedStepTransitionText - * 6) RHM Insert HLS - wrong font. - * 7) RHM HideCaret & ShowCaret should restore original color. - * 8) RHM HideCaret & ShowCaret should not turn on editor unless editor had been previously been active */ #region Fields public VlnFlexGrid MyFlexGrid @@ -192,12 +189,10 @@ namespace Volian.Controls.Library MyFlexGrid.Focus(); MyFlexGrid.StartEditing(); } - void MyFlexGrid_Click(object sender, EventArgs e) { MyFlexGrid.Focus(); } - void MyStepRTB_EditModeChanged(object sender, EventArgs args) { AdjustColorsForEditMode(); @@ -219,6 +214,8 @@ namespace Volian.Controls.Library private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore void MyFlexGrid_SelChange(object sender, EventArgs e) { + RTBLastFocus = false; + MyStepRTB.Visible = false; // Hide the editor if the Selection Changes if (MyFlexGrid.Selection.IsSingleCell && MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0) { object obj = MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col]; @@ -276,8 +273,12 @@ namespace Volian.Controls.Library this.MyStepRTB.EditModeChanged += new StepRTBEvent(MyStepRTB_EditModeChanged); this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown); this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); + this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus); + } + void MyStepRTB_GotFocus(object sender, EventArgs e) + { + RTBLastFocus = true; } - #endregion #region Override Method and Properties public override int BorderWidth { get { return (MyFlexGrid.Width - MyFlexGrid.ClientRectangle.Width); } }