2008-06-04 11:34:56 +00:00

247 lines
9.6 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.MyLinkText != null);
if (btnCMGoTo.Enabled == true) // 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
}
}
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.MyLinkText != null);
if (btnCMGoTo.Enabled == true) // 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
}
}
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)
{
}
}
}