Volian.Base.Library & Baseline
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ComponentModel;
|
||||
using Volian.Base.Library;
|
||||
|
||||
namespace Volian.Base.Library
|
||||
{
|
||||
@@ -451,11 +448,6 @@ namespace Volian.Base.Library
|
||||
}
|
||||
#endregion
|
||||
#region Structures
|
||||
//struct CharRange
|
||||
//{
|
||||
// public int cpMin;
|
||||
// public int cpMax;
|
||||
//}
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
|
||||
public struct CharFormat2
|
||||
{
|
||||
@@ -483,17 +475,11 @@ namespace Volian.Base.Library
|
||||
}
|
||||
public class CharFormatTwo
|
||||
{
|
||||
public CharFormatTwo(CharFormat2 cf)
|
||||
{
|
||||
_CharFormat2 = cf;
|
||||
}
|
||||
private CharFormat2 _CharFormat2;
|
||||
[Browsable(false)]
|
||||
public CharFormat2 CharFormat2
|
||||
{
|
||||
get { return _CharFormat2; }
|
||||
}
|
||||
[Browsable(false)]
|
||||
public CharFormatTwo(CharFormat2 cf) => _CharFormat2 = cf;
|
||||
private CharFormat2 _CharFormat2;
|
||||
[Browsable(false)]
|
||||
public CharFormat2 CharFormat2 => _CharFormat2;
|
||||
[Browsable(false)]
|
||||
public int cbSize
|
||||
{
|
||||
get { return _CharFormat2.cbSize; }
|
||||
@@ -521,15 +507,9 @@ namespace Volian.Base.Library
|
||||
get { return _CharFormat2.yOffset; }
|
||||
set { _CharFormat2.yOffset = value; }
|
||||
}
|
||||
private Color Int2Color(int color)
|
||||
{
|
||||
return Color.FromArgb(color % 256, (color / 256) % 256, color / (256 * 256));
|
||||
}
|
||||
private int Color2Int(Color color)
|
||||
{
|
||||
return color.R + (color.G * 256) + (color.B * 256 * 256);
|
||||
}
|
||||
public Color crTextColor
|
||||
private Color Int2Color(int color) => Color.FromArgb(color % 256, (color / 256) % 256, color / (256 * 256));
|
||||
private int Color2Int(Color color) => color.R + (color.G * 256) + (color.B * 256 * 256);
|
||||
public Color crTextColor
|
||||
{
|
||||
get { return Int2Color(_CharFormat2.crTextColor); }
|
||||
set { _CharFormat2.crTextColor = Color2Int(value); }
|
||||
@@ -637,15 +617,9 @@ namespace Volian.Base.Library
|
||||
public class ParaFormatTwo
|
||||
{
|
||||
private ParaFormat2 _ParaFormat2;
|
||||
public ParaFormatTwo(ParaFormat2 pf)
|
||||
{
|
||||
_ParaFormat2 = pf;
|
||||
}
|
||||
public ParaFormat2 ParaFormat2
|
||||
{
|
||||
get { return _ParaFormat2; }
|
||||
}
|
||||
public int cbSize
|
||||
public ParaFormatTwo(ParaFormat2 pf) => _ParaFormat2 = pf;
|
||||
public ParaFormat2 ParaFormat2 => _ParaFormat2;
|
||||
public int cbSize
|
||||
{
|
||||
get { return _ParaFormat2.cbSize; }
|
||||
set { _ParaFormat2.cbSize = value; }
|
||||
@@ -767,19 +741,11 @@ namespace Volian.Base.Library
|
||||
set { _ParaFormat2.wBorders = value; }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Static Methods
|
||||
public static bool HasVertScroll(Control ctl)
|
||||
{
|
||||
int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE);
|
||||
return (dwstyle & WS_VSCROLL) != 0;
|
||||
}
|
||||
public static bool HasHorzScroll(Control ctl)
|
||||
{
|
||||
int dwstyle = GetWindowLong(ctl.Handle, GWL_STYLE);
|
||||
return (dwstyle & WS_HSCROLL) != 0;
|
||||
}
|
||||
public static void SetScrollLocation(RichTextBox richTextBox, Point point)
|
||||
#endregion
|
||||
#region Static Methods
|
||||
public static bool HasVertScroll(Control ctl) => (GetWindowLong(ctl.Handle, GWL_STYLE) & WS_VSCROLL) != 0;
|
||||
public static bool HasHorzScroll(Control ctl) => (GetWindowLong(ctl.Handle, GWL_STYLE) & WS_HSCROLL) != 0;
|
||||
public static void SetScrollLocation(RichTextBox richTextBox, Point point)
|
||||
{
|
||||
if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETSCROLLPOS, 0, ref point) == 0)
|
||||
throw new Win32Exception();
|
||||
@@ -815,7 +781,6 @@ namespace Volian.Base.Library
|
||||
ParaFormat2 pf2 = pft.ParaFormat2;
|
||||
if (SendMessage(new HandleRef(richTextBox, richTextBox.Handle), Messages.EM_SETPARAFORMAT, 0, ref pf2) == 0)
|
||||
{
|
||||
//if(Marshal.GetLastWin32Error()!=0)
|
||||
throw new Win32Exception();
|
||||
}
|
||||
}
|
||||
@@ -849,15 +814,6 @@ namespace Volian.Base.Library
|
||||
}
|
||||
|
||||
}
|
||||
public static void SetHighlightColor(RichTextBox richTextBox, RTBSelection selection, Color color)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, selection);
|
||||
cft.crBackColor = color;
|
||||
cft.dwEffects = 0;
|
||||
cft.dwMask = 0;
|
||||
cft.dwMask |= CharFormatMasks.CFM_BACKCOLOR;
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
public static void SetSpaceBefore(RichTextBox richTextBox, int spaceBefore)
|
||||
{
|
||||
ParaFormatTwo pft = GetParaFormat(richTextBox);
|
||||
@@ -875,236 +831,6 @@ namespace Volian.Base.Library
|
||||
pft.dySpaceBefore = spaceBefore * 1440 / dpi;
|
||||
SetParaFormat(richTextBox, pft);
|
||||
}
|
||||
//developed for equation editor interface work, but ended up not needing it. Kept it in
|
||||
// case it is needed in the future.
|
||||
//public static void SetSpaceAfter(RichTextBox richTextBox, int spaceAfter)
|
||||
//{
|
||||
// ParaFormatTwo pft = GetParaFormat(richTextBox);
|
||||
// pft.dwMask = 0;
|
||||
// pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER;
|
||||
// // get the monitor's resolution in DPI and use it to set the linespacing value for
|
||||
// // the richtextbox. Note that without this, the Arial Unicode font made the appearance of
|
||||
// // almost double linespacing. Using PFS_Exact makes it appear as regular single spacing.
|
||||
// Graphics g = richTextBox.CreateGraphics();
|
||||
// int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2);
|
||||
// g.Dispose();
|
||||
// // dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one
|
||||
// //line to the next, in twips - thus the 1440.
|
||||
|
||||
// pft.dySpaceAfter = spaceAfter * 1440 / dpi;
|
||||
// SetParaFormat(richTextBox, pft);
|
||||
//}
|
||||
public static void SetLineSpacing(RichTextBox richTextBox, ParaSpacing type)
|
||||
{
|
||||
ParaFormatTwo pft = GetParaFormat(richTextBox);
|
||||
pft.bLineSpacingRule = type;
|
||||
pft.dwMask = 0;
|
||||
pft.dwMask |= ParaFormatMasks.PFM_LINESPACING;
|
||||
pft.dwMask |= ParaFormatMasks.PFM_SPACEAFTER;
|
||||
|
||||
// get the monitor's resolution in DPI and use it to set the linespacing value for
|
||||
// the richtextbox. Note that without this, the Arial Unicode font made the appearance of
|
||||
// almost double linespacing. Using PFS_Exact makes it appear as regular single spacing.
|
||||
Graphics g = richTextBox.CreateGraphics();
|
||||
int dpi = Convert.ToInt32((g.DpiX + g.DpiY) / 2);
|
||||
g.Dispose();
|
||||
// dyLineSpacing is Spacing between lines. the PFS_EXACT sets line spacing as the spacing from one
|
||||
//line to the next, in twips - thus the 1440.
|
||||
|
||||
pft.dyLineSpacing = Convert.ToInt32(.5 + richTextBox.Font.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 (richTextBox.SelectionCharOffset == -2) fs |= E_FontStyle.FS_SUBSCRIPT;
|
||||
if (richTextBox.SelectionCharOffset == 2) fs |= E_FontStyle.FS_SUPERSCRIPT;
|
||||
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)
|
||||
{
|
||||
richTextBox.SelectionCharOffset = -2;
|
||||
}
|
||||
if ((fs & E_FontStyle.FS_SUPERSCRIPT) == E_FontStyle.FS_SUPERSCRIPT)
|
||||
{
|
||||
richTextBox.SelectionCharOffset = 2;
|
||||
}
|
||||
SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft);
|
||||
}
|
||||
public static bool IsSuperScript(RichTextBox richTextBox)
|
||||
{
|
||||
return (richTextBox.SelectionCharOffset>0);
|
||||
}
|
||||
public static bool IsSubScript(RichTextBox richTextBox)
|
||||
{
|
||||
return (richTextBox.SelectionCharOffset < 0);
|
||||
}
|
||||
public static void ToggleSubscript(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
if (bSet)
|
||||
richTextBox.SelectionCharOffset = -2;
|
||||
else
|
||||
richTextBox.SelectionCharOffset = 0;
|
||||
}
|
||||
public static void ToggleSuperscript(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
if (bSet)
|
||||
richTextBox.SelectionCharOffset = 2;
|
||||
else
|
||||
richTextBox.SelectionCharOffset = 0;
|
||||
}
|
||||
public static bool IsBold(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_BOLD) == CharFormatMasks.CFM_BOLD) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_BOLD) == CharFormatEffects.CFE_BOLD));
|
||||
}
|
||||
public static void ToggleBold(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, selection);
|
||||
if (bSet)
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_BOLD;
|
||||
cft.dwMask = CharFormatMasks.CFM_BOLD;
|
||||
}
|
||||
else
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_NONE;
|
||||
cft.dwMask = CharFormatMasks.CFM_BOLD;
|
||||
}
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
public static bool IsUnderline(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_UNDERLINE) == CharFormatMasks.CFM_UNDERLINE) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_UNDERLINE) == CharFormatEffects.CFE_UNDERLINE));
|
||||
}
|
||||
public static void ToggleUnderline(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, selection);
|
||||
if (bSet)
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_UNDERLINE;
|
||||
cft.dwMask = CharFormatMasks.CFM_UNDERLINE;
|
||||
}
|
||||
else
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_NONE;
|
||||
cft.dwMask = CharFormatMasks.CFM_UNDERLINE;
|
||||
}
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
public static bool IsItalic(RichTextBox richTextBox)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, RTBSelection.SCF_SELECTION);
|
||||
return (((cft.dwMask & CharFormatMasks.CFM_ITALIC) == CharFormatMasks.CFM_ITALIC) &&
|
||||
((cft.dwEffects & CharFormatEffects.CFE_ITALIC) == CharFormatEffects.CFE_ITALIC));
|
||||
}
|
||||
public static void ToggleItalic(bool bSet, RichTextBox richTextBox, RTBSelection selection)
|
||||
{
|
||||
CharFormatTwo cft = GetCharFormat(richTextBox, selection);
|
||||
if (bSet)
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_ITALIC;
|
||||
cft.dwMask = CharFormatMasks.CFM_ITALIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
cft.dwEffects = CharFormatEffects.CFE_NONE;
|
||||
cft.dwMask = CharFormatMasks.CFM_ITALIC;
|
||||
}
|
||||
SetCharFormat(richTextBox, selection, cft);
|
||||
}
|
||||
//public static bool IsLink(RichTextBox richTextBox)
|
||||
//{
|
||||
// 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;
|
||||
// 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_PROTECTED;
|
||||
// cft.dwEffects = 0;
|
||||
// // 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;
|
||||
//}
|
||||
//public static void Protect(RichTextBox richTextBox) //, string type, string text, string link)
|
||||
//{
|
||||
// CharFormatTwo cft = GetCharFormat(richTextBox, RTBAPI.RTBSelection.SCF_SELECTION); ;
|
||||
// cft.dwMask = CharFormatMasks.CFM_PROTECTED;
|
||||
// cft.dwEffects = CharFormatEffects.CFE_PROTECTED;
|
||||
// SetCharFormat(richTextBox, RTBSelection.SCF_SELECTION, cft);
|
||||
//}
|
||||
//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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user