Equation Editor interface support

This commit is contained in:
2016-11-17 15:05:15 +00:00
parent 3e212834ea
commit 0b7371367c
26 changed files with 2129 additions and 855 deletions

View File

@@ -688,7 +688,7 @@ namespace Volian.Controls.Library
}
public StepRTB(IContainer container)
{
container.Add(this);
container.Add(this);
InitializeComponent();
_Container = container;
SetUpStepRTB();
@@ -833,7 +833,7 @@ namespace Volian.Controls.Library
}
void StepRTB_SelectionChanged(object sender, EventArgs e)
{
if (_InitializingRTB || _IsExperimenting) return;
if (_InitializingRTB || _IsExperimenting || (MyItemInfo!=null && MyItemInfo.IsRtfRaw)) return;
HandleSelectionChange();
}
private bool _MouseDown = false;
@@ -848,6 +848,7 @@ namespace Volian.Controls.Library
OnSetMenu(this, new StepRTBMenuEventArgs(inPsi?"PSI":"OpenContextMenu"));
_ContextMenuStripChanged = false;
CorrectSelectionAtEndOfLine();
if (e.Button == System.Windows.Forms.MouseButtons.Right && MyItemInfo.IsRtfRaw) OnSetMenu(this, new StepRTBMenuEventArgs("OpenRtfRawContextMenu"));
_MouseDown = true;
}
void StepRTB_MouseUp(object sender, MouseEventArgs e)
@@ -1049,6 +1050,13 @@ namespace Volian.Controls.Library
}
public void AddRtfText(string txt)
{
if (MyItemInfo != null && MyItemInfo.IsRtfRaw)
{
if (txt != null && txt != "") SelectedRtf = _LastRtf = txt;
_lastReadOnly = ReadOnly;
OrigRTF = txt;
return;
}
//Console.WriteLine("ItemID:{0}", MyItemInfo.ItemID);
//if(MyItemInfo.ItemID==10256)
// Volian.Base.Library.vlnStackTrace.ShowStackLocal("ItemID:{0}", MyItemInfo.ItemID.ToString());
@@ -1528,6 +1536,7 @@ namespace Volian.Controls.Library
private bool _HandlingCtrlA = false;
private void HandleLocalSelectionChange()
{
if (this.MyItemInfo.IsRtfRaw) return;
//if (MyRTBItem != null && MyRTBItem.MyStepPanel.SelectedStepRTB != this)
if (OnIsNotCurrentSelection(this, new EventArgs()))
return;
@@ -1885,6 +1894,10 @@ namespace Volian.Controls.Library
{
switch (e.KeyCode)
{
case Keys.E:
OnSetMenu(this, new StepRTBMenuEventArgs("InsEquation"));
e.Handled = true;
break;
case Keys.F:
OnSetMenu(this, new StepRTBMenuEventArgs("InsFigure"));
e.Handled = true;
@@ -1916,6 +1929,11 @@ namespace Volian.Controls.Library
}
}
}
if (MyItemInfo.IsRtfRaw)
{
e.Handled = true;
return;
}
if (!e.Shift) return;
switch (e.KeyCode)
{
@@ -1993,6 +2011,16 @@ namespace Volian.Controls.Library
// added jcb 20130103 to support set ro from word doc with annotation when right click menu is opened by keyboard
if (e.KeyCode == Keys.Apps)
OnSetMenu(this, new StepRTBMenuEventArgs("OpenContextMenu"));
// the following code only allows arrow keys & pageup/down for rtf raw items:
if (!e.Control && !e.Shift && MyItemInfo != null && MyItemInfo.IsRtfRaw) // error message is displayed in keypress for this.
{
if (e.KeyCode != Keys.Up && e.KeyCode != Keys.Down && e.KeyCode != Keys.Right && e.KeyCode != Keys.Left && e.KeyCode != Keys.PageDown && e.KeyCode != Keys.PageUp)
{
e.Handled = true;
return;
}
}
if (e.Control)
{
IsControlChar = true;
@@ -2036,6 +2064,46 @@ namespace Volian.Controls.Library
// maps the Ctrl-V to btnPaste for those StepRTB's that are associated with the StepTabRibbon, i.e.
// EditItems & Grid cells.
IDataObject iData = Clipboard.GetDataObject();
// verify that data in clipboard is valid for this type. If inserting an equation, need to verify that
// input data has an 'equation', and if not inserting into an equation step type, it must not have
// equation data.
DataFormats.Format frm = DataFormats.GetFormat("Embed Source");
System.Windows.Forms.RichTextBox richTextBox1;
richTextBox1 = new System.Windows.Forms.RichTextBox();
richTextBox1.Location = new System.Drawing.Point(35, 32);
richTextBox1.Name = "richTextBox1";
richTextBox1.Size = new System.Drawing.Size(67, 58);
richTextBox1.TabIndex = 0;
richTextBox1.Text = "";
richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
bool hasEquation = false;
try
{
richTextBox1.Paste(frm);
// if (richTextBox1.Rtf.ToUpper().Contains("EQUAT") || richTextBox1.Rtf.ToUpper().Contains("VISIO")) hasEquation = true;
if (richTextBox1.Rtf.ToUpper().Contains("EQUAT")) hasEquation = true;
}
catch (Exception ex)
{
hasEquation = true;
}
if (MyItemInfo != null && MyItemInfo.IsRtfRaw && MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION") && !hasEquation)
{
MessageBox.Show("Cannot paste non-equation data into an equation step type.", "Invalid data", MessageBoxButtons.OK);
richTextBox1.Dispose();
e.Handled = true;
return;
}
// if inserting anything other than equation, be sure that an equation is not in the buffer:
else if (hasEquation && (MyItemInfo==null || (MyItemInfo != null && !MyItemInfo.IsRtfRaw && !MyItemInfo.FormatStepData.Type.ToUpper().Contains("EQUATION"))))
{
MessageBox.Show("Cannot paste equation data into an non-equation step type.", "Invalid data", MessageBoxButtons.OK);
richTextBox1.Dispose();
e.Handled = true;
return;
}
// only allow the paste of a screen shot image if using the shortcut switch "/EmbedImages"
if (Volian.Base.Library.VlnSettings.GetCommandFlag("EmbedImages") && iData.GetDataPresent(DataFormats.Dib)) // Device Independent Bitmap
{
@@ -2046,6 +2114,15 @@ namespace Volian.Controls.Library
e.Handled = true;
return;
}
else if (iData.GetDataPresent("Embed Source")) //DS Equation") || iData.GetDataPresent("MathType EF"))
{
Size sz = RtfRawItem.GetRtfRawSize(richTextBox1.Rtf);
this.Rtf = richTextBox1.Rtf;
Width = sz.Width;
Height = sz.Height;
e.Handled = true;
return;
}
else if (iData.GetDataPresent(DataFormats.Dib))
{
System.Drawing.Image img = Clipboard.GetImage();
@@ -2402,6 +2479,7 @@ namespace Volian.Controls.Library
}
e.Handled = true;
}
}
private static Form ParentForm(Control ctrl)
{
@@ -2433,6 +2511,13 @@ namespace Volian.Controls.Library
{
if (!ReadOnly)
{
if (!IsControlChar && MyItemInfo != null && MyItemInfo.IsRtfRaw)
{
string err = string.Format("Cannot enter text into an equation or incorrect keystroke entered for equation");
MessageBox.Show(err, "Invalid text.", MessageBoxButtons.OK);
e.Handled = true;
return;
}
if (Text == "" && Parent != null && Parent is VlnFlexGrid)
{
//ShowMyParentsFonts();