Move frmErrors when frmLoader is moved

Shutoff SpellCheck for StepRTB
Use using for temporary StepRTB
Use using for vlnFlexGrid
Added debug output to track StepRTBs and vlnFlexGrids in memory
Limit bottom margin to 0 or above
Dispose of roImage after it is done being used
Dispose of Figure after it is done being used.
Use GetJustRODB so that images are not loaded.
Added ErrorHandler if annotation is deleted after a search
Track create, dispose and finalize
Add static variable to control if SpellCheck is used
Use using for temporary StepRTB
Lazy Load SelectionStack
Clean-up on Dispose
Track create, dispose and finalize
Make MyCopyInfo Lazy Loaded
Use using for temporary StepRTB
Add Dispose method for TableCellEditor
Cleanup on Dispose
Only kill MSWord instances that are invisible
This commit is contained in:
Rich
2012-07-13 18:34:57 +00:00
parent ce21565a15
commit 7bcfafcc8b
12 changed files with 520 additions and 387 deletions

View File

@@ -28,6 +28,25 @@ namespace Volian.Controls.Library
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
private bool _Finalized = false;
~StepRTB()
{
if (!_Finalized) _CountFinalized++;
_Finalized = true;
}
#region Events
public event StepRTBRoEvent RoInsert;
public void OnRoInsert(object sender, StepRTBRoEventArgs args)
@@ -207,12 +226,12 @@ namespace Volian.Controls.Library
font = new Font(value, 10, FontStyle.Italic);
using (StepRTB srtb = new StepRTB())
{
if (srtb.FontIsFixed(font)) _MySymbolFontName = "VESymbFix";
else _MySymbolFontName = "Arial Unicode MS";
}
if (srtb.FontIsFixed(font)) _MySymbolFontName = "VESymbFix";
else _MySymbolFontName = "Arial Unicode MS";
}
}
}
}
// use newer rich text box....
//[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
//static extern IntPtr LoadLibrary(string lpFileName);
@@ -542,7 +561,6 @@ namespace Volian.Controls.Library
SetUpStepRTB();
AddEventHandlers();
this.BorderStyleChanged += new EventHandler(StepRTB_BorderStyleChanged);
}
protected override void OnMouseWheel(MouseEventArgs e)
{
@@ -646,7 +664,8 @@ namespace Volian.Controls.Library
private void SetUpStepRTB()
{
DetectUrls = false;
C1SpellChecker2.SetActiveSpellChecking(this, true);
if(DoSpellCheck)
C1SpellChecker2.SetActiveSpellChecking(this, true);
this.Height = 10; // initialize the height to 10, the default height was too big for the cells in grid tables
BorderStyle = System.Windows.Forms.BorderStyle.None;
this.ScrollBars = RichTextBoxScrollBars.None;
@@ -892,7 +911,7 @@ namespace Volian.Controls.Library
if(newRtf != _LastRtf || ReadOnly != _lastReadOnly)
{
//Console.WriteLine("ItemID:{0}\r\nOld:'{1}'\r\nNew:'{2}'\r\n", MyItemInfo.ItemID, Rtf, newRtf);
this.ContentsResized -=new ContentsResizedEventHandler(StepRTB_ContentsResized);
this.ContentsResized -= new ContentsResizedEventHandler(StepRTB_ContentsResized);
Text = "";
this.ContentsResized += new ContentsResizedEventHandler(StepRTB_ContentsResized);
SelectedRtf = _LastRtf = newRtf;
@@ -1704,37 +1723,39 @@ namespace Volian.Controls.Library
private string GetSelectedDisplayableText()
{
StepRTB srtb = new StepRTB();
srtb.Rtf = this.SelectedRtf.Replace(@"\u8209?", "-");
string rtnstr = "";
string ctxt = srtb.Text;//this.SelectedText;
if (ctxt.EndsWith("<START]"))
ctxt = ctxt.Substring(0, ctxt.Length - 7);
int idx = 0;
int strtidx = ctxt.IndexOf("<START]");
int lnkidx = ctxt.IndexOf("#Link");
int endidx = ctxt.IndexOf("[END>");
if ((strtidx == -1 || strtidx > lnkidx) && lnkidx > -1 && endidx > -1)
using (StepRTB srtb = new StepRTB())
{
rtnstr += ctxt.Substring(idx, lnkidx);
idx = endidx + 5;
strtidx = ctxt.IndexOf("<START]", idx);
lnkidx = ctxt.IndexOf("#Link:", idx);
endidx = ctxt.IndexOf("[END>", idx);
srtb.Rtf = this.SelectedRtf.Replace(@"\u8209?", "-");
string rtnstr = "";
string ctxt = srtb.Text;//this.SelectedText;
if (ctxt.EndsWith("<START]"))
ctxt = ctxt.Substring(0, ctxt.Length - 7);
int idx = 0;
int strtidx = ctxt.IndexOf("<START]");
int lnkidx = ctxt.IndexOf("#Link");
int endidx = ctxt.IndexOf("[END>");
if ((strtidx == -1 || strtidx > lnkidx) && lnkidx > -1 && endidx > -1)
{
rtnstr += ctxt.Substring(idx, lnkidx);
idx = endidx + 5;
strtidx = ctxt.IndexOf("<START]", idx);
lnkidx = ctxt.IndexOf("#Link:", idx);
endidx = ctxt.IndexOf("[END>", idx);
}
while (strtidx > -1)
{
rtnstr += ctxt.Substring(idx, strtidx - idx);
idx = strtidx + 7;
rtnstr += ctxt.Substring(idx, lnkidx - idx);
idx = endidx + 5;
strtidx = ctxt.IndexOf("<START]", idx);
lnkidx = ctxt.IndexOf("#Link:", idx);
endidx = ctxt.IndexOf("[END>", idx);
}
if (idx < ctxt.Length)
rtnstr += ctxt.Substring(idx);
return rtnstr;
}
while (strtidx > -1)
{
rtnstr += ctxt.Substring(idx, strtidx - idx);
idx = strtidx + 7;
rtnstr += ctxt.Substring(idx, lnkidx - idx);
idx = endidx + 5;
strtidx = ctxt.IndexOf("<START]", idx);
lnkidx = ctxt.IndexOf("#Link:", idx);
endidx = ctxt.IndexOf("[END>", idx);
}
if (idx < ctxt.Length)
rtnstr += ctxt.Substring(idx);
return rtnstr;
}
private bool IsControlChar = false;
@@ -2158,14 +2179,25 @@ namespace Volian.Controls.Library
#endregion
#endregion
#region SelectionStack
Stack<SelectionData> _SelectionStack = new Stack<SelectionData>();
Stack<SelectionData> _SelectionStack = null;
public Stack<SelectionData> SelectionStack
{
get
{
if (_SelectionStack == null)
_SelectionStack = new Stack<SelectionData>();
return _SelectionStack;
}
}
public void PushSelection()
{
_SelectionStack.Push(new SelectionData(this));
SelectionStack.Push(new SelectionData(this));
}
public void PopSelection()
{
SelectionData selection = _SelectionStack.Pop();
SelectionData selection = SelectionStack.Pop();
if (SelectionStack.Count == 0)
_SelectionStack = null;
Select(selection.SelectionStart, selection.SelectionLength);
}
public class SelectionData
@@ -2299,59 +2331,61 @@ namespace Volian.Controls.Library
private RichTextBoxFinds _FindOptions = RichTextBoxFinds.None;
public bool FindText(string str, bool caseSensitive, bool matchWholeWord, bool reverse)
{
StepRTB savRTF = new StepRTB();
int startpos = SelectionStart + SelectionLength;
savRTF.Text = this.Text;
using (StepRTB savRTF = new StepRTB())
{
int startpos = SelectionStart + SelectionLength;
savRTF.Text = this.Text;
_FindOptions = RichTextBoxFinds.None;
if (caseSensitive)
_FindOptions |= RichTextBoxFinds.MatchCase;
if (matchWholeWord)
_FindOptions |= RichTextBoxFinds.WholeWord;
if (reverse)
{
_FindOptions |= RichTextBoxFinds.Reverse;
savRTF.Text = this.Text.Substring(0, SelectionStart);
startpos = savRTF.Text.Length;
if (startpos == 0)
return false; // at beginning of rtfbox during a reverse find
}
else
{
if (startpos >= savRTF.Text.Length)
return false; // at end of rtfbox during a forward find
}
// look for the find string in the temporary rtfbox
// then set the cursor selection in the real rtfbox
bool keepgoing = true;
while (keepgoing)
{
int pos = savRTF.Find(str, startpos, _FindOptions);
keepgoing = false;
if (pos >= 0)
_FindOptions = RichTextBoxFinds.None;
if (caseSensitive)
_FindOptions |= RichTextBoxFinds.MatchCase;
if (matchWholeWord)
_FindOptions |= RichTextBoxFinds.WholeWord;
if (reverse)
{
if (this.SkipLinkInfo(pos, str.Length))
{
if (reverse)
{
startpos--;
savRTF.Text = savRTF.Text.Substring(0, startpos);
}
else
startpos++;
if (startpos > 0 && startpos < savRTF.Text.Length)
keepgoing = true;
}
else
{
SelectionStart = pos;
SelectionLength = str.Length;
}
_FindOptions |= RichTextBoxFinds.Reverse;
savRTF.Text = this.Text.Substring(0, SelectionStart);
startpos = savRTF.Text.Length;
if (startpos == 0)
return false; // at beginning of rtfbox during a reverse find
}
else
return false;
{
if (startpos >= savRTF.Text.Length)
return false; // at end of rtfbox during a forward find
}
// look for the find string in the temporary rtfbox
// then set the cursor selection in the real rtfbox
bool keepgoing = true;
while (keepgoing)
{
int pos = savRTF.Find(str, startpos, _FindOptions);
keepgoing = false;
if (pos >= 0)
{
if (this.SkipLinkInfo(pos, str.Length))
{
if (reverse)
{
startpos--;
savRTF.Text = savRTF.Text.Substring(0, startpos);
}
else
startpos++;
if (startpos > 0 && startpos < savRTF.Text.Length)
keepgoing = true;
}
else
{
SelectionStart = pos;
SelectionLength = str.Length;
}
}
else
return false;
}
return true;
}
return true;
}
private int FindStart()
{
@@ -2784,6 +2818,12 @@ namespace Volian.Controls.Library
}
#endregion
#region SpellChecker
private static bool _DoSpellCheck = true;
public static bool DoSpellCheck
{
get { return StepRTB._DoSpellCheck; }
set { StepRTB._DoSpellCheck = value; }
}
// We made the Spell Checker method a static so that all of the StepRTB boxes will bare the same instance of the dictionary.
// This allow all the StepRTB's to automatically update when a new word is added.
private static C1.Win.C1SpellChecker.C1SpellChecker _C1SpellChecker2;