Spell checker fix

This commit is contained in:
John Jenko 2011-06-07 19:11:46 +00:00
parent 45a5ea5263
commit f66289aacf

View File

@ -12,6 +12,7 @@ using System.IO;
using Volian.Controls.Library; using Volian.Controls.Library;
using VEPROMS.CSLA.Library; using VEPROMS.CSLA.Library;
using C1.Win.C1FlexGrid; using C1.Win.C1FlexGrid;
using C1.Win.C1SpellChecker;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml.Serialization; using System.Xml.Serialization;
@ -22,6 +23,14 @@ namespace Volian.Controls.Library
public delegate string VlnFlexGridPasteEvent(object sender, VlnFlexGridPasteEventArgs args); public delegate string VlnFlexGridPasteEvent(object sender, VlnFlexGridPasteEventArgs args);
public partial class VlnFlexGrid : C1.Win.C1FlexGrid.C1FlexGrid public partial class VlnFlexGrid : C1.Win.C1FlexGrid.C1FlexGrid
{ {
private C1SpellChecker _SpellChecker;
public C1SpellChecker SpellChecker
{
get { return _SpellChecker; }
set { _SpellChecker = value; }
}
public static GridCopyInfo MyCopyInfo = new GridCopyInfo(); public static GridCopyInfo MyCopyInfo = new GridCopyInfo();
private Color _DefaultCellBackgroundcolor; private Color _DefaultCellBackgroundcolor;
@ -633,7 +642,8 @@ namespace Volian.Controls.Library
_tableCellEditor = new TableCellEditor(this); _tableCellEditor = new TableCellEditor(this);
_tableCellEditor.HeightChanged += new StepRTBEvent(_tableCellEditor_HeightChanged); _tableCellEditor.HeightChanged += new StepRTBEvent(_tableCellEditor_HeightChanged);
_clpbrdCpyPste = new TableClipBoardFuncts(); _clpbrdCpyPste = new TableClipBoardFuncts();
_SpellChecker = _tableCellEditor.SpellCheckerInstance;
this.AfterResizeRow += new C1.Win.C1FlexGrid.RowColEventHandler(this.Grid_AfterResize); this.AfterResizeRow += new C1.Win.C1FlexGrid.RowColEventHandler(this.Grid_AfterResize);
this.StartEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._StartEdit); this.StartEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._StartEdit);
this.AfterEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._AfterEdit); this.AfterEdit += new C1.Win.C1FlexGrid.RowColEventHandler(this._AfterEdit);
@ -793,89 +803,124 @@ namespace Volian.Controls.Library
// //Console.WriteLine("LeaveEdit Style = {0}", this.GetCellRange(e.Row, e.Col).Style.Name); // //Console.WriteLine("LeaveEdit Style = {0}", this.GetCellRange(e.Row, e.Col).Style.Name);
// this.GetCellRange(e.Row, e.Col).Style.ForeColor = Color.Black; // this.GetCellRange(e.Row, e.Col).Style.ForeColor = Color.Black;
//} //}
private void Grid_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e) private void Grid_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{ {
using (RTF _rtf = new RTF()) using (RTF _rtf = new RTF())
{ {
// use nearest solid color // use nearest solid color
// (the RTF control doesn't dither, and doesn't support transparent backgrounds) // (the RTF control doesn't dither, and doesn't support transparent backgrounds)
Color solid = e.Graphics.GetNearestColor(e.Style.BackColor); Color solid = e.Graphics.GetNearestColor(e.Style.BackColor);
DPI = e.Graphics.DpiX; DPI = e.Graphics.DpiX;
if (e.Style.BackColor != solid) if (e.Style.BackColor != solid)
e.Style.BackColor = solid; e.Style.BackColor = solid;
// check whether the cell contains RTF // check whether the cell contains RTF
string rtfText = this.GetDataDisplay(e.Row, e.Col).Replace(@"\~", @"\u160?"); string rtfText = this.GetDataDisplay(e.Row, e.Col).Replace(@"\~", @"\u160?");
GridItem gi = Parent as GridItem; GridItem gi = Parent as GridItem;
if (gi != null) if (gi != null)
{ {
DisplayText dt = new DisplayText(gi.MyItemInfo, rtfText, true); DisplayText dt = new DisplayText(gi.MyItemInfo, rtfText, true);
rtfText = dt.StartText; rtfText = dt.StartText;
} }
// it does, so draw background // it does, so draw background
e.DrawCell(DrawCellFlags.Background); e.DrawCell(DrawCellFlags.Background);
if (rtfText.StartsWith(@"{\rtf")) // Please add a comment if this value needs to be changed
{ _rtf.Rtf = rtfText;
if (rtfText.StartsWith(@"{\rtf"))
{
// draw the RTF text
if (e.Bounds.Width > 0 && e.Bounds.Height > 0)
{
_rtf.Width = e.Bounds.Width - 1; // This has also been -3 which matchs the rener command
CellRange cr = GetMergedRange(e.Row, e.Col);
cr.UserData = _rtf.Height;
int hAdjust = 0;
int hDiff = e.Bounds.Height - _rtf.Height;
if (hDiff < 0)
{
Rows[e.Row].Height = _rtf.Height + 4;
AdjustGridControlSize();
hDiff = 0;
}
if (e.Style != null)
{
switch (e.Style.TextAlign)
{
case TextAlignEnum.CenterBottom:
case TextAlignEnum.GeneralBottom:
case TextAlignEnum.LeftBottom:
case TextAlignEnum.RightBottom:
hAdjust = hDiff;
break;
case TextAlignEnum.CenterCenter:
case TextAlignEnum.GeneralCenter:
case TextAlignEnum.LeftCenter:
case TextAlignEnum.RightCenter:
hAdjust = hDiff / 2;
break;
default:
break;
}
}
if (IsRoTable)
{
_rtf.ForeColor = Color.Red;
}
else
{
_rtf.ForeColor = e.Style.ForeColor;
}
_rtf.BackColor = e.Style.BackColor;
_rtf.Render(e.Graphics, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + hAdjust, e.Bounds.Width - 3, e.Bounds.Height));
}
}
// spell check unless (we're just measuring)
if (!e.Measuring)
{
CharRangeList errors = SpellChecker.CheckText(_rtf.Text);//(text);
// underline errors
if (errors.Count > 0)
{
CharacterRange[] ranges = new CharacterRange[1];
ranges[0] = new CharacterRange(0, 1);
Pen pn = new Pen(Color.Green, 2);
StringFormat sf = new StringFormat(e.Style.StringFormat);
sf.SetMeasurableCharacterRanges(ranges);
Rectangle rc = e.Style.GetTextRectangle(e.Bounds, null);
Region[] rgns = e.Graphics.MeasureCharacterRanges(_rtf.Text, e.Style.Font, rc, sf);//(text, e.Style.Font, rc, sf);
float btm = rgns[0].GetBounds(e.Graphics).Bottom;
float top = rgns[0].GetBounds(e.Graphics).Top;
int adj = (int)(btm - top);
for (int i = 0; i < errors.Count; i++)
{
Point ptStart = _rtf.GetPositionFromCharIndex(errors[i].Start);
Point ptEnd = _rtf.GetPositionFromCharIndex(errors[i].Start + errors[i].Length);
SquigleLine(e.Graphics, e.Bounds.Left + ptStart.X, e.Bounds.Top + ptStart.Y + adj, e.Bounds.Left + ptEnd.X);
}
}
}
// and draw border last
//e.DrawCell(DrawCellFlags.Border);
// This can be used to draw more specific borders
DrawCellBorder(e);
// we're done with this cell
e.Handled = true;
}
}
// draw the RTF text private void SquigleLine(Graphics graphics, int x1, int y1, int x2)
if (e.Bounds.Width > 0 && e.Bounds.Height > 0) {
{ for (Point pt = new Point(x1, y1); pt.X + 2 < x2; pt.X += 4)
_rtf.Width = e.Bounds.Width - 1; // This has also been -3 which matchs the rener command {
// Please add a comment if this value nedds to be changed //Console.WriteLine("squiggle point {0}", pt);
_rtf.Rtf = rtfText; graphics.DrawLines(Pens.Red, new Point[]
CellRange cr = GetMergedRange(e.Row, e.Col); {
cr.UserData = _rtf.Height; new Point(pt.X, pt.Y),
int hAdjust = 0; new Point(pt.X + 2, pt.Y - 2),
int hDiff = e.Bounds.Height - _rtf.Height; new Point(pt.X + 4, pt.Y)
if (hDiff < 0) });
{ }
Rows[e.Row].Height = _rtf.Height + 4; }
AdjustGridControlSize();
hDiff = 0;
}
if (e.Style != null)
{
switch (e.Style.TextAlign)
{
case TextAlignEnum.CenterBottom:
case TextAlignEnum.GeneralBottom:
case TextAlignEnum.LeftBottom:
case TextAlignEnum.RightBottom:
hAdjust = hDiff;
break;
case TextAlignEnum.CenterCenter:
case TextAlignEnum.GeneralCenter:
case TextAlignEnum.LeftCenter:
case TextAlignEnum.RightCenter:
hAdjust = hDiff / 2;
break;
default:
break;
}
}
if (IsRoTable)
{
_rtf.ForeColor = Color.Red;
}
else
{
_rtf.ForeColor = e.Style.ForeColor;
}
_rtf.BackColor = e.Style.BackColor;
_rtf.Render(e.Graphics, new Rectangle(e.Bounds.X + 1, e.Bounds.Y + hAdjust, e.Bounds.Width - 3, e.Bounds.Height));
//CellRange cr = GetCellRange(e.Row, e.Col);
//Console.WriteLine("ownerDraw UserData [{0},{1}] = {2}", cr.r1, cr.c1, _rtf.ContentsRectangle.Height);
//cr.UserData = _rtf.ContentsRectangle.Height;
}
}
// and draw border last
//e.DrawCell(DrawCellFlags.Border);
// This can be used to draw more specific borders
DrawCellBorder(e);
// we're done with this cell
e.Handled = true;
}
}
private static Color _BorderColor = Color.Black; private static Color _BorderColor = Color.Black;
public static Color BorderColor public static Color BorderColor
{ {
@ -3965,7 +4010,6 @@ namespace Volian.Controls.Library
BackColor = Color.SkyBlue; BackColor = Color.SkyBlue;
BorderStyle = BorderStyle.None; BorderStyle = BorderStyle.None;
ScrollBars = RichTextBoxScrollBars.None; ScrollBars = RichTextBoxScrollBars.None;
_initializingEdit = false; _initializingEdit = false;
_pendingKey = (char)0; _pendingKey = (char)0;
_cancel = false; _cancel = false;