B2020-018: table font size – short cut keys not catching limits & selection not kept when using buttons

This commit is contained in:
Kathy Ruffing 2020-02-13 13:46:09 +00:00
parent c4026b688e
commit 9fae7d8e38
3 changed files with 52 additions and 38 deletions

View File

@ -2161,6 +2161,15 @@ namespace Volian.Controls.Library
case Keys.Oemplus: // the plus on the keyboard (not the key pad) case Keys.Oemplus: // the plus on the keyboard (not the key pad)
e.Handled = true; e.Handled = true;
break; break;
// B2020-018: Oemcomma & OemPeriod are short cut keys for changing the font size - only do this if in a table:
case Keys.Oemcomma: // '<'
if (_MyItemInfo != null && _MyItemInfo.IsTable && !IsRoTable) SetFontSize(false);
e.Handled = true;
break;
case Keys.OemPeriod: // '>'
if (_MyItemInfo != null && _MyItemInfo.IsTable && !IsRoTable) SetFontSize(true);
e.Handled = true;
break;
} }
} }
else else
@ -2618,6 +2627,46 @@ namespace Volian.Controls.Library
} }
} }
//B2020-018: SetFontSize and SetFontSizeReplace were moved from StepTabRibbon so that the short cut keys could also
// access the code that puts boundaries on font size.
// SetFontSize: replace rtf string of selection or entire rtb
public void SetFontSize(bool increase)
{
if (SelectedText == null || SelectedText == "")
Rtf = SetFontSizeReplace(Rtf, increase);
else
{
int selst = SelectionStart;
int selln = SelectionLength;
SelectedRtf = SetFontSizeReplace(SelectedRtf, increase);
Select(selst, selln);
}
}
private string SetFontSizeReplace(string rtf, bool increase)
{
MatchCollection mc = Regex.Matches(rtf, @"\\fs([0-9]+)");
bool didMsg = false;
foreach (Match match in mc)
{
float sz = float.Parse(match.Groups[1].Value);
float repwith = increase ? sz + 1 : sz - 1;
if (repwith > 36 || repwith < 16) // Font size can be increased to 18 and decreased to 8 (note that \fs## has number 2 * pt)
{
if (!didMsg) // only put out message once.
{
MessageBox.Show(increase ? "Reached maximum font size, cannot increase." : "Reached minimum font size, cannot decrease.", "Warning font size change");
didMsg = true;
}
}
else
{
string repsz = match.Value; // use \fs## rather than number in replace in case text contains the number
string repwithsz = match.Value.Replace(sz.ToString(), ((int)repwith).ToString());
rtf = rtf.Replace(repsz, repwithsz);
}
}
return rtf;
}
private static Form ParentForm(Control ctrl) private static Form ParentForm(Control ctrl)
{ {
while (!(ctrl.Parent is Form || ctrl.Parent is EditItem)) while (!(ctrl.Parent is Form || ctrl.Parent is EditItem))

View File

@ -2531,50 +2531,15 @@ namespace Volian.Controls.Library
MyStepRTB.Select(0, 0); MyStepRTB.Select(0, 0);
break; break;
} }
SetFontSize(MyStepRTB, increase); MyStepRTB.SetFontSize(increase);
} }
MyFlexGrid.Select(cr); MyFlexGrid.Select(cr);
} }
else else
SetFontSize(MyStepRTB, increase); // not in a grid, apply style to current step type MyStepRTB.SetFontSize(increase); // not in a grid, apply style to current step type
} }
else else
SetFontSize(MyStepRTB, increase); MyStepRTB.SetFontSize(increase);
}
// SetFontSize: replace rtf string of selection or entire rtb
private void SetFontSize(StepRTB MyStepRTB, bool increase)
{
if (MyStepRTB.SelectedText == null || MyStepRTB.SelectedText == "")
MyStepRTB.Rtf = SetFontSizeReplace(MyStepRTB.Rtf, increase);
else
MyStepRTB.SelectedRtf = SetFontSizeReplace(MyStepRTB.SelectedRtf, increase);
}
// SetFontSizeReplace: for the input string, increase or decrease the font size - use a regular expression to get
// all current font sizes in the string & increase them all.
private string SetFontSizeReplace(string rtf, bool increase)
{
MatchCollection mc = Regex.Matches(rtf, @"\\fs([0-9]+)");
bool didMsg = false;
foreach (Match match in mc)
{
float sz = float.Parse(match.Groups[1].Value);
float repwith = increase ? sz + 1 : sz - 1;
if (repwith > 36 || repwith < 16) // Font size can be increased to 18 and decreased to 8 (note that \fs## has number 2 * pt)
{
if (!didMsg) // only put out message once.
{
MessageBox.Show(increase ? "Reached maximum font size, cannot increase." : "Reached minimum font size, cannot decrease.", "Warning font size change");
didMsg = true;
}
}
else
{
string repsz = match.Value; // use \fs## rather than number in replace in case text contains the number
string repwithsz = match.Value.Replace(sz.ToString(), ((int)repwith).ToString());
rtf = rtf.Replace(repsz, repwithsz);
}
}
return rtf;
} }
private void ToggleBold() private void ToggleBold()
{ {