This commit is contained in:
@@ -13,6 +13,9 @@ using VEPROMS.CSLA.Library;
|
||||
namespace Volian.Controls.Library
|
||||
{
|
||||
public delegate void StepRTBEvent(object sender, EventArgs args);
|
||||
public delegate void StepRTBCursorKeysEvent(object sender, KeyEventArgs args);
|
||||
public delegate void StepRTBCursorMovementEvent(object sender, StepRTBCursorMovementEventArgs args);
|
||||
//public delegate void StepRTBMouseWheelEvent(object sender, MouseEventArgs args);
|
||||
public partial class StepRTB : RichTextBox , IStepRTB
|
||||
{
|
||||
#region Events
|
||||
@@ -31,6 +34,22 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
if (RTBRangeStatusChanged != null) RTBRangeStatusChanged(sender, args);
|
||||
}
|
||||
public event StepRTBCursorKeysEvent CursorKeyPress;
|
||||
private void OnCursorKeyPress(object sender, KeyEventArgs args)
|
||||
{
|
||||
if (CursorKeyPress != null) CursorKeyPress(sender, args);
|
||||
}
|
||||
public event StepRTBCursorMovementEvent CursorMovement;
|
||||
private void OnCursorMovement(object sender, StepRTBCursorMovementEventArgs args)
|
||||
{
|
||||
if (CursorMovement != null) CursorMovement(sender, args);
|
||||
}
|
||||
//public event StepRTBMouseWheelEvent MouseWheel;
|
||||
//private void OnMouseWheel(object sender, MouseEventArgs args)
|
||||
//{
|
||||
// if (MouseWheel != null) MouseWheel(sender, args);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// This event is not raised during all the in-between changes for link deletions
|
||||
/// </summary>
|
||||
@@ -166,10 +185,15 @@ namespace Volian.Controls.Library
|
||||
get { return RTBAPI.GetScrollLocation(this); }
|
||||
set { RTBAPI.SetScrollLocation(this, value); }
|
||||
}
|
||||
private Rectangle _ContentsRectangle;
|
||||
private Rectangle _ContentsRectangle = new Rectangle(0,0,0,0);
|
||||
public Rectangle ContentsRectangle
|
||||
{
|
||||
get { return _ContentsRectangle; }
|
||||
get
|
||||
{
|
||||
if (_ContentsRectangle.X == 0 && _ContentsRectangle.Y == 0 && _ContentsRectangle.Width == 0 && _ContentsRectangle.Height == 0)
|
||||
_ContentsRectangle = this.ClientRectangle;
|
||||
return _ContentsRectangle;
|
||||
}
|
||||
set
|
||||
{
|
||||
_ContentsRectangle = value;
|
||||
@@ -180,7 +204,7 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
get { return _ContentsRectangle.Size; }
|
||||
}
|
||||
private Size _AdjustSize; // if 0,0 puts text right next to bottom of box.
|
||||
private Size _AdjustSize = new Size(0,0); // if 0,0 puts text right next to bottom of box.
|
||||
public Size AdjustSize
|
||||
{
|
||||
get { return _AdjustSize; }
|
||||
@@ -232,14 +256,16 @@ namespace Volian.Controls.Library
|
||||
_Container = container;
|
||||
SetUp();
|
||||
}
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
_MyStepItem.MyStepPanel.MouseWheel(e);
|
||||
//base.OnMouseWheel(e);
|
||||
}
|
||||
//protected override void OnMouseWheel(MouseEventArgs e)
|
||||
//{
|
||||
// //_MyStepItem.MyStepPanel.MouseWheel(e);
|
||||
// OnMouseWheel(this,e);
|
||||
// //base.OnMouseWheel(e);
|
||||
//}
|
||||
private void SetUp()
|
||||
{
|
||||
BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.ScrollBars = RichTextBoxScrollBars.None;
|
||||
this.DetectUrls = true;
|
||||
ContentsResized += new ContentsResizedEventHandler(StepRTB_ContentsResized);
|
||||
this.LinkClicked += new LinkClickedEventHandler(StepRTB_LinkClicked);
|
||||
@@ -274,7 +300,8 @@ namespace Volian.Controls.Library
|
||||
void StepRTB_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
_MouseDown = false;
|
||||
HandleSelectionChange();
|
||||
if(this.Focused) // Only HandleSelectionChange if this control has focus.
|
||||
HandleSelectionChange();
|
||||
}
|
||||
#endregion
|
||||
#region ApplicationSupport
|
||||
@@ -574,11 +601,79 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private void AdjustSizeForContents()
|
||||
{
|
||||
// The client size should match the new rectangle.
|
||||
// First, determine the offset
|
||||
Size offset = Size - ClientSize;
|
||||
this.Size = ContentsSize + offset + AdjustSize;
|
||||
OnHeightChanged(this, new EventArgs());
|
||||
int widthNew = ContentsSize.Width + offset.Width + AdjustSize.Width;
|
||||
int heightNew = ContentsSize.Height + offset.Height + AdjustSize.Height;
|
||||
Size szNew = new Size(widthNew,heightNew);
|
||||
if (this.Size != szNew)
|
||||
{
|
||||
this.Size = szNew;
|
||||
OnHeightChanged(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
private float GetStringWidth(string strMeasureString)
|
||||
{
|
||||
using (Graphics g = Graphics.FromHwnd(Handle))
|
||||
{
|
||||
return g.MeasureString(strMeasureString, Font).Width;
|
||||
}
|
||||
}
|
||||
private int Ceiling(float f)
|
||||
{
|
||||
return (int)(Math.Ceiling(f));
|
||||
}
|
||||
public void AdjustWidthForContent()
|
||||
{
|
||||
int widthNL = Ceiling(GetStringWidth("\n"));
|
||||
int widthMax = 0;
|
||||
int widthMaxWW = 0;
|
||||
int indexStart = 0;
|
||||
int lineCountFromLines = Lines.Length;
|
||||
int lineCountFromGet = GetLineFromCharIndex(TextLength)+1;
|
||||
for (int i = 0; i < Lines.Length; i++)
|
||||
{
|
||||
int lineStart = GetLineFromCharIndex(indexStart);
|
||||
int indexEnd = indexStart + Lines[i].Length;
|
||||
int lineEnd = GetLineFromCharIndex(indexEnd);
|
||||
Point pointStart = GetPositionFromCharIndex(indexStart);
|
||||
Point pointEnd = GetPositionFromCharIndex(indexEnd);
|
||||
int indexEndPos = GetCharIndexFromPosition(pointEnd);
|
||||
if (indexEndPos + 1 < indexEnd) // This indicates that the text is wider than the Rich Text Box
|
||||
{
|
||||
int w = pointEnd.X + (indexEnd - indexEndPos) * widthNL;
|
||||
if (w > widthMaxWW)
|
||||
{
|
||||
widthMaxWW = w;
|
||||
}
|
||||
}
|
||||
if (lineEnd > lineStart)// this indicates that there was word-wrap on this line.
|
||||
{
|
||||
int w = pointEnd.X + Width * (lineEnd - lineStart);
|
||||
if (w > widthMaxWW)
|
||||
widthMaxWW = w;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pointEnd.X > widthMax)
|
||||
widthMax = pointEnd.X;
|
||||
}
|
||||
indexStart = indexEnd + 1;
|
||||
}
|
||||
if (widthMaxWW == 0)
|
||||
{
|
||||
int widthBorder = Width - ClientSize.Width;
|
||||
int w = widthMax + widthNL + widthBorder;
|
||||
if (Width != w)
|
||||
{
|
||||
Width = w;
|
||||
AdjustWidthForContent();// Try one more time
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Width = widthMaxWW;
|
||||
AdjustWidthForContent();
|
||||
}
|
||||
}
|
||||
public int CalculateHeight()
|
||||
{
|
||||
@@ -1129,17 +1224,20 @@ namespace Volian.Controls.Library
|
||||
if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) return;
|
||||
// Cursor moves out of box only if control is pressed too - otherwise key is
|
||||
// handled in rtb.
|
||||
if (keyargs.Control)_MyStepItem.MyStepPanel.StepCursorKeys(this, keyargs);
|
||||
//if (keyargs.Control)_MyStepItem.MyStepPanel.StepCursorKeys(this, keyargs); // Replaced with an event
|
||||
if (keyargs.Control) OnCursorKeyPress(this, keyargs);
|
||||
}
|
||||
private void StepRTB_PageKeyPressed(KeyEventArgs keyargs)
|
||||
{
|
||||
if (MyItemInfo.IsProcedure || MyItemInfo.IsSection) return;
|
||||
_MyStepItem.MyStepPanel.StepCursorKeys(this, keyargs);
|
||||
//_MyStepItem.MyStepPanel.StepCursorKeys(this, keyargs); Replaced with an event
|
||||
OnCursorKeyPress(this, keyargs);
|
||||
}
|
||||
private void StepRTB_ArrowPressed(E_ArrowKeys key)
|
||||
{
|
||||
Point cp = PointToClient(Cursor.Position);
|
||||
_MyStepItem.MyStepPanel.CursorMovement(this, cp, key);
|
||||
//_MyStepItem.MyStepPanel.CursorMovement(this, cp, key); Replaced with an event
|
||||
OnCursorMovement(this, new StepRTBCursorMovementEventArgs(cp, key));
|
||||
}
|
||||
private void StepRTB_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
|
||||
{
|
||||
@@ -1698,6 +1796,26 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public class StepRTBCursorMovementEventArgs
|
||||
{
|
||||
private Point _CursorLocation;
|
||||
public Point CursorLocation
|
||||
{
|
||||
get { return _CursorLocation; }
|
||||
set { _CursorLocation = value; }
|
||||
}
|
||||
private E_ArrowKeys _Key;
|
||||
public E_ArrowKeys Key
|
||||
{
|
||||
get { return _Key; }
|
||||
set { _Key = value; }
|
||||
}
|
||||
public StepRTBCursorMovementEventArgs(Point pt, E_ArrowKeys key)
|
||||
{
|
||||
_CursorLocation = pt;
|
||||
_Key = key;
|
||||
}
|
||||
}
|
||||
#region LinkLocation Class
|
||||
public class LinkLocation
|
||||
{
|
||||
|
Reference in New Issue
Block a user