Initialize Borders from FlexGrid selection

Eliminate SelChange funtions during Initialization
Eliminate Moving GridItem to the Left and Right on selection
Fixed a bug where SelectedEditItem was null
Eliminate SelChange funtions during Initialization
Use FlexGrid CellRange (Selection) to Get and Set Range Borders
Added Unknown value to GridLinePattern enum
Set Range Borders based upon CellRange (Selection)
This commit is contained in:
Rich 2011-03-22 15:05:22 +00:00
parent 81b22109e6
commit a03970cd09
6 changed files with 95 additions and 19 deletions

View File

@ -5,6 +5,7 @@ using System.Diagnostics;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using System.Drawing; using System.Drawing;
using C1.Win.C1FlexGrid;
namespace Volian.Controls.Library namespace Volian.Controls.Library
{ {
@ -152,6 +153,51 @@ namespace Volian.Controls.Library
HasColumns = c2 > c1; HasColumns = c2 > c1;
Invalidate(); Invalidate();
} }
public void InitializeBorder(VlnFlexGrid myFlexGrid, CellRange myRange)
{
_TopBorder = GridLinePattern.Unknown;
_InsideHorizontalBorder = GridLinePattern.Unknown;
_BottomBorder = GridLinePattern.Unknown;
_LeftBorder = GridLinePattern.Unknown;
_InsideVerticalBorder = GridLinePattern.Unknown;
_RightBorder = GridLinePattern.Unknown;
for (int r = myRange.r1; r <= myRange.r2; r++)
for (int c = myRange.c1; c <= myRange.c2; c++)
{
CellRange cr = myFlexGrid.GetMergedRange(r, c);
if (r == myRange.r1) // Top Border
_TopBorder = CombinePattern(_TopBorder, myFlexGrid.MyBorders.HorizontalLines[cr.r1, cr.c1]);
if (r == myRange.r1 && c == myRange.c1) // Left Border
_LeftBorder = CombinePattern(_LeftBorder, myFlexGrid.MyBorders.VerticalLines[cr.r1, cr.c1]);
if (r == myRange.r2) // Bottom Border
_BottomBorder = CombinePattern(_BottomBorder, myFlexGrid.MyBorders.HorizontalLines[cr.r2+1, cr.c2]);
if (r == myRange.r2 && c == myRange.c2) // Right Border
_RightBorder = CombinePattern(_RightBorder, myFlexGrid.MyBorders.VerticalLines[cr.r2, cr.c2+1]);
if (r == cr.r1 && c == cr.c1) // Look for inside lines
{
if (cr.r1 > myRange.r1 && cr.r1 < myRange.r2) // Inside Horizontal Top
_InsideHorizontalBorder = CombinePattern(_InsideHorizontalBorder, myFlexGrid.MyBorders.HorizontalLines[cr.r1, cr.c1]);
if (cr.r2 > myRange.r1 && cr.r2 < myRange.r2) // Inside Horizontal Bottom
_InsideHorizontalBorder = CombinePattern(_InsideHorizontalBorder, myFlexGrid.MyBorders.HorizontalLines[cr.r2 +1, cr.c2]);
if (cr.c1 > myRange.c1 && cr.c1 < myRange.c2) // Inside Vertical Left
_InsideVerticalBorder = CombinePattern(_InsideVerticalBorder, myFlexGrid.MyBorders.VerticalLines[cr.r1, cr.c1]);
if (cr.c2 > myRange.c1 && cr.c2 < myRange.c2) // Inside Vertical Right
_InsideVerticalBorder = CombinePattern(_InsideVerticalBorder, myFlexGrid.MyBorders.VerticalLines[cr.r2, cr.c2 + 1]);
}
c = cr.c2;//Skip to the end of the merged cells
}
HasRows = (_InsideHorizontalBorder != GridLinePattern.Unknown);
if (!HasRows) _InsideHorizontalBorder = GridLinePattern.None;
HasColumns = (_InsideVerticalBorder != GridLinePattern.Unknown);
if (!HasColumns) _InsideVerticalBorder = GridLinePattern.None;
Invalidate();
}
private GridLinePattern CombinePattern(GridLinePattern oldPattern, GridLinePattern newPattern)
{
if (oldPattern == GridLinePattern.Unknown) return newPattern;
if (oldPattern == newPattern) return oldPattern;
return GridLinePattern.Mixed;
}
#endregion #endregion
#region ctor #region ctor
public BorderSelectionPanel() public BorderSelectionPanel()

