296 lines
11 KiB
C#
296 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class StepTabRibbon : UserControl
|
|
{
|
|
private StepItem _MyStepItem;
|
|
public StepItem MyStepItem
|
|
{
|
|
get { return _MyStepItem; }
|
|
set
|
|
{
|
|
_MyStepItem = value;
|
|
if (value != null)
|
|
{
|
|
MyStepRTB = value.MyStepRTB;
|
|
}
|
|
}
|
|
}
|
|
private StepRTB _MyStepRTB;
|
|
public StepRTB MyStepRTB
|
|
{
|
|
get { return _MyStepRTB; }
|
|
set
|
|
{
|
|
_MyStepRTB = value;
|
|
if (value != null)
|
|
{
|
|
_ContextMenuBar.SetContextMenuEx(_MyStepRTB, btnCMRtfEdit);
|
|
_MyStepRTB.SelectionChanged += new EventHandler(MyStepRTB_SelectionChanged);
|
|
_MyStepRTB.Leave += new EventHandler(MyStepRTB_Leave);
|
|
_MyStepRTB.LinkChanged += new StepRTBLinkEvent(_MyStepRTB_LinkChanged);
|
|
SetButtonAndMenuEnabling();
|
|
}
|
|
}
|
|
}
|
|
void _MyStepRTB_LinkChanged(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
// do all Transition and ReferencedObject menu items/buttons based on whether a 'link is selected' and the link type.
|
|
btnCMGoTo.Enabled = btnGoTo.Enabled = _MyStepRTB.SelectionProtected;
|
|
if (btnCMGoTo.Enabled == true && _MyStepRTB.MyLinkText != null) // must have some link test, use it to set edit of transition or ro...
|
|
{
|
|
btnCMEditTran.Enabled = _MyStepRTB.MyLinkText.IndexOf("Transition") > -1; // selected link must be a transition
|
|
btnCMEditRO.Enabled = _MyStepRTB.MyLinkText.IndexOf("ReferencedObject") > -1; // selected link must be ro
|
|
}
|
|
else
|
|
{
|
|
btnCMEditTran.Enabled = false;
|
|
btnCMEditRO.Enabled = false;
|
|
}
|
|
}
|
|
void MyStepRTB_Leave(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.SelectionChanged -= new EventHandler(MyStepRTB_SelectionChanged);
|
|
_MyStepRTB.Leave -= new EventHandler(MyStepRTB_Leave);
|
|
_MyStepRTB.LinkChanged -= new StepRTBLinkEvent(_MyStepRTB_LinkChanged);
|
|
}
|
|
void MyStepRTB_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
SetButtonAndMenuEnabling();
|
|
}
|
|
private void SetButtonAndMenuEnabling()
|
|
{
|
|
if (_MyStepRTB == null) return;
|
|
if (_MyStepRTB.SelectionFont != null)
|
|
{
|
|
btnCMBold.Checked = btnBold.Checked = RTBAPI.IsBold(_MyStepRTB);
|
|
btnCMItalics.Checked = btnItalics.Checked = RTBAPI.IsItalic(_MyStepRTB);
|
|
btnCMUnderline.Checked = btnUnderline.Checked = RTBAPI.IsUnderline(_MyStepRTB);
|
|
btnCMSubscript.Checked = btnSubscript.Checked = RTBAPI.IsSubScript(_MyStepRTB);
|
|
btnCMSuperscript.Checked = btnSuperscript.Checked = RTBAPI.IsSuperScript(_MyStepRTB);
|
|
}
|
|
btnCMCut.Enabled = btnCMCopy.Enabled = btnCut.Enabled = btnCopy.Enabled = _MyStepRTB.SelectionLength > 0;
|
|
btnCMUndo.Enabled = btnUndo.Enabled = _MyStepRTB.CanUndo;
|
|
btnCMRedo.Enabled = btnRedo.Enabled = _MyStepRTB.CanRedo;
|
|
|
|
// for paste, see if there is clipboard data, & if so, of a type we can use.
|
|
IDataObject iData = Clipboard.GetDataObject();
|
|
btnCMPaste.Enabled = btnPaste.Enabled = (iData.GetDataPresent(DataFormats.Text) || iData.GetDataPresent(DataFormats.Rtf));
|
|
|
|
// do all Transition and ReferencedObject menu items/buttons based on whether a 'link is selected' and the link type.
|
|
btnCMGoTo.Enabled = btnGoTo.Enabled = _MyStepRTB.SelectionProtected; //(_MyStepRTB.MyLinkText != null);
|
|
if (btnCMGoTo.Enabled == true && _MyStepRTB.MyLinkText != null) // must have some link test, use it to set edit of transition or ro...
|
|
{
|
|
btnCMEditTran.Enabled = _MyStepRTB.MyLinkText.IndexOf("Transition")>-1; // selected link must be a transition
|
|
btnCMEditRO.Enabled = _MyStepRTB.MyLinkText.IndexOf("ReferencedObject") > -1; // selected link must be ro
|
|
}
|
|
else
|
|
{
|
|
btnCMEditTran.Enabled = false;
|
|
btnCMEditRO.Enabled = false;
|
|
}
|
|
}
|
|
public StepTabRibbon()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Add symbols to the tabribbon & also to the context menu getting info from the format file...
|
|
// Note that the ButtonItems must be used in order to place the buttons on a gallery (cannot
|
|
// use buttonx or dotnet/windows/button). However, you cannot change the font on ButtonItems so
|
|
// the ribbon MUST use the Arial Unicode MS Font for this to work!!!!
|
|
Format fmt = VEPROMS.CSLA.Library.Format.Get(1); //base for now - TO DO KBR:
|
|
SymbolList sl = fmt.PlantFormat.FormatData.SymbolList;
|
|
if (sl == null || sl.Count <= 0)
|
|
{
|
|
MessageBox.Show("No symbols are available, check with administrator");
|
|
return;
|
|
}
|
|
foreach (Symbol sym in sl)
|
|
{
|
|
DevComponents.DotNetBar.ButtonItem btn = new DevComponents.DotNetBar.ButtonItem();
|
|
btn.Text = string.Format("{0}", (char)sym.Unicode);
|
|
// to name button use unicode rather than desc, desc may have spaces or odd chars
|
|
btn.Name = "btn" + sym.Unicode.ToString();
|
|
btn.Tooltip = sym.Desc;
|
|
btn.Tag = string.Format(@"\u{0}", sym.Unicode);
|
|
btn.FontBold = true;
|
|
btn.Click += new System.EventHandler(btnSym_Click);
|
|
galleryContainerSymbols.SubItems.Add(btn);
|
|
DevComponents.DotNetBar.ButtonItem btnCM = new DevComponents.DotNetBar.ButtonItem();
|
|
btnCM.Text = string.Format("{0}", (char)sym.Unicode);
|
|
// to name button use unicode rather than desc, desc may have spaces or odd chars
|
|
btnCM.Name = "btnCM" + sym.Unicode.ToString();
|
|
btnCM.Tooltip = sym.Desc;
|
|
btnCM.Tag = string.Format(@"\u{0}", sym.Unicode);
|
|
btnCM.FontBold = true;
|
|
btnCM.Click += new System.EventHandler(btnSym_Click);
|
|
galleryContainerSymbolsCM.SubItems.Add(btnCM);
|
|
}
|
|
}
|
|
private void btnSym_Click(object sender, EventArgs e)
|
|
{
|
|
DevComponents.DotNetBar.ButtonItem b = (DevComponents.DotNetBar.ButtonItem)sender;
|
|
_MyStepRTB.InsertSymbol((string)b.Tag);
|
|
}
|
|
private void btnPaste_Click(object sender, EventArgs e)
|
|
{
|
|
IDataObject myDO = Clipboard.GetDataObject();
|
|
if (myDO.GetDataPresent(DataFormats.Rtf))
|
|
_MyStepRTB.SelectedRtf = myDO.GetData(DataFormats.Rtf).ToString();
|
|
else if (myDO.GetDataPresent(DataFormats.Text))
|
|
_MyStepRTB.SelectedText = myDO.GetData(DataFormats.Text).ToString();
|
|
}
|
|
private void btnCut_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear();
|
|
DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf);
|
|
Clipboard.SetDataObject(myDO);
|
|
_MyStepRTB.SelectedText = "";
|
|
}
|
|
private void btnCopy_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear();
|
|
DataObject myDO = new DataObject("Rich Text Format", _MyStepRTB.SelectedRtf);
|
|
Clipboard.SetDataObject(myDO);
|
|
}
|
|
private void btnBold_Click(object sender, EventArgs e)
|
|
{
|
|
RTBAPI.ToggleBold(!RTBAPI.IsBold(_MyStepRTB), _MyStepRTB, _MyStepRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
|
btnCMBold.Checked = btnBold.Checked = RTBAPI.IsBold(_MyStepRTB);
|
|
}
|
|
private void btnItalics_Click(object sender, EventArgs e)
|
|
{
|
|
RTBAPI.ToggleItalic(!RTBAPI.IsItalic(_MyStepRTB), _MyStepRTB, _MyStepRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
|
btnCMItalics.Checked = btnItalics.Checked = RTBAPI.IsItalic(_MyStepRTB);
|
|
}
|
|
private void btnUnderline_Click(object sender, EventArgs e)
|
|
{
|
|
RTBAPI.ToggleUnderline(!RTBAPI.IsUnderline(_MyStepRTB), _MyStepRTB, _MyStepRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
|
btnCMUnderline.Checked = btnUnderline.Checked = RTBAPI.IsUnderline(_MyStepRTB);
|
|
}
|
|
|
|
private void btnSuperscript_Click(object sender, EventArgs e)
|
|
{
|
|
RTBAPI.ToggleSuperscript(!RTBAPI.IsSuperScript(_MyStepRTB), _MyStepRTB, _MyStepRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
|
btnCMSuperscript.Checked = btnSuperscript.Checked = RTBAPI.IsSuperScript(_MyStepRTB);
|
|
}
|
|
|
|
private void btnSubscript_Click(object sender, EventArgs e)
|
|
{
|
|
RTBAPI.ToggleSubscript(!RTBAPI.IsSubScript(_MyStepRTB), _MyStepRTB, _MyStepRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
|
btnCMSubscript.Checked = btnSubscript.Checked = RTBAPI.IsSubScript(_MyStepRTB);
|
|
}
|
|
|
|
private void btnUppercase_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.SetSelectedCase('U');
|
|
}
|
|
|
|
private void btnLowercase_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.SetSelectedCase('l');
|
|
}
|
|
|
|
private void btnTitleCase_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.SetSelectedCase('T');
|
|
}
|
|
private void btnInsTrans_Click(object sender, EventArgs e)
|
|
{
|
|
// see if user is positioned 'on' a transition within the rtb, if so do a modify, otherwise,
|
|
// insert transition.
|
|
StepTabPanel tmp = Parent as StepTabPanel;
|
|
tmp.MyDisplayTabControl.OnLinkModifyTran(this, new StepPanelLinkEventArgs(_MyStepItem, MyStepRTB.MyLinkText));
|
|
}
|
|
|
|
private void btnInsHrdSpc_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.InsertSymbol(@"\u160?");
|
|
}
|
|
|
|
private void btnInsRO_Click(object sender, EventArgs e)
|
|
{
|
|
// see if user is positioned 'on' an ReferencedObject within the rtb, if so do a modify, otherwise,
|
|
// insert transition.
|
|
StepTabPanel tmp = Parent as StepTabPanel;
|
|
tmp.MyDisplayTabControl.OnLinkModifyRO(this, new StepPanelLinkEventArgs(_MyStepItem, MyStepRTB.MyLinkText));
|
|
}
|
|
|
|
private void btnRedo_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.Redo();
|
|
}
|
|
|
|
private void btnUndo_Click(object sender, EventArgs e)
|
|
{
|
|
_MyStepRTB.Undo();
|
|
}
|
|
private void btnGoTo_Click(object sender, EventArgs e)
|
|
{
|
|
// if on a transition, go to the selected transition 'to'. If on
|
|
// a referenced object, bring up ReferencedObject Editor (for now, just put up a message box.
|
|
if (_MyStepRTB.MyLinkText.IndexOf("Transition") > -1)
|
|
{
|
|
_MyStepItem.MyStepPanel.OnLinkClicked(sender, new StepPanelLinkEventArgs(_MyStepItem, _MyStepRTB.MyLinkText));
|
|
}
|
|
else
|
|
{
|
|
// bring up ro editor - for now just do a messagebox.
|
|
MessageBox.Show("Bring up ro editor");
|
|
}
|
|
}
|
|
|
|
private void rpanInsert_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
#if DEBUG
|
|
// The following code generates an XML output for the selected item for print testing.
|
|
private void btnPageBreak_Click(object sender, EventArgs e)
|
|
{
|
|
// This is here temporarily to get a node and all of it's children for print testing.
|
|
OutputAllChildren(MyStepItem);
|
|
}
|
|
private void OutputAllChildren(StepItem myStepItem)
|
|
{
|
|
OutputAllChildren(myStepItem.MyBeforeStepItems);
|
|
OutputStepInfo(myStepItem);
|
|
OutputAllChildren(myStepItem.MyAfterStepItems);
|
|
OutputAllChildren(myStepItem.MyRNOStepItems);
|
|
}
|
|
private void OutputStepInfo(StepItem myStepItem)
|
|
{
|
|
Label lbl = myStepItem.MyLabel;
|
|
if (lbl.Text.Trim() != "")
|
|
Console.WriteLine("<text x='{0}In' y='{1}In' font-family='{2}' font-size='{3}Pt'>{4}</text>",
|
|
ToInches(myStepItem.Left + lbl.Left), ToInches(myStepItem.Top + lbl.Top),
|
|
lbl.Font.FontFamily.Name,lbl.Font.SizeInPoints,lbl.Text);
|
|
StepRTB rtb = myStepItem.MyStepRTB;
|
|
Console.WriteLine("<foreignObject x='{0}In' y='{1}In' width='{2}In' " +
|
|
"requiredExtensions='http://Volian.Com/EmbeddedRTF'>{3}</foreignObject>",
|
|
ToInches(myStepItem.Left + rtb.Left), ToInches(myStepItem.Top + rtb.Top), ToInches(rtb.Width), myStepItem.MyItemInfo.MyContent.Text);
|
|
// ToInches(myStepItem.Left + rtb.Left), ToInches(myStepItem.Top + rtb.Top), ToInches(rtb.Width), rtb.Rtf);
|
|
}
|
|
private float ToInches(int val)
|
|
{
|
|
return Convert.ToSingle(val)/96F;
|
|
}
|
|
|
|
private void OutputAllChildren(List<StepItem> list)
|
|
{
|
|
if(list != null)
|
|
foreach (StepItem itm in list)
|
|
OutputAllChildren(itm);
|
|
}
|
|
#endif
|
|
}
|
|
}
|