194 lines
6.9 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);
}
}
}
void MyStepRTB_Leave(object sender, EventArgs e)
{
_MyStepRTB.SelectionChanged -= new EventHandler(MyStepRTB_SelectionChanged);
_MyStepRTB.Leave -= new EventHandler(MyStepRTB_Leave);
}
void MyStepRTB_SelectionChanged(object sender, EventArgs e)
{
btnCMBold.Checked = btnBold.Checked = _MyStepRTB.SelectionFont.Bold;
btnCMItalics.Checked = btnItalics.Checked = _MyStepRTB.SelectionFont.Italic;
btnCMUnderline.Checked = btnUnderline.Checked = _MyStepRTB.SelectionFont.Underline;
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;
}
public StepTabRibbon()
{
InitializeComponent();
// get the xml for all of the symbols, create buttons for them & add them to the gallery.
// Note that this code was added here rather than in DisplayTabRinnon.designer.cs because
// if it is in the designer, this tabribbon could not be brought up in the VS form designer!
// Also 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);
}
}
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("Rich Text Format"))
_MyStepRTB.SelectedRtf = myDO.GetData("Rich Text Format").ToString();
else if (myDO.GetDataPresent("Text"))
_MyStepRTB.SelectedText = myDO.GetData("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)
{
FontStyle fs = _MyStepRTB.SelectionFont.Style ^ FontStyle.Bold;
_MyStepRTB.SelectionFont = new Font(_MyStepRTB.SelectionFont, fs);
btnCMBold.Checked = btnBold.Checked = _MyStepRTB.SelectionFont.Bold;
}
private void btnItalics_Click(object sender, EventArgs e)
{
FontStyle fs = _MyStepRTB.SelectionFont.Style ^ FontStyle.Italic;
_MyStepRTB.SelectionFont = new Font(_MyStepRTB.SelectionFont, fs);
btnCMItalics.Checked = btnItalics.Checked = _MyStepRTB.SelectionFont.Italic;
}
private void btnUnderline_Click(object sender, EventArgs e)
{
FontStyle fs = _MyStepRTB.SelectionFont.Style ^ FontStyle.Underline;
_MyStepRTB.SelectionFont = new Font(_MyStepRTB.SelectionFont, fs);
btnCMUnderline.Checked = btnUnderline.Checked = _MyStepRTB.SelectionFont.Underline;
}
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');
}
//public event DisplayRTBLinkEvent LinkInsertTran;
//private void OnLinkInsertTran(object sender, LinkClickedEventArgs args)
//{
// _LinkClickedEventArgs = args;
// if (LinkInsertTran != null) LinkInsertTran(sender, args);
//}
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, null));
}
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 RO within the rtb, if so do a modify, otherwise,
// insert transition.
StepTabPanel tmp = Parent as StepTabPanel;
tmp.MyDisplayTabControl.OnLinkModifyRO(this, new StepPanelLinkEventArgs(_MyStepItem, null));
}
private void btnRedo_Click(object sender, EventArgs e)
{
_MyStepRTB.Redo();
}
private void btnUndo_Click(object sender, EventArgs e)
{
_MyStepRTB.Undo();
}
}
}