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 DisplayTabRibbon : UserControl { private StepItem _MyDisplayItem; public StepItem MyDisplayItem { get { return _MyDisplayItem; } set { _MyDisplayItem = value; if (value != null) { _MyDisplayRTB = value.MyDisplayRTB; } } } private StepRTB _MyDisplayRTB; public StepRTB MyDisplayRTB { get { return _MyDisplayRTB; } set { _MyDisplayRTB = value; if (value != null) { _ContextMenuBar.SetContextMenuEx(_MyDisplayRTB, btnCMRtfEdit); _MyDisplayRTB.SelectionChanged += new EventHandler(MyDisplayRTB_SelectionChanged); _MyDisplayRTB.Leave += new EventHandler(MyDisplayRTB_Leave); } } } void MyDisplayRTB_Leave(object sender, EventArgs e) { _MyDisplayRTB.SelectionChanged -= new EventHandler(MyDisplayRTB_SelectionChanged); _MyDisplayRTB.Leave -= new EventHandler(MyDisplayRTB_Leave); } void MyDisplayRTB_SelectionChanged(object sender, EventArgs e) { btnCMBold.Checked = btnBold.Checked = _MyDisplayRTB.SelectionFont.Bold; btnCMItalics.Checked = btnItalics.Checked = _MyDisplayRTB.SelectionFont.Italic; btnCMUnderline.Checked = btnUnderline.Checked = _MyDisplayRTB.SelectionFont.Underline; btnCMSubscript.Checked = btnSubscript.Checked = RTBAPI.IsSubScript(_MyDisplayRTB); btnCMSuperscript.Checked = btnSuperscript.Checked = RTBAPI.IsSuperScript(_MyDisplayRTB); btnCMCut.Enabled = btnCMCopy.Enabled = btnCut.Enabled = btnCopy.Enabled = _MyDisplayRTB.SelectionLength > 0; } public DisplayTabRibbon() { 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; _MyDisplayRTB.InsertSymbol((string)b.Tag); } private void btnPaste_Click(object sender, EventArgs e) { IDataObject myDO = Clipboard.GetDataObject(); if (myDO.GetDataPresent("Rich Text Format")) _MyDisplayRTB.SelectedRtf = myDO.GetData("Rich Text Format").ToString(); else if (myDO.GetDataPresent("Text")) _MyDisplayRTB.SelectedText = myDO.GetData("Text").ToString(); } private void btnCut_Click(object sender, EventArgs e) { Clipboard.Clear(); DataObject myDO = new DataObject("Rich Text Format", _MyDisplayRTB.SelectedRtf); Clipboard.SetDataObject(myDO); _MyDisplayRTB.SelectedText = ""; } private void btnCopy_Click(object sender, EventArgs e) { Clipboard.Clear(); DataObject myDO = new DataObject("Rich Text Format", _MyDisplayRTB.SelectedRtf); Clipboard.SetDataObject(myDO); } private void btnBold_Click(object sender, EventArgs e) { FontStyle fs = _MyDisplayRTB.SelectionFont.Style ^ FontStyle.Bold; _MyDisplayRTB.SelectionFont = new Font(_MyDisplayRTB.SelectionFont, fs); btnCMBold.Checked = btnBold.Checked = _MyDisplayRTB.SelectionFont.Bold; } private void btnItalics_Click(object sender, EventArgs e) { FontStyle fs = _MyDisplayRTB.SelectionFont.Style ^ FontStyle.Italic; _MyDisplayRTB.SelectionFont = new Font(_MyDisplayRTB.SelectionFont, fs); btnCMItalics.Checked = btnItalics.Checked = _MyDisplayRTB.SelectionFont.Italic; } private void btnUnderline_Click(object sender, EventArgs e) { FontStyle fs = _MyDisplayRTB.SelectionFont.Style ^ FontStyle.Underline; _MyDisplayRTB.SelectionFont = new Font(_MyDisplayRTB.SelectionFont, fs); btnCMUnderline.Checked = btnUnderline.Checked = _MyDisplayRTB.SelectionFont.Underline; } private void btnSuperscript_Click(object sender, EventArgs e) { RTBAPI.ToggleSuperscript(!RTBAPI.IsSuperScript(_MyDisplayRTB), _MyDisplayRTB, _MyDisplayRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); btnCMSuperscript.Checked = btnSuperscript.Checked = RTBAPI.IsSuperScript(_MyDisplayRTB); } private void btnSubscript_Click(object sender, EventArgs e) { RTBAPI.ToggleSubscript(!RTBAPI.IsSubScript(_MyDisplayRTB), _MyDisplayRTB, _MyDisplayRTB.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION); btnCMSubscript.Checked = btnSubscript.Checked = RTBAPI.IsSubScript(_MyDisplayRTB); } private void btnUppercase_Click(object sender, EventArgs e) { _MyDisplayRTB.SetSelectedCase('U'); } private void btnLowercase_Click(object sender, EventArgs e) { _MyDisplayRTB.SetSelectedCase('l'); } private void btnTitleCase_Click(object sender, EventArgs e) { _MyDisplayRTB.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.MyTabControl.OnLinkModifyTran(this, new DisplayLinkEventArgs(_MyDisplayItem, null)); } private void btnInsHrdSpc_Click(object sender, EventArgs e) { _MyDisplayRTB.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.MyTabControl.OnLinkModifyRO(this, new DisplayLinkEventArgs(_MyDisplayItem, null)); } private void btnRedo_Click(object sender, EventArgs e) { _MyDisplayRTB.Redo(); } private void btnUndo_Click(object sender, EventArgs e) { _MyDisplayRTB.Undo(); } } }