This commit is contained in:
749
PROMS/Volian.Controls.Library/StepRTB.cs
Normal file
749
PROMS/Volian.Controls.Library/StepRTB.cs
Normal file
@@ -0,0 +1,749 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using VEPROMS.CSLA.Library;
|
||||
|
||||
namespace Volian.Controls.Library
|
||||
{
|
||||
public delegate void DisplayRTBEvent(object sender, EventArgs args);
|
||||
public partial class DisplayRTB : RichTextBox
|
||||
{
|
||||
#region Properties and Variables
|
||||
// use newer rich text box....
|
||||
//[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||
//static extern IntPtr LoadLibrary(string lpFileName);
|
||||
//protected override CreateParams CreateParams
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// CreateParams prams = base.CreateParams;
|
||||
// if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
|
||||
// {
|
||||
// //prams.ExStyle |= 0x020; // transparent
|
||||
|
||||
// prams.ClassName = "RICHEDIT50W";
|
||||
// }
|
||||
// return prams;
|
||||
// }
|
||||
//}
|
||||
private bool _IsDirty = false;
|
||||
private bool _InitializingRTB;
|
||||
private IContainer _Container = null;
|
||||
private string _MyClassName=string.Empty;
|
||||
public string MyClassName
|
||||
{
|
||||
get { if (_MyClassName == string.Empty)_MyClassName = CreateParams.ClassName; return _MyClassName; }
|
||||
set { _MyClassName = value; }
|
||||
}
|
||||
private E_EditPrintMode _epMode = E_EditPrintMode.Edit;
|
||||
public E_EditPrintMode EpMode
|
||||
{
|
||||
get { return _epMode; }
|
||||
set { _epMode = value; }
|
||||
}
|
||||
private E_ViewMode _vwMode = E_ViewMode.Edit;
|
||||
public E_ViewMode VwMode
|
||||
{
|
||||
get { return _vwMode; }
|
||||
set { _vwMode = value; }
|
||||
}
|
||||
private ItemInfo _MyItem;
|
||||
public ItemInfo MyItem
|
||||
{
|
||||
get { return _MyItem; }
|
||||
set
|
||||
{
|
||||
_MyItem = value;
|
||||
if (value != null)
|
||||
{
|
||||
_InitializingRTB = true;
|
||||
DisplayText vlntxt = new DisplayText(_MyItem, EpMode, VwMode);
|
||||
_origVlnText = vlntxt;
|
||||
Font = _origVlnText.TextFont.WindowsFont;
|
||||
AddRtfText(vlntxt);
|
||||
ReadOnly = !(EpMode == E_EditPrintMode.Edit && VwMode == E_ViewMode.Edit);
|
||||
RTBAPI.SetLineSpacing(this, RTBAPI.ParaSpacing.PFS_EXACT);
|
||||
_InitializingRTB = false;
|
||||
_IsDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//public EnterKeyHandler EnterKeyPressed;
|
||||
//protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
//{
|
||||
// const int WM_KEYDOWN = 0x100;
|
||||
// const int WM_SYSKEYDOWN = 0x104;
|
||||
// if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
|
||||
// {
|
||||
// switch (keyData)
|
||||
// {
|
||||
// case Keys.Control | Keys.V:
|
||||
// // check for valid data to be inserted:
|
||||
// return base.ProcessCmdKey(ref msg, keyData);
|
||||
// default:
|
||||
// return base.ProcessCmdKey(ref msg, keyData);
|
||||
// }
|
||||
// }
|
||||
// return base.ProcessCmdKey(ref msg, keyData);
|
||||
//}
|
||||
private Point ScrollPos
|
||||
{
|
||||
get { return RTBAPI.GetScrollLocation(this); }
|
||||
set { RTBAPI.SetScrollLocation(this, value); }
|
||||
}
|
||||
private Rectangle _ContentsRectangle;
|
||||
public Rectangle ContentsRectangle
|
||||
{
|
||||
get { return _ContentsRectangle; }
|
||||
set
|
||||
{
|
||||
_ContentsRectangle = value;
|
||||
AdjustSizeForContents();
|
||||
}
|
||||
}
|
||||
public Size ContentsSize
|
||||
{
|
||||
get { return _ContentsRectangle.Size; }
|
||||
}
|
||||
private Size _AdjustSize; // if 0,0 puts text right next to bottom of box.
|
||||
public Size AdjustSize
|
||||
{
|
||||
get { return _AdjustSize; }
|
||||
set
|
||||
{
|
||||
_AdjustSize = value;
|
||||
AdjustSizeForContents();
|
||||
}
|
||||
}
|
||||
public System.Windows.Forms.AutoScaleMode AutoScaleMode;
|
||||
private DisplayText _origVlnText;
|
||||
private RichTextBox _rtbTemp = new RichTextBox();
|
||||
private string _MyLinkText;
|
||||
|
||||
public string MyLinkText
|
||||
{
|
||||
get { return _MyLinkText; }
|
||||
set
|
||||
{
|
||||
if (value != _MyLinkText)
|
||||
{
|
||||
_MyLinkText = value;
|
||||
OnLinkChanged(this, new LinkClickedEventArgs(_MyLinkText));
|
||||
Console.WriteLine("DisplayRTB - MyLinkText changed {0}", _MyLinkText);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// vlnRichTextBox constructor:
|
||||
/// Creates a MyDisplayRTB with extra support for veproms editing/printing.
|
||||
/// Arguments are:
|
||||
/// string txtbxname - name to give box (is this needed)
|
||||
/// ItemInfo itm - Item for which box is created
|
||||
/// int x,y - starting position for box
|
||||
/// int iwid - width of box
|
||||
/// int tbindx - tab index
|
||||
/// E_EditPrintMode ep_mode - edit or print.
|
||||
/// E_ViewMode vw_mode - view or edit.
|
||||
/// </summary>
|
||||
public DisplayRTB()
|
||||
{
|
||||
InitializeComponent();
|
||||
SetUp();
|
||||
}
|
||||
public DisplayRTB(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
InitializeComponent();
|
||||
_Container = container;
|
||||
SetUp();
|
||||
}
|
||||
private void SetUp()
|
||||
{
|
||||
BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.DetectUrls = true;
|
||||
ContextMenuStrip = contextMenuStrip;
|
||||
ContentsResized += new ContentsResizedEventHandler(DisplayRTB_ContentsResized);
|
||||
this.LinkClicked += new LinkClickedEventHandler(DisplayRTB_LinkClicked);
|
||||
this.Click +=new EventHandler(DisplayRTB_Click);
|
||||
this.KeyPress += new KeyPressEventHandler(DisplayRTB_KeyPress);
|
||||
this.KeyUp += new KeyEventHandler(DisplayRTB_KeyUp);
|
||||
this.KeyDown += new KeyEventHandler(DisplayRTB_KeyDown);
|
||||
this.TextChanged += new EventHandler(DisplayRTB_TextChanged);
|
||||
//this.SelectionChanged += new EventHandler(DisplayRTB_SelectionChanged);
|
||||
}
|
||||
|
||||
private void DisplayRTB_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
if (!SelectionProtected)
|
||||
{
|
||||
MyLinkText = null;
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayRTB_SelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
Console.WriteLine("SelectionStart {0}, SelectionLength {1}", SelectionStart, SelectionLength);
|
||||
if (!SelectionProtected && MyLinkText != null)
|
||||
MyLinkText = null;
|
||||
// TODO: Else Set mylinktext to what is currently selected (null if not on link, otherwise link info)
|
||||
// TODO: Raise event if moving on (modify) or moving off (insert)
|
||||
}
|
||||
#endregion
|
||||
#region ApplicationSupport
|
||||
public void ToggleViewEdit()
|
||||
{
|
||||
ItemInfo tmp = MyItem;
|
||||
MyItem = null;
|
||||
ReadOnly = !ReadOnly;
|
||||
EpMode = ReadOnly ? E_EditPrintMode.Print : E_EditPrintMode.Edit;
|
||||
VwMode = ReadOnly ? E_ViewMode.View : E_ViewMode.Edit;
|
||||
Clear();
|
||||
MyItem = tmp;
|
||||
}
|
||||
public void InsertRO(string value, string link)
|
||||
{
|
||||
AddRtfLink(value, link);
|
||||
}
|
||||
public void InsertTran(string value, string link)
|
||||
{
|
||||
AddRtfLink(value, link);
|
||||
}
|
||||
public void InsertSymbol(string symbol)
|
||||
{
|
||||
AddSymbol(symbol);
|
||||
}
|
||||
#endregion
|
||||
#region SaveData
|
||||
public void SaveText()
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
if (!_IsDirty) return;
|
||||
bool success = _origVlnText.Save((RichTextBox)this);
|
||||
if (!success) Console.WriteLine("Failed to save text: {0}", this.Text);
|
||||
}
|
||||
#endregion
|
||||
#region AddRtfText
|
||||
private void AddRtfText(DisplayText vlntext)
|
||||
{
|
||||
foreach (displayTextElement vte in vlntext.DisplayTextElementList)
|
||||
{
|
||||
if (vte.Type == E_TextElementType.TEXT)
|
||||
AddRtf(vte);
|
||||
else if (vte.Type == E_TextElementType.SYMBOL)
|
||||
AddSymbol(vte);
|
||||
else
|
||||
AddRtfLink((displayLinkElement)vte);
|
||||
}
|
||||
}
|
||||
private void AddRtf(displayTextElement vte)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 "+this.Font.FontFamily.Name+@";}}\f0\fs" + this.Font.SizeInPoints*2 + " " + vte.Text + @"}}";
|
||||
}
|
||||
private void AddRtf(string str)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset2 " + this.Font.FontFamily.Name + @";}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + str + @"}}";
|
||||
}
|
||||
private void AddSymbol(displayTextElement vte)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + vte.Text + @"}";
|
||||
}
|
||||
private void AddSymbol(string str)
|
||||
{
|
||||
SelectedRtf = @"{\rtf1{\fonttbl{\f0\fcharset0 Arial Unicode MS;}}\f0\fs" + this.Font.SizeInPoints * 2 + " " + /* ConvertUnicodeChar(str) */ str + @"}";
|
||||
}
|
||||
private void AddRtfLink(displayLinkElement vte)
|
||||
{
|
||||
if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
|
||||
AddLink50(vte.Text, vte.Link);
|
||||
else
|
||||
|
||||
AddLink20(vte.Text, vte.Link);
|
||||
}
|
||||
public void AddRtfLink(string linkUrl, string linkValue)
|
||||
{
|
||||
if (CreateParams.ClassName == "RICHEDIT50W")
|
||||
|
||||
AddLink50(linkUrl, linkValue);
|
||||
else
|
||||
|
||||
AddLink20(linkUrl, linkValue);
|
||||
}
|
||||
private void AddLink20(string linkValue, string linkUrl)
|
||||
{
|
||||
this.DetectUrls = false;
|
||||
RTBAPI.CharFormatTwo charFormat = RTBAPI.GetCharFormat(this, RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
int position = SelectionStart; // before inserttran = this.TextLength;
|
||||
SelectionLength = 0;
|
||||
SelectedRtf = @"{\rtf1\ansi " + linkValue + @"\v " + linkUrl + @"\v0}";
|
||||
Select(position, linkValue.Length + linkUrl.Length);
|
||||
// Protect the link text to avoid manual changes
|
||||
charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED;
|
||||
charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED;
|
||||
RTBAPI.SetCharFormat((RichTextBox)this, RTBAPI.RTBSelection.SCF_SELECTION, charFormat);
|
||||
this.SelectionStart = this.TextLength;
|
||||
this.SelectionLength = 0;
|
||||
}
|
||||
private void AddLink50(string linkValue, string linkUrl)
|
||||
{
|
||||
this.DetectUrls = false;
|
||||
int position = SelectionStart; // before inserttran = this.TextLength;
|
||||
SelectionLength = 0;
|
||||
SelectedRtf = string.Format(@"{{\rtf\field{{\*\fldinst{{HYPERLINK ""www.volian.com #{0}"" }}}}{{\fldrslt{{\cf2\ul {1}}}}}}}", linkUrl, linkValue);
|
||||
this.SelectionStart = this.TextLength;
|
||||
this.SelectionLength = 0;
|
||||
}
|
||||
#endregion
|
||||
#region HeightSupport
|
||||
public event DisplayRTBEvent HeightChanged;
|
||||
private void OnHeightChanged(object sender, EventArgs args)
|
||||
{
|
||||
if (HeightChanged != null) HeightChanged(sender, args);
|
||||
}
|
||||
private void AdjustSizeForContents()
|
||||
{
|
||||
//Console.WriteLine("Size {0} Client {1} New {2}", Size, ClientRectangle, ContentsRectangle);
|
||||
// I want the client size to match the new rectangle.
|
||||
// First I need to determine the offset
|
||||
Size offset = Size - ClientSize;
|
||||
this.Size = ContentsSize + offset + AdjustSize;
|
||||
OnHeightChanged(this, new EventArgs());
|
||||
}
|
||||
public int CalculateHeight()
|
||||
{
|
||||
if (this.CreateParams.ClassName == "RICHEDIT50W")
|
||||
return CalculateHeight50();
|
||||
else
|
||||
return CalculateHeight20();
|
||||
}
|
||||
private int CalculateHeight20()
|
||||
{
|
||||
Application.DoEvents();
|
||||
int yBottom = GetPositionFromCharIndex(TextLength).Y;
|
||||
int yTop = GetPositionFromCharIndex(0).Y;
|
||||
int heightFont = SelectionFont.Height;
|
||||
int borderSize = this.Height - this.ClientSize.Height;
|
||||
int heightNext = (yBottom - yTop) + heightFont + borderSize + 2;// 2 pixels - 1 at the top and 1 at the bottom
|
||||
if (heightNext != Height)
|
||||
{
|
||||
Height = heightNext;
|
||||
|
||||
OnHeightChanged(this, new EventArgs());
|
||||
ScrollPos = new Point(0, 0); // Scroll to make sure that the first line is displayed as the first line
|
||||
}
|
||||
return heightNext;
|
||||
}
|
||||
private int CalculateHeight50()
|
||||
{
|
||||
Application.DoEvents();
|
||||
int heightFont = SelectionFont.Height;
|
||||
int borderSize = this.Height - this.ClientSize.Height;
|
||||
//for (int i = 235; i < TextLength; i++)
|
||||
//{
|
||||
// Console.WriteLine("{0}\t{1}\t{2}", i, GetLineFromCharIndex(i), GetPositionFromCharIndex(i));
|
||||
//}
|
||||
int heightNext = (1 + GetLineFromCharIndex(TextLength)) * heightFont + borderSize + 2;// 2 pixels - 1 at the top and 1 at the bottom
|
||||
return heightNext;
|
||||
}
|
||||
#endregion
|
||||
#region ColorSupport - Not currently used.
|
||||
private void SetBackGroundColor(ItemInfo itemInfo)
|
||||
{
|
||||
string backcolor = null;
|
||||
int type = (int)itemInfo.MyContent.Type;
|
||||
FormatInfo formatinfo = itemInfo.ActiveFormat;
|
||||
if (type == (int)E_FromType.Procedure)
|
||||
backcolor = formatinfo.PlantFormat.FormatData.ProcData.BackColor;
|
||||
else if (type == (int)E_FromType.Section)
|
||||
backcolor = formatinfo.PlantFormat.FormatData.SectData.BackColor;
|
||||
else
|
||||
{
|
||||
int typindx = (int)itemInfo.MyContent.Type - 20000; // what to do for other types rather than steps
|
||||
backcolor = formatinfo.PlantFormat.FormatData.StepDataList[typindx].StepLayoutData.BackColor;
|
||||
}
|
||||
BackColor = Color.FromName(backcolor);
|
||||
}
|
||||
#endregion
|
||||
#region EventSupport
|
||||
#region LinkEvents
|
||||
private LinkClickedEventArgs _LinkClickedEventArgs;
|
||||
public event DisplayRTBLinkEvent LinkChanged; // TODO: ?
|
||||
private void OnLinkChanged(object sender, LinkClickedEventArgs args)
|
||||
{
|
||||
_LinkClickedEventArgs = args;
|
||||
if (LinkChanged != null) LinkChanged(sender, args);
|
||||
}
|
||||
public event DisplayRTBLinkEvent LinkGoTo;
|
||||
private void OnLinkGoTo(object sender, LinkClickedEventArgs args)
|
||||
{
|
||||
_LinkClickedEventArgs = args;
|
||||
if (LinkGoTo != null) LinkGoTo(sender, args);
|
||||
}
|
||||
public event DisplayRTBLinkEvent LinkModifyTran;
|
||||
private void OnLinkModifyTran(object sender, LinkClickedEventArgs args)
|
||||
{
|
||||
_LinkClickedEventArgs = args;
|
||||
if (LinkModifyTran != null) LinkModifyTran(sender, args);
|
||||
}
|
||||
public event DisplayRTBLinkEvent LinkModifyRO;
|
||||
private void OnLinkModifyRO(object sender, LinkClickedEventArgs args)
|
||||
{
|
||||
_LinkClickedEventArgs = args;
|
||||
if (LinkModifyRO != null) LinkModifyRO(sender, args);
|
||||
}
|
||||
private Point _savcurpos;
|
||||
private void DisplayRTB_LinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e)
|
||||
{
|
||||
if (ReadOnly) return;
|
||||
|
||||
_LinkClickedEventArgs = e;
|
||||
_savcurpos = Cursor.Position;
|
||||
SelectLink(e.LinkText);
|
||||
OnLinkChanged(sender, e);
|
||||
//_savcurpos = Cursor.Position;
|
||||
//if (e.LinkText.IndexOf("ReferencedObject") > -1)
|
||||
// this.contextMenuStripROs.Show(System.Windows.Forms.Cursor.Position);
|
||||
//else
|
||||
// this.contextMenuStripTrans.Show(System.Windows.Forms.Cursor.Position);
|
||||
}
|
||||
private void SelectLink(string LinkText)
|
||||
{
|
||||
Point cp = PointToClient(_savcurpos);
|
||||
int index = GetCharIndexFromPosition(cp);
|
||||
//int iMax = index;
|
||||
//int iMin = index;
|
||||
//Select(index, 0);
|
||||
|
||||
//while (iMin > 0 && SelectionProtected)
|
||||
// Select(--iMin, 0);
|
||||
//Select(iMin + 1, 0);
|
||||
//SelectLink();
|
||||
////SelectionProtected = false; // unprotect link only if deleted
|
||||
//MyLinkText = SelectedText;
|
||||
//int index = SelectionStart;
|
||||
int iMin = index;
|
||||
Select(index, 0);
|
||||
while (iMin > 0 && SelectionProtected)
|
||||
Select(--iMin, 0);
|
||||
Select(iMin + 1, 0);
|
||||
SelectLink();
|
||||
}
|
||||
#endregion
|
||||
#region TextOrContents
|
||||
void DisplayRTB_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_IsDirty = true;
|
||||
}
|
||||
void DisplayRTB_ContentsResized(object sender, ContentsResizedEventArgs e)
|
||||
{
|
||||
ContentsRectangle = e.NewRectangle;
|
||||
}
|
||||
#endregion
|
||||
#region KeyboardHandling
|
||||
private bool IsControlChar = false;
|
||||
void DisplayRTB_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Modifiers == Keys.Control)
|
||||
{
|
||||
IsControlChar = true;
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.V:
|
||||
string buff = Clipboard.GetText(TextDataFormat.UnicodeText);
|
||||
|
||||
// check if insertable?
|
||||
Console.WriteLine(String.Format("in switch, keydata = {0}, keyvalue = {1}, buff = {2}", e.KeyData, e.KeyValue, buff));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void DisplayRTB_KeyUp(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
|
||||
{
|
||||
e.Handled = HandleLUDArrows();
|
||||
}
|
||||
else if (e.KeyCode == Keys.Right)
|
||||
{
|
||||
e.Handled = HandleRightArrow();
|
||||
}
|
||||
}
|
||||
private void SelectLink()
|
||||
{
|
||||
int index = SelectionStart;
|
||||
int iMax = index;
|
||||
Select(index, 0);
|
||||
while (iMax < TextLength && SelectionProtected)
|
||||
Select(++iMax, 0);
|
||||
Select(index - 1, SelectionStart + 1 - index);
|
||||
MyLinkText = SelectedText;
|
||||
}
|
||||
private bool HandleRightArrow()
|
||||
{
|
||||
if (!SelectionProtected)
|
||||
{
|
||||
MyLinkText = null;
|
||||
return false;
|
||||
}
|
||||
SelectLink();
|
||||
return true;
|
||||
}
|
||||
private bool HandleLUDArrows()
|
||||
{
|
||||
if (!SelectionProtected)
|
||||
{
|
||||
MyLinkText = null;
|
||||
return false;
|
||||
}
|
||||
int index = this.SelectionStart;
|
||||
int iMin = index;
|
||||
Select(index, 0);
|
||||
while (iMin > 0 && SelectionProtected)
|
||||
Select(--iMin, 0);
|
||||
Select(iMin + 1, 0);
|
||||
SelectLink();
|
||||
return true;
|
||||
}
|
||||
private void DisplayRTB_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
|
||||
{
|
||||
if (!ReadOnly)
|
||||
{
|
||||
// add the character with its font depending on the char....
|
||||
if (!IsControlChar)
|
||||
{
|
||||
if (e.KeyChar == '\b') return; // return on backspace otherwise, get a block char
|
||||
if (e.KeyChar == '-')
|
||||
AddSymbol(@"\u8209?");
|
||||
else
|
||||
AddRtf(e.KeyChar.ToString());
|
||||
e.Handled = true; // flag that it's been handled, otherwise, will get 2 chars.
|
||||
}
|
||||
IsControlChar = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
#region Font with Styles
|
||||
private void ToggleFontStyle(FontStyle style, bool att_on)
|
||||
{
|
||||
int start = SelectionStart;
|
||||
int len = SelectionLength;
|
||||
System.Drawing.Font currentFont;
|
||||
FontStyle fs;
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
Select(start + i, 1);
|
||||
currentFont = SelectionFont;
|
||||
fs = currentFont.Style;
|
||||
//add or remove style
|
||||
if (!att_on)fs = fs | style;
|
||||
else fs = fs & ~style;
|
||||
|
||||
SelectionFont = new Font(
|
||||
currentFont.FontFamily,
|
||||
currentFont.Size,
|
||||
fs
|
||||
);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a Font with:
|
||||
/// 1) The font applying to the entire selection, if none is the default font.
|
||||
/// 2) The font size applying to the entire selection, if none is the size of the default font.
|
||||
/// 3) A style containing the attributes that are common to the entire selection, default regular.
|
||||
/// </summary>
|
||||
///
|
||||
public Font GetFontDetails()
|
||||
{
|
||||
//This method should handle cases that occur when multiple fonts/styles are selected
|
||||
|
||||
int start = SelectionStart;
|
||||
int len = SelectionLength;
|
||||
int TempStart = 0;
|
||||
|
||||
if (len <= 1)
|
||||
{
|
||||
// Return the selection or default font
|
||||
if (SelectionFont != null)
|
||||
return SelectionFont;
|
||||
else
|
||||
return Font; // should be default from format.
|
||||
}
|
||||
|
||||
// Step through the selected text one char at a time
|
||||
// after setting defaults from first char
|
||||
_rtbTemp.Rtf = SelectedRtf;
|
||||
|
||||
//Turn everything on so we can turn it off one by one
|
||||
FontStyle replystyle =
|
||||
FontStyle.Bold | FontStyle.Italic | FontStyle.Underline;
|
||||
|
||||
// Set reply font, size and style to that of first char in selection.
|
||||
_rtbTemp.Select(TempStart, 1);
|
||||
string replyfont = _rtbTemp.SelectionFont.Name;
|
||||
float replyfontsize = _rtbTemp.SelectionFont.Size;
|
||||
replystyle = replystyle & _rtbTemp.SelectionFont.Style;
|
||||
|
||||
// Search the rest of the selection
|
||||
for (int i = 1; i < len; ++i)
|
||||
{
|
||||
_rtbTemp.Select(TempStart + i, 1);
|
||||
|
||||
// Check reply for different style
|
||||
replystyle = replystyle & _rtbTemp.SelectionFont.Style;
|
||||
|
||||
// Check font
|
||||
if (replyfont != _rtbTemp.SelectionFont.FontFamily.Name)
|
||||
replyfont = "";
|
||||
|
||||
// Check font size
|
||||
if (replyfontsize != _rtbTemp.SelectionFont.Size)
|
||||
replyfontsize = (float)0.0;
|
||||
}
|
||||
|
||||
// Now set font and size if more than one font or font size was selected
|
||||
if (replyfont == "")
|
||||
replyfont = _rtbTemp.Font.FontFamily.Name;
|
||||
|
||||
if (replyfontsize == 0.0)
|
||||
replyfontsize = _rtbTemp.Font.Size;
|
||||
|
||||
// generate reply font
|
||||
Font reply
|
||||
= new Font(replyfont, replyfontsize, replystyle);
|
||||
|
||||
return reply;
|
||||
}
|
||||
#endregion
|
||||
#region Context Menu Strip
|
||||
private void contextMenuStrip_Opening(object sender, CancelEventArgs e)
|
||||
{
|
||||
Font cfont = GetFontDetails();
|
||||
menu_Bold.Checked = cfont.Bold;
|
||||
menu_Underline.Checked = cfont.Underline;
|
||||
menu_Italics.Checked = cfont.Italic;
|
||||
menu_Superscript.Checked = RTBAPI.IsSuperScript(this);
|
||||
menu_Subscript.Checked = RTBAPI.IsSubScript(this);
|
||||
menu_Bold.Enabled = !ReadOnly;
|
||||
menu_Underline.Enabled = !ReadOnly;
|
||||
menu_Italics.Enabled = !ReadOnly;
|
||||
menu_Superscript.Enabled = !ReadOnly;
|
||||
menu_Subscript.Enabled = !ReadOnly;
|
||||
menu_Undo.Enabled = !ReadOnly;
|
||||
menu_Redo.Enabled = !ReadOnly;
|
||||
menu_lowercase.Enabled = !ReadOnly;
|
||||
menu_UPPERCASE.Enabled = !ReadOnly;
|
||||
menu_TitleCase.Enabled = !ReadOnly;
|
||||
menu_InsRO.Enabled = !ReadOnly;
|
||||
menu_InsTran.Enabled = !ReadOnly;
|
||||
menu_InsSym.Enabled = !ReadOnly;
|
||||
menu_ToggleView.Enabled = true;
|
||||
}
|
||||
private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Font cfont = GetFontDetails();
|
||||
|
||||
//if (e.ClickedItem.ToString() == "Paste") DoPaste();
|
||||
if (e.ClickedItem.ToString() == "Underline") ToggleFontStyle(FontStyle.Underline, cfont.Underline);
|
||||
else if (e.ClickedItem.ToString() == "Bold") ToggleFontStyle(FontStyle.Bold, cfont.Bold);
|
||||
else if (e.ClickedItem.ToString() == "Italics") ToggleFontStyle(FontStyle.Italic, cfont.Italic);
|
||||
else if (e.ClickedItem.ToString() == "Subscript")
|
||||
RTBAPI.ToggleSubscript(!RTBAPI.IsSubScript(this), this, this.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
else if (e.ClickedItem.ToString() == "Superscript")
|
||||
RTBAPI.ToggleSuperscript(!RTBAPI.IsSuperScript(this), this, this.SelectionLength == 0 ? RTBAPI.RTBSelection.SCF_DEFAULT : RTBAPI.RTBSelection.SCF_SELECTION);
|
||||
else if (e.ClickedItem.ToString() == "Undo")
|
||||
this.Undo();
|
||||
else if (e.ClickedItem.ToString() == "Redo")
|
||||
this.Redo();
|
||||
else if (e.ClickedItem.ToString() == "lowercase")
|
||||
SetSelectedCase('l');
|
||||
else if (e.ClickedItem.ToString() == "UPPERCASE")
|
||||
SetSelectedCase('U');
|
||||
else if (e.ClickedItem.ToString() == "TitleCase")
|
||||
SetSelectedCase('T');
|
||||
else if (e.ClickedItem.ToString() == "Insert RO")
|
||||
MessageBox.Show("Not supported from context menu yet");
|
||||
else if (e.ClickedItem.ToString() == "Insert Transition")
|
||||
MessageBox.Show("Not supported from context menu yet");
|
||||
else if (e.ClickedItem.ToString() == "Insert Symbol")
|
||||
MessageBox.Show("Not supported from context menu yet");
|
||||
else if (e.ClickedItem.ToString() == "Toggle View/Edit")
|
||||
ToggleViewEdit();
|
||||
//else if (e.ClickedItem.ToString() == "Find text") findit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
public void SetSelectedCase(char type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 'l':
|
||||
SelectedText = SelectedText.ToLower();
|
||||
break;
|
||||
case 'U':
|
||||
SelectedText = SelectedText.ToUpper();
|
||||
break;
|
||||
case 'T':
|
||||
SelectedText = SelectedText.Substring(0,1).ToUpper() + SelectedText.Substring(1, SelectedText.Length - 1).ToLower();
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void DeleteTransition()
|
||||
{
|
||||
SelectLink(_MyLinkText);
|
||||
SelectedText = "";
|
||||
}
|
||||
private void contextMenuStripTrans_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem.ToString() == "Delete Transition") DeleteTransition();
|
||||
else if (e.ClickedItem.ToString() == "Modify Transition")
|
||||
{
|
||||
OnLinkModifyTran(sender, _LinkClickedEventArgs);
|
||||
}
|
||||
else if (e.ClickedItem.ToString() == "Go To")
|
||||
{
|
||||
Console.WriteLine("DisplayRTB:contextMenu:Go TO");
|
||||
OnLinkGoTo(sender, _LinkClickedEventArgs);
|
||||
}
|
||||
|
||||
}
|
||||
private void contextMenuStripTrans_Opening(object sender, CancelEventArgs e)
|
||||
{
|
||||
menu_GoToTrans.Enabled = true;
|
||||
menu_DeleteTrans.Enabled = !ReadOnly;
|
||||
menu_ModifyTrans.Enabled = !ReadOnly;
|
||||
}
|
||||
private void contextMenuStripROs_Opening(object sender, CancelEventArgs e)
|
||||
{
|
||||
menu_DeleteRO.Enabled = !ReadOnly;
|
||||
menu_ModifyRO.Enabled = !ReadOnly;
|
||||
}
|
||||
private void DeleteRefObj()
|
||||
{
|
||||
SelectLink(_MyLinkText);
|
||||
SelectedText = "";
|
||||
}
|
||||
private void contextMenuStripROs_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem.ToString() == "Delete RO") DeleteRefObj();
|
||||
else if (e.ClickedItem.ToString() == "Modify RO") OnLinkModifyRO(sender, _LinkClickedEventArgs);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user