This commit is contained in:
parent
d126729cae
commit
8cdab33846
@ -432,6 +432,16 @@ namespace Volian.Controls.Library
|
||||
PFS_EXACT = 4,
|
||||
PFS_EXACT20 = 5
|
||||
}
|
||||
[Flags]
|
||||
public enum E_FontStyle : byte
|
||||
{
|
||||
FS_NONE = 0,
|
||||
FS_BOLD = 0x01,
|
||||
FS_UNDERLINE = 0x02,
|
||||
FS_ITALIC = 0x04,
|
||||
FS_SUPERSCRIPT = 0x08,
|
||||
FS_SUBSCRIPT = 0x10
|
||||
}
|
||||
#endregion
|
||||
#region Structures
|
||||
//struct CharRange
|
||||
@ -794,11 +804,6 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
public static CharFormatTwo GetCharFormat(RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
/*
|
||||
* You can still call SendMessage, passing the EM_GETCHARFORMAT message.
|
||||
You just need to check the dwMask field to see which attributes are
|
||||
consistent throughout the selection.
|
||||
*/
|
||||
CharFormat2 cf = new CharFormat2();
|
||||
cf.cbSize = Marshal.SizeOf(cf);
|
||||
if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_GETCHARFORMAT, selection, ref cf) == 0)
|
||||
@ -856,6 +861,52 @@ consistent throughout the selection.
|
||||
pft.dyLineSpacing = Convert.ToInt32(.5 + richTextBox.SelectionFont.GetHeight(dpi)) * 1440 / dpi;
|
||||
SetParaFormat(richTextBox, pft);
|
||||
}
|
||||
public static E_FontStyle GetFontStyle(RichTextBox richTextBox)
|
||||
{
|
||||
E_FontStyle fs = E_FontStyle.FS_NONE;
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
if (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD)) fs |= E_FontStyle.FS_BOLD;
|
||||
if (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE)) fs |= E_FontStyle.FS_UNDERLINE;
|
||||
if (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC)) fs |= E_FontStyle.FS_ITALIC;
|
||||
if (((cft.dwMask & CharFormatMasks.CFM_SUPERSCRIPT) == CharFormatMasks.CFM_SUPERSCRIPT) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_SUPERSCRIPT) == CharFormatEffects.CFE_SUPERSCRIPT)) fs |= E_FontStyle.FS_SUPERSCRIPT;
|
||||
if (((cft.dwMask & CharFormatMasks.CFM_SUBSCRIPT) == CharFormatMasks.CFM_SUBSCRIPT) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_SUBSCRIPT) == CharFormatEffects.CFE_SUBSCRIPT)) fs |= E_FontStyle.FS_SUBSCRIPT;
|
||||
return fs;
|
||||
}
|
||||
public static void SetFontStyle(RichTextBox richTextBox, E_FontStyle fs)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
if ((fs & E_FontStyle.FS_BOLD) == E_FontStyle.FS_BOLD)
|
||||
{
|
||||
cft.dwEffects |= CharFormatEffects.CFE_BOLD;
|
||||
cft.dwMask |= CharFormatMasks.CFM_BOLD;
|
||||
}
|
||||
if ((fs & E_FontStyle.FS_UNDERLINE) == E_FontStyle.FS_UNDERLINE)
|
||||
{
|
||||
cft.dwEffects |= CharFormatEffects.CFE_UNDERLINE;
|
||||
cft.dwMask |= CharFormatMasks.CFM_UNDERLINE;
|
||||
}
|
||||
if ((fs & E_FontStyle.FS_ITALIC) == E_FontStyle.FS_ITALIC)
|
||||
{
|
||||
cft.dwEffects |= CharFormatEffects.CFE_ITALIC;
|
||||
cft.dwMask |= CharFormatMasks.CFM_ITALIC;
|
||||
}
|
||||
if ((fs & E_FontStyle.FS_SUBSCRIPT) == E_FontStyle.FS_SUBSCRIPT)
|
||||
{
|
||||
cft.dwEffects |= CharFormatEffects.CFE_SUBSCRIPT;
|
||||
cft.dwMask |= CharFormatMasks.CFM_SUBSCRIPT;
|
||||
}
|
||||
if ((fs & E_FontStyle.FS_SUPERSCRIPT) == E_FontStyle.FS_SUPERSCRIPT)
|
||||
{
|
||||
cft.dwEffects |= RTBAPI.CharFormatEffects.CFE_SUPERSCRIPT;
|
||||
cft.dwMask |= RTBAPI.CharFormatMasks.CFM_SUPERSCRIPT;
|
||||
}
|
||||
SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft);
|
||||
}
|
||||
public static bool IsSuperScript(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
@ -953,7 +1004,7 @@ consistent throughout the selection.
|
||||
}
|
||||
else
|
||||
{
|
||||
cft.dwEffects &= ~RTBAPI.CharFormatEffects.CFE_UNDERLINE;
|
||||
cft.dwEffects &= ~RTBAPI.CharFormatEffects.CFE_ITALIC;
|
||||
}
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
@ -962,6 +1013,20 @@ consistent throughout the selection.
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return ((cft.dwEffects & CharFormatEffects.CFE_PROTECTED) == CharFormatEffects.CFE_PROTECTED);
|
||||
}
|
||||
public static void ToggleLink(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, selection);
|
||||
if (bSet)
|
||||
{
|
||||
cft.dwEffects |= CharFormatEffects.CFE_LINK;
|
||||
cft.dwMask |= CharFormatMasks.CFM_LINK;
|
||||
}
|
||||
else
|
||||
{
|
||||
cft.dwEffects &= ~RTBAPI.CharFormatEffects.CFE_LINK;
|
||||
}
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
public static void UnProtect(RichTextBox richTextBox) //, string type, string text, string link)
|
||||
{
|
||||
//richTextBox.DetectUrls = false;
|
||||
@ -981,25 +1046,32 @@ consistent throughout the selection.
|
||||
//richTextBox.SelectionStart = richTextBox.TextLength;
|
||||
//richTextBox.SelectionLength = 0;
|
||||
}
|
||||
public static void SetLink(RichTextBox richTextBox, string type, string text, string link)
|
||||
public static void Protect(RichTextBox richTextBox) //, string type, string text, string link)
|
||||
{
|
||||
richTextBox.DetectUrls = false;
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ;
|
||||
int position = richTextBox.SelectionStart = richTextBox.TextLength;
|
||||
richTextBox.SelectionLength = 0;
|
||||
//richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}";
|
||||
richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}";
|
||||
richTextBox.Select(position, type.Length + text.Length + link.Length + 1);
|
||||
cft.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED;
|
||||
cft.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED;
|
||||
// The lines below can be used to allow link text to be edited
|
||||
//charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK;
|
||||
//charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK;
|
||||
cft.dwMask = CharFormatMasks.CFM_PROTECTED;
|
||||
cft.dwEffects = CharFormatEffects.CFE_PROTECTED;
|
||||
SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft);
|
||||
//rtbRTF.SetSelectionLink(true);
|
||||
richTextBox.SelectionStart = richTextBox.TextLength;
|
||||
richTextBox.SelectionLength = 0;
|
||||
}
|
||||
//public static void SetLink(RichTextBox richTextBox, string type, string text, string link)
|
||||
//{
|
||||
// richTextBox.DetectUrls = false;
|
||||
// CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ;
|
||||
// int position = richTextBox.SelectionStart = richTextBox.TextLength;
|
||||
// richTextBox.SelectionLength = 0;
|
||||
// //richTextBox.SelectedRtf = @"{\rtf1\ansi " + text + @"\v #" + link + @"\v0}";
|
||||
// richTextBox.SelectedRtf = "{" + string.Format(@"\rtf1\ansi\protect\v {0}\v0 {1}\v #{2}", type, text, link) + "}";
|
||||
// richTextBox.Select(position, type.Length + text.Length + link.Length + 1);
|
||||
// cft.dwMask = RTBAPI.CharFormatMasks.CFM_LINK | RTBAPI.CharFormatMasks.CFM_PROTECTED;
|
||||
// cft.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK | RTBAPI.CharFormatEffects.CFE_PROTECTED;
|
||||
// // The lines below can be used to allow link text to be edited
|
||||
// //charFormat.dwMask = RTBAPI.CharFormatMasks.CFM_LINK;
|
||||
// //charFormat.dwEffects = RTBAPI.CharFormatEffects.CFE_LINK;
|
||||
// SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft);
|
||||
// //rtbRTF.SetSelectionLink(true);
|
||||
// richTextBox.SelectionStart = richTextBox.TextLength;
|
||||
// richTextBox.SelectionLength = 0;
|
||||
//}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user