View File

@ -200,6 +200,8 @@ namespace Volian.Controls.Library
private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore private string _OrigRtf; // used to store original rtf to allow for 'escape' key restore
void MyFlexGrid_SelChange(object sender, EventArgs e) void MyFlexGrid_SelChange(object sender, EventArgs e)
{ {
if (Initializing) return;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("MyFlexGrid_SelChange {0}",MyFlexGrid.Selection);
RTBLastFocus = false; RTBLastFocus = false;
MyStepRTB.Visible = false; // Hide the editor if the Selection Changes MyStepRTB.Visible = false; // Hide the editor if the Selection Changes
if (MyFlexGrid.Selection.IsSingleCell && MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0) if (MyFlexGrid.Selection.IsSingleCell && MyFlexGrid.Row >= 0 && MyFlexGrid.Col >= 0)
@ -268,8 +270,6 @@ namespace Volian.Controls.Library
this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert); this.MyStepRTB.RoInsert += new StepRTBRoEvent(MyStepRTB_RoInsert);
this.MyFlexGrid.AdjustPastedText += new VlnFlexGridPasteEvent(MyFlexGrid_AdjustPastedText); this.MyFlexGrid.AdjustPastedText += new VlnFlexGridPasteEvent(MyFlexGrid_AdjustPastedText);
} }
void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args) void MyStepRTB_RoInsert(object sender, StepRTBRoEventArgs args)
{ {
if (MyFlexGrid.IsRoTable) if (MyFlexGrid.IsRoTable)
@ -302,8 +302,9 @@ namespace Volian.Controls.Library
//_MyStepRTB.Font = MyStepData.Font.WindowsFont; //_MyStepRTB.Font = MyStepData.Font.WindowsFont;
//ItemWidth = (int)GetTableWidth(MyStepRTB.Font, MyItemInfo.MyContent.Text, true); //ItemWidth = (int)GetTableWidth(MyStepRTB.Font, MyItemInfo.MyContent.Text, true);
//ItemWidth = MyFlexGrid.Width; //ItemWidth = MyFlexGrid.Width;
ItemLocation = new Point(50, _MyParentEditItem.Bottom); //ItemLocation = new Point(50, _MyParentEditItem.Bottom);
ItemLocation = TableLocation(_MyParentEditItem, MyStepSectionLayoutData, ItemWidth); Point newLocation = TableLocation(_MyParentEditItem, MyStepSectionLayoutData, ItemWidth);
if (!newLocation.Equals(ItemLocation)) ItemLocation = newLocation;
} }
public override void SetToolTip(string tip) public override void SetToolTip(string tip)
{ {
@ -483,10 +484,12 @@ namespace Volian.Controls.Library
{ {
VE_Font vefont = MyItemInfo.GetItemFont(); VE_Font vefont = MyItemInfo.GetItemFont();
MyFlexGrid.Font = vefont.WindowsFont; MyFlexGrid.Font = vefont.WindowsFont;
Initializing = true;
MyFlexGrid.ParseTableFromText(valtext); MyFlexGrid.ParseTableFromText(valtext);
MyFlexGrid.AutoSizeCols(); MyFlexGrid.AutoSizeCols();
MyFlexGrid.AutoSizeRows(); MyFlexGrid.AutoSizeRows();
MyFlexGrid.MakeRTFcells(); MyFlexGrid.MakeRTFcells();
Initializing = false;
} }
private bool FinishSave(string searchableText) private bool FinishSave(string searchableText)
{ {

View File

@ -459,7 +459,7 @@ namespace Volian.Controls.Library
/// </summary> /// </summary>
public void ItemShow() public void ItemShow()
{ {
if (_SelectedItemInfo != null && SelectedEditItem.BeingDisposed == false) if (_SelectedEditItem != null && SelectedEditItem.BeingDisposed == false)
{ {
SelectedEditItem.ItemShow(); SelectedEditItem.ItemShow();
OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedEditItem)); OnItemSelectedChanged(this, new ItemSelectedChangedEventArgs(SelectedEditItem));

View File

@ -158,17 +158,17 @@ namespace Volian.Controls.Library
} }
} }
} }
void MyFlexGrid_SelChange(object sender, EventArgs e) void MyFlexGrid_SelChange(object sender, EventArgs e)
{ {
if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0) if (MyFlexGrid.Selection.c1 < 0 || MyFlexGrid.Selection.r1 < 0)
return; return;
if (MyFlexGrid.Selection.c1 >= MyFlexGrid.Cols.Count-1 || MyFlexGrid.Selection.r1 >= MyFlexGrid.Rows.Count-1) if (MyFlexGrid.Selection.c1 >= MyFlexGrid.Cols.Count-1 || MyFlexGrid.Selection.r1 >= MyFlexGrid.Rows.Count-1)
return; return;
C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection(); if ((MyEditItem as GridItem).Initializing) return;
rbnBorderSelectionPanel.InitializeBorder(MyFlexGrid.MyBorders, cr.r1, cr.c1, cr.r2, cr.c2); //C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection();
//rbnBorderSelectionPanel.InitializeBorder(MyFlexGrid.MyBorders, cr.r1, cr.c1, cr.r2, cr.c2);
rbnBorderSelectionPanel.InitializeBorder(MyFlexGrid, MyFlexGrid.Selection);
} }
void _MyEditItem_Leave(object sender, EventArgs e) void _MyEditItem_Leave(object sender, EventArgs e)
{ {
// The following two lines were replaced by the third line so that the Ribbon KeyTips will work properly. // The following two lines were replaced by the third line so that the Ribbon KeyTips will work properly.
@ -186,7 +186,6 @@ namespace Volian.Controls.Library
MyFlexGrid.SelChange -= new EventHandler(MyFlexGrid_SelChange); MyFlexGrid.SelChange -= new EventHandler(MyFlexGrid_SelChange);
} }
} }
void _MyEditItem_Enter(object sender, EventArgs e) void _MyEditItem_Enter(object sender, EventArgs e)
{ {
// The following two lines were replaced by the third line so that the Ribbon KeyTips will work properly. // The following two lines were replaced by the third line so that the Ribbon KeyTips will work properly.
@ -205,7 +204,6 @@ namespace Volian.Controls.Library
Console.WriteLine("Turn on SelChange"); Console.WriteLine("Turn on SelChange");
} }
} }
void MyFlexGrid_CopyOptionChanged(object sender, EventArgs args) void MyFlexGrid_CopyOptionChanged(object sender, EventArgs args)
{ {
btnTblDgnPaste.Enabled = true; btnTblDgnPaste.Enabled = true;
@ -234,7 +232,6 @@ namespace Volian.Controls.Library
break; break;
} }
} }
void _MyStepRTB_SelectionChanged(object sender, EventArgs e) void _MyStepRTB_SelectionChanged(object sender, EventArgs e)
{ {
SetButtonAndMenuEnabling(false); SetButtonAndMenuEnabling(false);
@ -1929,12 +1926,9 @@ namespace Volian.Controls.Library
private void rbnBorderSelectionPanel_BordersChanged(object sender, EventArgs args) private void rbnBorderSelectionPanel_BordersChanged(object sender, EventArgs args)
{ {
C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection(); //C1.Win.C1FlexGrid.CellRange cr = MyFlexGrid.GetEvenSelection();
//foreach (C1.Win.C1FlexGrid.CellRange cr in MyFlexGrid.MySelection) MyFlexGrid.SetBorders(MyFlexGrid.Selection, rbnBorderSelectionPanel.TopBorder, rbnBorderSelectionPanel.InsideHorizontalBorder,
//{
MyFlexGrid.MyBorders.SetRange(cr.r1, cr.c1, cr.r2, cr.c2, rbnBorderSelectionPanel.TopBorder, rbnBorderSelectionPanel.InsideHorizontalBorder,
rbnBorderSelectionPanel.BottomBorder, rbnBorderSelectionPanel.LeftBorder, rbnBorderSelectionPanel.InsideVerticalBorder, rbnBorderSelectionPanel.RightBorder); rbnBorderSelectionPanel.BottomBorder, rbnBorderSelectionPanel.LeftBorder, rbnBorderSelectionPanel.InsideVerticalBorder, rbnBorderSelectionPanel.RightBorder);
//}
MyEditItem.Invalidate(); MyEditItem.Invalidate();
MyFlexGrid.Invalidate(); MyFlexGrid.Invalidate();
} }

View File

@ -438,6 +438,7 @@ namespace Volian.Controls.Library
} }
public enum GridLinePattern : int public enum GridLinePattern : int
{ {
Unknown = -1,
None = 0, None = 0,
Single = 1, Single = 1,
Double = 2, Double = 2,

View File

@ -92,6 +92,38 @@ namespace Volian.Controls.Library
get { return _MyItemInfo; } get { return _MyItemInfo; }
set { _MyItemInfo = value; } set { _MyItemInfo = value; }
} }
public void SetBorders(CellRange myRange,
GridLinePattern top, GridLinePattern middle, GridLinePattern bottom,
GridLinePattern left, GridLinePattern center, GridLinePattern right)
{
for (int r = myRange.r1; r <= myRange.r2; r++)
for (int c = myRange.c1; c <= myRange.c2; c++)
{
CellRange cr = GetMergedRange(r, c);
if (r == myRange.r1) // Top Border
if(top != GridLinePattern.Mixed) MyBorders.HorizontalLines[cr.r1, cr.c1]=top;
if (r == myRange.r1 && c == myRange.c1) // Left Border
if(left != GridLinePattern.Mixed) MyBorders.VerticalLines[cr.r1, cr.c1]=left;
if (r == myRange.r2) // Bottom Border
if(bottom != GridLinePattern.Mixed) MyBorders.HorizontalLines[cr.r2 + 1, cr.c2]=bottom;
if (r == myRange.r2 && c == myRange.c2) // Right Border
if(right != GridLinePattern.Mixed) MyBorders.VerticalLines[cr.r2, cr.c2 + 1] = right;
if (r == cr.r1 && c == cr.c1) // Look for inside lines
{
if (cr.r1 > myRange.r1 && cr.r1 < myRange.r2) // Inside Horizontal Top
if(middle != GridLinePattern.Mixed) MyBorders.HorizontalLines[cr.r1, cr.c1]=middle;
if (cr.r2 > myRange.r1 && cr.r2 < myRange.r2) // Inside Horizontal Bottom
if(middle != GridLinePattern.Mixed) MyBorders.HorizontalLines[cr.r2 + 1, cr.c2]=middle;
if (cr.c1 > myRange.c1 && cr.c1 < myRange.c2) // Inside Vertical Left
if(center != GridLinePattern.Mixed) MyBorders.VerticalLines[cr.r1, cr.c1]=center;
if (cr.c2 > myRange.c1 && cr.c2 < myRange.c2) // Inside Vertical Right
if(center != GridLinePattern.Mixed) MyBorders.VerticalLines[cr.r2, cr.c2 + 1]=center;
}
c = cr.c2;//Skip to the end of the merged cells
}
}
[XmlIgnore] [XmlIgnore]
public bool HasVScroll public bool HasVScroll
{ {