From 2f073726417cdc48f9ab3d84e55286119cc7f3ae Mon Sep 17 00:00:00 2001 From: John Date: Thu, 18 Nov 2021 19:32:25 +0000 Subject: [PATCH] C2021-004 logic to support table cell shading null reference check --- .../VlnFlexGrid.Designer.cs | 1 + PROMS/Volian.Controls.Library/VlnFlexGrid.cs | 140 ++++++++++++++---- PROMS/Volian.Controls.Library/vlnTreeView.cs | 1 + 3 files changed, 116 insertions(+), 26 deletions(-) diff --git a/PROMS/Volian.Controls.Library/VlnFlexGrid.Designer.cs b/PROMS/Volian.Controls.Library/VlnFlexGrid.Designer.cs index fe3114ca..95fa1523 100644 --- a/PROMS/Volian.Controls.Library/VlnFlexGrid.Designer.cs +++ b/PROMS/Volian.Controls.Library/VlnFlexGrid.Designer.cs @@ -52,6 +52,7 @@ namespace Volian.Controls.Library _CountDisposed++; _Disposed = true; _MyBorders = null; + _MyShading = null; _SpellChecker = null; _tableCellEditor = null; if (disposing && (components != null)) diff --git a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs index 9ebe8fdc..5a9397bc 100644 --- a/PROMS/Volian.Controls.Library/VlnFlexGrid.cs +++ b/PROMS/Volian.Controls.Library/VlnFlexGrid.cs @@ -190,6 +190,12 @@ namespace Volian.Controls.Library //check for merged cells 6th if (GetCellMergeString(XdNew) != GetCellMergeString(XdOld)) return true; + // C2021-004 check volian shading 7th + XmlNode oldNode = XdOld.SelectSingleNode("C1FlexGrid/Control/MyShadingDetailString"); // old shading information + XmlNode newNode = XdNew.SelectSingleNode("C1FlexGrid/Control/MyShadingDetailString"); // new shading information + if ((oldNode == null || oldNode.InnerText == null) || + checkFormat && newNode.InnerText != oldNode.InnerText) + return true; return false; } private string GetRowColSizeString(XmlDocument xd) @@ -476,8 +482,75 @@ namespace Volian.Controls.Library MyBorders.HorizontalLines[r+1, c] = MyCopyInfo.MyCopiedFlexGrid.MyBorders.HorizontalLines[br+1, bc]; MyBorders.VerticalLines[r, c+1] = MyCopyInfo.MyCopiedFlexGrid.MyBorders.VerticalLines[br, bc+1]; } - + #region Table Cell Shading + [XmlElement("MyShading")] + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public string MyShadingDetailString + { + get + { + return MyShading.ConvertToString(); + } + set + { + if (value != null) + _MyShading = VlnGridCellShading.Get(value); + else + _MyShading = null; + } + } + private VlnGridCellShading _MyShading = null; [XmlIgnore] + public VlnGridCellShading MyShading + { + get + { + if (_MyShading == null || _MyShading.TableShadingInfo.CellShadingColor.Length == 0) + _MyShading = new VlnGridCellShading(Color.White, Rows.Count, Cols.Count); + return _MyShading; + } + set { _MyShading = value; } + } + public void SetShading(CellRange myRange, Color shading) + { + Console.WriteLine("SetShading toString {0}", shading.ToString()); + //Console.WriteLine("SetShading toArgb {0}", shading.ToArgb()); + //Console.WriteLine("SetShading Name {0}", shading.Name); + for (int r = myRange.r1; r <= myRange.r2; r++) + for (int c = myRange.c1; c <= myRange.c2; c++) + { + CellRange cr = GetMergedRange(r, c); + MyShading.TableShadingInfo[cr.r1, cr.c1] = MyShading.GetARGBstring(shading); + c = cr.c2; //Skip to the end of the merged cells + } + } + public void SetShading(CellRange myRange, ShadingOption fmtShadingOpt) + { + Console.WriteLine("SetShading toString {0}", fmtShadingOpt.ToString()); + for (int r = myRange.r1; r <= myRange.r2; r++) + for (int c = myRange.c1; c <= myRange.c2; c++) + { + CellRange cr = GetMergedRange(r, c); + MyShading.TableShadingInfo[cr.r1, cr.c1] = fmtShadingOpt.GetARBGstringForTableCells(); + c = cr.c2; //Skip to the end of the merged cells + } + } + public void ShowTableCellShading() + { + for (int r = 0; r < Rows.Count; r++) + for (int c = 0; c < Cols.Count; c++) + { + CellRange cr = GetMergedRange(r, c); + Color clr = MyShading.GetColor(cr.r1, cr.c1); + cr.StyleNew.BackColor = clr; + } + } + public void PasteShading(int r, int c, int sr, int sc) + { + MyShading.TableShadingInfo[r, c] = MyCopyInfo.MyCopiedFlexGrid.MyShading.TableShadingInfo[sr, sc]; + } + #endregion[XmlIgnore] public bool HasVScroll { get @@ -1263,9 +1336,9 @@ namespace Volian.Controls.Library { using (RTF _rtf = new RTF()) { - // use nearest solid color - // (the RTF control doesn't dither, and doesn't support transparent backgrounds) - Color solid = e.Graphics.GetNearestColor(e.Style.BackColor); + // use nearest solid color + // (the RTF control doesn't dither, and doesn't support transparent backgrounds) + Color solid = e.Graphics.GetNearestColor(e.Style.BackColor); DPI = e.Graphics.DpiX; if (e.Style.BackColor != solid) e.Style.BackColor = solid; @@ -1365,10 +1438,10 @@ namespace Volian.Controls.Library } } } - // and draw border last - //e.DrawCell(DrawCellFlags.Border); - // This can be used to draw more specific borders - DrawCellBorder(e); + // 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; } @@ -3027,6 +3100,7 @@ namespace Volian.Controls.Library // set new column width to same width as column from where it was inserted this.Cols[newcol].Width = this.Cols[newcol + 1].Width; MyBorders.InsertColumn(newcol); + MyShading.InsertColumn(newcol); // C2021-004 table cell shading this.AdjustMergedColumns(newcol, true, false); this.AdjustGridControlSize(); } @@ -3039,6 +3113,7 @@ namespace Volian.Controls.Library else this.Cols.Insert(colidx + 1); MyBorders.InsertColumn(colidx); + MyShading.InsertColumn(colidx); // C2021-004 table cell shading // set new column width to same width as column from where it was inserted this.Cols[colidx + 1].Width = this.Cols[colidx].Width; this.AdjustMergedColumns(colidx + 1, false, false); @@ -3053,6 +3128,7 @@ namespace Volian.Controls.Library this.Rows[newrow].Height = (Rows[newrow + 1].Height == -1) ? Rows.DefaultSize : Rows[newrow + 1].Height; //this.Rows[newrow].Height = this.Rows[newrow + 1].Height; MyBorders.InsertRow(newrow); + MyShading.InsertRow(newrow); // C2021-004 table cell shading this.AdjustMergedRows(newrow, true, false); this.AdjustGridControlSize(); } @@ -3068,6 +3144,7 @@ namespace Volian.Controls.Library this.Rows[rowidx + 1].Height = (Rows[rowidx].Height == -1) ? Rows.DefaultSize : Rows[rowidx].Height; //this.Rows[rowidx + 1].Height = this.Rows[rowidx].Height; MyBorders.InsertRow(rowidx + 1); + MyShading.InsertRow(rowidx + 1); // C2021-004 table cell shading this.AdjustMergedRows(rowidx + 1, false, false); this.AdjustGridControlSize(); } @@ -3160,7 +3237,8 @@ namespace Volian.Controls.Library mergedRow = false; } MyBorders.DeleteRows(strow, cnt); - this.AdjustGridControlSize(); + MyShading.DeleteRows(strow, cnt); // C2021-004 table cell shading + this.AdjustGridControlSize(); } private void RemoveColumns(int strow, int stcol, int cnt) @@ -3183,7 +3261,8 @@ namespace Volian.Controls.Library mergedCol = false; } MyBorders.DeleteColumns(stcol, cnt); - this.AdjustGridControlSize(); + MyShading.DeleteColumns(stcol, cnt); // C2021-004 table cell shading + this.AdjustGridControlSize(); } #endregion //Grid Add and Remove Row / Column @@ -3266,6 +3345,7 @@ namespace Volian.Controls.Library Cols.Add(colsToAdd); AdjustMergedColumns(Cols.Count - 1, colsToAdd, false, false); MyBorders.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); + MyShading.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); // C2021-004 table cell shading } switch (pp) @@ -3274,6 +3354,7 @@ namespace Volian.Controls.Library this.Rows.InsertRange(selR1, rowsToAdd); AdjustMergedRows(selR1, rowsToAdd, true, false); MyBorders.InsertRows(Rows.Count - rowsToAdd - 1, rowsToAdd); + MyShading.InsertRows(Rows.Count - rowsToAdd - 1, rowsToAdd); // C2021-004 table cell shading break; case enmPastePos.After: if (selR2+1 < Rows.Count - 1) @@ -3284,6 +3365,7 @@ namespace Volian.Controls.Library else this.Rows.Add(rowsToAdd); MyBorders.InsertRows(Rows.Count - rowsToAdd - 1, rowsToAdd); + MyShading.InsertRows(Rows.Count - rowsToAdd - 1, rowsToAdd); // C2021-004 table cell shading break; case enmPastePos.Replace: if (rowsToAdd > Rows.Count - Selection.r1) @@ -3313,6 +3395,7 @@ namespace Volian.Controls.Library this[r + rowOffset, c] = MyCopyInfo.MyCopiedFlexGrid[r, c]; MatchStyle(crm, cr); PasteBorders(r + rowOffset, c, r, c); + PasteShading(r + rowOffset, c, r, c); // C2021-004 paste the shading information // if the paste is above - put back the range for the source location // if the paste is below - copy merge range for the destination int r1 = crm.r1 + rowsToAdd - rowOffset; @@ -3368,6 +3451,7 @@ namespace Volian.Controls.Library Rows.Add(rowsToAdd); AdjustMergedRows(Rows.Count, false, false); MyBorders.InsertRows(Rows.Count - rowsToAdd - 1,rowsToAdd); + MyShading.InsertRows(Rows.Count - rowsToAdd - 1, rowsToAdd); // C2021-004 table cell shading } switch (pp) @@ -3376,6 +3460,7 @@ namespace Volian.Controls.Library this.Cols.InsertRange(selC1, colsToAdd); AdjustMergedColumns(selC1, colsToAdd, true, false); MyBorders.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); + MyShading.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); // C2021-004 table cell shading break; case enmPastePos.After: if (selC2+1 < Cols.Count - 1) @@ -3386,6 +3471,7 @@ namespace Volian.Controls.Library else this.Cols.Add(colsToAdd); MyBorders.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); + MyShading.InsertColumns(Cols.Count - colsToAdd - 1, colsToAdd); // C2021-004 table cell shading break; case enmPastePos.Replace: if (colsToAdd > Cols.Count - selC1) @@ -3418,6 +3504,7 @@ namespace Volian.Controls.Library this[r, c + colOffset] = MyCopyInfo.MyCopiedFlexGrid[r, c]; MatchStyle(crm, cr); PasteBorders(r, c + colOffset, r, c); + PasteShading(r, c + colOffset, r, c); // C2021-004 paste the shading information // if the paste is to the left - put back the range for the source location // if the paste is to the right - copy merge range for the destination int c1 = crm.c1 + colsToAdd - colOffset; @@ -3462,7 +3549,8 @@ namespace Volian.Controls.Library else this.Rows.Add(rowsToAdd); MyBorders.InsertRows(selR2,rowsToAdd); - } + MyShading.InsertRows(selR2, rowsToAdd); // C2021-004 table cell shading + } if (colsToAdd > 0) { @@ -3474,7 +3562,8 @@ namespace Volian.Controls.Library else this.Cols.Add(colsToAdd); MyBorders.InsertColumns(selC2,colsToAdd); - } + MyShading.InsertColumns(selC2, colsToAdd); // C2021-004 table cell shading + } RemoveMergedRanges(MyCopyInfo.MyCopiedCellRange.r1 + rowOffset, MyCopyInfo.MyCopiedCellRange.c1 + colOffset, MyCopyInfo.MyCopiedCellRange.r2 + rowOffset, MyCopyInfo.MyCopiedCellRange.c2 + colOffset); @@ -3495,6 +3584,7 @@ namespace Volian.Controls.Library this[r + rowOffset, c + colOffset] = MyCopyInfo.MyCopiedFlexGrid[r, c]; MatchStyle(crm, cr); PasteBorders(r + rowOffset, c + colOffset, r, c); + PasteShading(r + rowOffset, c + colOffset, r, c); // C2021-004 paste the shading information } } } @@ -4217,6 +4307,7 @@ namespace Volian.Controls.Library } } MyBorders = new VlnBorders(border, Rows.Count, Cols.Count); + MyShading = new VlnGridCellShading(Color.White, Rows.Count, Cols.Count); // C2021-004 setup shading information } private void TrimMergedRangeCellText(CellRange cr) @@ -4442,20 +4533,16 @@ namespace Volian.Controls.Library { Styles.Normal.BackColor = value; Styles.Alternate.BackColor = value; - for (int c = 0; c < Cols.Count; c++) - for (int r = 0; r < Rows.Count; r++) - { - CellRange cr = GetMergedRange(r, c); - if (cr.Style != null && cr.Style.BackColor != value && cr.Style.Name != "Fixed") - { - //if (r == 0 && c == 0) - // cr.Style.BackColor = Color.DarkGreen; - //else - cr.Style.BackColor = value; - //Console.WriteLine("{0}, {1}, {2}, {3}", r, c, cr.Style.Name, cr.Style.BackColor); - } - } - } + for (int c = 0; c < Cols.Count; c++) + for (int r = 0; r < Rows.Count; r++) + { + CellRange cr = GetMergedRange(r, c); + if (cr.Style != null && cr.Style.BackColor != value && cr.Style.Name != "Fixed") + { + cr.Style.BackColor = value; + } + } + } } /// /// Returns a list of cells or merged cells within the selection @@ -4692,6 +4779,7 @@ namespace Volian.Controls.Library { float fnSz = GetRTFFontSize(); // returns the font size in pts from the text's RTF _owner.SelectedFontSize = fnSz; // will trigger the changing of the font size from VlnFlexGrid class + _owner.ShowTableCellShading(); //C2021-004 display any background color change when you move off a cell } } diff --git a/PROMS/Volian.Controls.Library/vlnTreeView.cs b/PROMS/Volian.Controls.Library/vlnTreeView.cs index 9db2048f..4af9d3a3 100644 --- a/PROMS/Volian.Controls.Library/vlnTreeView.cs +++ b/PROMS/Volian.Controls.Library/vlnTreeView.cs @@ -3656,6 +3656,7 @@ namespace Volian.Controls.Library try { TreeNode dragNode = GetTreeNodeFromData(e.Data); + if (dragNode == null) return; // Compute drag position and move image Point formP = this.FindForm().PointToClient(new Point(e.X, e.Y)); DragHelper.ImageList_DragMove(formP.X - this.Left, formP.Y - this.Top);