- Restore the selection color after HideCaret

- Only show the pseudo caret if the StepRTB was active for the grid
Add a property to track if the StepRTB was active for a grid
Track if the StepRTB was active for a grid
This commit is contained in:
Rich 2011-02-14 19:00:41 +00:00
parent 4fdc4d4493
commit 5786528a44
3 changed files with 58 additions and 30 deletions

View File

@ -489,31 +489,44 @@ namespace Volian.Controls.Library
{ {
get { return _PnlCaret; } get { return _PnlCaret; }
} }
private Color _OldForeColor = Color.Empty;
private Color _OldBackColor = Color.Empty;
public void ShowCaret() public void ShowCaret()
{ {
if (_MyStepRTB != null) if (_MyStepRTB != null)
{ {
if (!_MyStepRTB.Visible) if (_MyEditItem.RTBLastFocus)
_MyStepRTB.Visible = true;
if (_MyStepRTB.SelectionLength == 0)
{ {
Point pt = _MyStepRTB.GetPositionFromCharIndex(_MyStepRTB.SelectionStart); if (!_MyStepRTB.Visible)
pt = _MyStepRTB.PointToScreen(pt); _MyStepRTB.Visible = true;
pt = this.PointToClient(pt); if (_MyStepRTB.SelectionLength == 0)
PnlCaret.Location = pt;
PnlCaret.BackColor = _MyStepRTB.ForeColor;
using (Graphics gr = this.CreateGraphics())
{ {
SizeF sf = gr.MeasureString("Mg", _MyStepRTB.SelectionFont); Point pt = _MyStepRTB.GetPositionFromCharIndex(_MyStepRTB.SelectionStart);
sf.Width = 1; pt = _MyStepRTB.PointToScreen(pt);
PnlCaret.Size = sf.ToSize(); 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 else
{ {
_MyStepRTB.SelectionColor = _MyStepRTB.ForeColor; if (_OldForeColor != Color.Empty)
_MyStepRTB.SelectionBackColor = _MyStepRTB.BackColor; {
_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 #endregion
#region Private Methods #region Private Methods
///// <summary> ///// <summary>
@ -748,9 +773,5 @@ namespace Volian.Controls.Library
myDisplayTabItem.Dispose(); myDisplayTabItem.Dispose();
} }
#endregion #endregion
private void tmrCaret_Tick(object sender, EventArgs e)
{
PnlCaret.Visible = !PnlCaret.Visible;
}
} }
} }

View File

@ -58,6 +58,12 @@ namespace Volian.Controls.Library
} }
#endregion #endregion
#region Properties #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 static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected ChildRelation _MyChildRelation; protected ChildRelation _MyChildRelation;
protected bool _Loading = true; protected bool _Loading = true;

View File

@ -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, * 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 & * or when an ROvalue is changed. In ItemInsertExt.cs, UpdateTransitionText &
* UpdatePastedStepTransitionText * 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 #region Fields
public VlnFlexGrid MyFlexGrid public VlnFlexGrid MyFlexGrid
@ -192,12 +189,10 @@ namespace Volian.Controls.Library
MyFlexGrid.Focus(); MyFlexGrid.Focus();
MyFlexGrid.StartEditing(); MyFlexGrid.StartEditing();
} }
void MyFlexGrid_Click(object sender, EventArgs e) void MyFlexGrid_Click(object sender, EventArgs e)
{ {
MyFlexGrid.Focus(); MyFlexGrid.Focus();
} }
void MyStepRTB_EditModeChanged(object sender, EventArgs args) void MyStepRTB_EditModeChanged(object sender, EventArgs args)
{ {
AdjustColorsForEditMode(); AdjustColorsForEditMode();
@ -219,6 +214,8 @@ namespace Volian.Controls.Library
private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore
void MyFlexGrid_SelChange(object sender, EventArgs e) 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) if (MyFlexGrid.Selection.IsSingleCell && MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0)
{ {
object obj = MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col]; object obj = MyFlexGrid[MyFlexGrid.Row, MyFlexGrid.Col];
@ -276,8 +273,12 @@ namespace Volian.Controls.Library
this.MyStepRTB.EditModeChanged += new StepRTBEvent(MyStepRTB_EditModeChanged); this.MyStepRTB.EditModeChanged += new StepRTBEvent(MyStepRTB_EditModeChanged);
this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown); this.MyStepRTB.KeyDown += new KeyEventHandler(MyStepRTB_KeyDown);
this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange); this.MyFlexGrid.SelChange += new EventHandler(MyFlexGrid_SelChange);
this.MyStepRTB.GotFocus += new EventHandler(MyStepRTB_GotFocus);
}
void MyStepRTB_GotFocus(object sender, EventArgs e)
{
RTBLastFocus = true;
} }
#endregion #endregion
#region Override Method and Properties #region Override Method and Properties
public override int BorderWidth { get { return (MyFlexGrid.Width - MyFlexGrid.ClientRectangle.Width); } } public override int BorderWidth { get { return (MyFlexGrid.Width - MyFlexGrid.ClientRectangle.Width); } }