Override the default font for Demo Mode

Check for null MyFlexGrid before using it.
Added Static LineWidth0 method used for drawing borders on the screen
Fixed logic to draw borders on the VlnFlexGrid
Fixed logic to draw grid borders on the pdf output.
This commit is contained in:
Rich
2011-04-07 23:35:07 +00:00
parent f1074ce770
commit 2d16db5bf2
6 changed files with 310 additions and 145 deletions

View File

@@ -29,7 +29,6 @@ namespace Volian.Controls.Library
{
get { return _DefaultFixedBackgroundColor; }
}
public void CopyToCopiedFlexGrid(GridCopyOption myCopyOption)
{
MyCopyInfo.MyCopiedFlexGrid = new VlnFlexGrid(); //make a copy of the grid being copied
@@ -537,7 +536,7 @@ namespace Volian.Controls.Library
private void SetupGrid(int numrows, int numcols) //C1FlexGrid NewGrid()
{
// setup the default size of each cell in the table/grid
this.Cols.DefaultSize = 40;
this.Cols.DefaultSize = (int) DPI;
this.Rows.DefaultSize = 20;
// setup the number of rows and columns
@@ -771,125 +770,260 @@ namespace Volian.Controls.Library
e.Handled = true;
}
}
private static Color _BorderColor = Color.Black;
public static Color BorderColor
{
get { return VlnFlexGrid._BorderColor; }
set { VlnFlexGrid._BorderColor = value; }
}
private void DrawCellBorder(C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{
Graphics graphics =e.Graphics;
Graphics grGrid =e.Graphics;
Rectangle bounds = e.Bounds;
int row = e.Row;
int col = e.Col;
CellRange cr = GetMergedRange(row, col);
GridLinePattern lineTop = MyBorders.HorizontalLines[cr.r1,cr.c1];
GridLinePattern lineLeft = MyBorders.VerticalLines[cr.r1, cr.c1];
GridLinePattern lineBottom = MyBorders.HorizontalLines[cr.r2+1, cr.c2];
GridLinePattern lineRight = MyBorders.VerticalLines[cr.r2, cr.c2+1];
GridLinePattern topSide = MyBorders.HorizontalLines[cr.r1,cr.c1];
GridLinePattern rightOfTopSide = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c2 + 1];
GridLinePattern leftOfTopSide = cr.c1 == 0? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c1 - 1];
GridLinePattern leftSide = MyBorders.VerticalLines[cr.r1, cr.c1];
GridLinePattern aboveLeftSide = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c1];
GridLinePattern belowLeftSide = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c1];
GridLinePattern bottomSide = MyBorders.HorizontalLines[cr.r2+1, cr.c2];
GridLinePattern rightOfBottomSide = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c2 + 1];
GridLinePattern rightSide = MyBorders.VerticalLines[cr.r2, cr.c2+1];
GridLinePattern belowRightSide = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c2 + 1];
GridLinePattern none = GridLinePattern.None;
int x1 = bounds.Left;
int y1 = bounds.Top;
int x2 = bounds.Right - 1;
int y2 = bounds.Bottom - 1;
// We should look at the results of the following for Focus Style
Color bColor = Color.Blue; // Temporary - Set the border color to blue.
if ((e.Style ?? Styles.Normal).Name == "Focus")
{
if (lineRight == GridLinePattern.Thick || lineRight == GridLinePattern.Double)
lineRight = GridLinePattern.Single;
if (lineBottom == GridLinePattern.Thick || lineBottom == GridLinePattern.Double)
lineBottom = GridLinePattern.Single;
}
GridItem myGridItem = Parent as GridItem;
if (myGridItem == null) return;
if (row == 0 && lineTop != GridLinePattern.None)
if (row == 0 || col == 0) // Top or Left Edge - Draw on parent
{
Pen pn = VlnBorders.LinePen(lineTop, bColor);
//GridLinePattern lineTopLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c1 - 1];
GridLinePattern lineTopRight = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r1, cr.c2 + 1];
int dxTop = col == 0 ? (lineLeft == GridLinePattern.Double || lineLeft == GridLinePattern.Thick ? -3 : -1) : 0;
int dx = col == 0 ? -1 : 0;
using (Graphics grParent = myGridItem.CreateGraphics())
{
if (lineTop == GridLinePattern.Double)// cr.r2 == 0)
if (row == 0)
{
int lengthAdjustBottom = lineRight == GridLinePattern.Double ? -2 : 0;
grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 3, x2 + Left, y1 + Top - 3);
grParent.DrawLine(pn, x1 + Left + dx, y1 + Top - 1, x2 + Left + lengthAdjustBottom, y1 + Top - 1);
//if (lineRight == GridLinePattern.Double && lineTopRight != GridLinePattern.Double)
if (lineRight != GridLinePattern.None && lineTopRight != GridLinePattern.Double)
grParent.DrawLine(VlnBorders.LinePen(lineRight,bColor), x2 + Left, y1 + Top - 3, x2 + Left, y1 + Top - 1);
if (col == 0)
{
// Draw the top left intersection
DrawIntersection(grParent, Left - 3, Top-1, none, topSide,leftSide, none);
}
// Draw the top right intersection
DrawIntersection(grParent, Left +x2 - 2, Top-1, none, rightOfTopSide,rightSide,topSide);
// Draw the top side on the parent
DrawLine(grParent, topSide, Left + x1, Top + y1 - 1, Left + x2-3, Top + y1 -1);
}
else if(pn.Width < 2)
grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 1, x2 + Left, y1 + Top - 1);
else // Move line up and draw an extra pixel long to account for a bug in graphics
grParent.DrawLine(pn, x1 + Left + dxTop, y1 + Top - 2, x2 + Left + 1, y1 + Top - 2);
}
}
if (col == 0 && lineLeft != GridLinePattern.None)
{
Pen pn = VlnBorders.LinePen(lineLeft, bColor);
//GridLinePattern lineLeftAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c1];
GridLinePattern lineLeftBelow = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c1];
int dyLeft = row == 0 ? (lineLeft == GridLinePattern.Double || lineLeft == GridLinePattern.Thick ? -3 : -1) : 0;
int dy = row == 0 ? -1 : 0;
//GridItem myGridItem = Parent as GridItem;
using (Graphics grParent = myGridItem.CreateGraphics())
{
if (lineLeft == GridLinePattern.Double)// cr.r2 == 0)
if (col == 0)
{
int lengthAdjustRight = lineBottom == GridLinePattern.Double ? -2 : 0;
grParent.DrawLine(pn, x1 + Left - 3, y1 + Top + dyLeft, x1 + Left - 3, y2 + Top);
grParent.DrawLine(pn, x1 + Left - 1, y1 + Top + dy, x1 + Left - 1, y2 + Top + lengthAdjustRight);
if (lineBottom != GridLinePattern.None && lineLeftBelow != GridLinePattern.Double)
grParent.DrawLine(VlnBorders.LinePen(lineBottom, bColor), x1 + Left - 3, y2 + Top, x1 + Left - 1, y2 + Top);
// Draw the bottom left intersection
DrawIntersection(grParent, Left -3, Top + y2, leftSide,bottomSide,belowLeftSide,none);
// Draw the left side
DrawLine(grParent, leftSide, Left + x1 - 1, Top + y1, Left + x1 - 1, Top + y2-3);
}
else if (pn.Width < 2)
grParent.DrawLine(pn, x1 + Left - 1, y1 + Top + dyLeft, x1 + Left - 1, y2 + Top);
else // Move line left and draw an extra pixel long to account for a bug in graphics
grParent.DrawLine(pn, x1 + Left - 2, y1 + Top + dyLeft, x1 + Left - 2, y2 + Top + 1);
}
}
//GridLinePattern lineBottomLeft = cr.c1 == 0 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c1 - 1];
GridLinePattern lineBottomRight = cr.c2 == Cols.Count - 1 ? GridLinePattern.None : MyBorders.HorizontalLines[cr.r2 + 1, cr.c2 + 1];
//GridLinePattern lineRightAbove = cr.r1 == 0 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r1 - 1, cr.c2 + 1];
GridLinePattern lineRightBelow = cr.r2 == Rows.Count - 1 ? GridLinePattern.None : MyBorders.VerticalLines[cr.r2 + 1, cr.c2 + 1];
if (lineBottom != GridLinePattern.None)
// Draw the bottom right intersection
DrawIntersection(grGrid, x2 - 2, y2, rightSide, rightOfBottomSide, belowRightSide, bottomSide);
// Draw the bottom side
DrawLine(grGrid, bottomSide, x1, y2, x2-3, y2);
// Draw the right side
DrawLine(grGrid, rightSide, x2, y1, x2, y2-3);
}
private static void DrawLine(Graphics gr, GridLinePattern pattern, int x1, int y1, int x2, int y2)
{
if (pattern == GridLinePattern.None) return;
Pen pn = VlnBorders.LinePen(pattern, BorderColor);
DrawLine(gr, pn, pattern, x1, y1, x2, y2);
}
private static void DrawLine(Graphics gr, Pen pn, int x1, int y1, int x2, int y2)
{
DrawLine(gr, pn, GridLinePattern.Single, x1, y1, x2, y2);
}
private static void DrawLine(Graphics gr, Pen pn, GridLinePattern pattern, int x1, int y1, int x2, int y2)
{
int dx = 0;
int dy = 0;
int dblx = 0;
int dbly = 0;
int xThick = 0;
int yThick = 0;
if (x1 == x2) // Vertical Line
{
Pen pn = VlnBorders.LinePen(lineBottom, bColor);
int rightWidth = lineRight == GridLinePattern.Double ? 3 : 0; //VlnBorders.LineWidth(lineRight);
int thickAdjust = 0;
if (lineBottom == GridLinePattern.Thick && lineRight == GridLinePattern.Double && lineBottomRight != GridLinePattern.Thick)
thickAdjust = -3;
if (lineBottom == GridLinePattern.Double)
{
int lengthAdjustTop = lineRight == GridLinePattern.Double ? -2 : 0;
int lengthAdjustBottom = lineRightBelow == GridLinePattern.Double ? -2 : 0;
graphics.DrawLine(pn, x1, y2 - 2, x2+lengthAdjustTop, y2 - 2);
graphics.DrawLine(pn, x1, y2, x2+lengthAdjustBottom, y2);
if (lineRight == GridLinePattern.Double && lineBottomRight == GridLinePattern.Double && lineRightBelow == GridLinePattern.Double)
graphics.DrawLine(pn, x2, y2, x2+1, y2);
}
else if(pn.Width < 2) // Bottom line is thin. Determine if intersecting with double:
graphics.DrawLine(pn, x1, y2, x2-rightWidth, y2);
else // Move line up and draw an extra pixel long to account for a bug in graphics
graphics.DrawLine(pn, x1, y2 - 1, x2 + 1 + thickAdjust, y2 - 1);
dx = (int) (-pn.Width / 2);
dblx = -2;
if (pn.Width > 2)
yThick = 1;
}
if (lineRight != GridLinePattern.None)
else // Horizontal Line
{
Pen pn = VlnBorders.LinePen(lineRight, bColor);
int bottomWidth = lineBottom == GridLinePattern.Double ? 3 : 0;//VlnBorders.LineWidth(lineBottom);
int thickAdjust = 0;
if (lineRight == GridLinePattern.Thick && lineBottom == GridLinePattern.Double && lineRightBelow != GridLinePattern.Thick)
thickAdjust = -3;
if (lineRight == GridLinePattern.Double)// cr.r2 == 0)
{
int lengthAdjustLeft = lineBottom == GridLinePattern.Double ? -2 : 0;
int lengthAdjustRight = lineBottomRight == GridLinePattern.Double ? -2 : 0;
graphics.DrawLine(pn, x2 - 2, y1, x2 - 2, y2+lengthAdjustLeft);
graphics.DrawLine(pn, x2, y1, x2, y2+lengthAdjustRight);
}
else if (pn.Width < 2)
graphics.DrawLine(pn, x2, y1, x2, y2-bottomWidth);
dy = (int) (-pn.Width / 2);
dbly = -2;
if (pn.Width > 2)
xThick = 1;
}
gr.DrawLine(pn, x1 + dx, y1 + dy, x2 + dx + xThick, y2 + dy + yThick);
if(pattern == GridLinePattern.Double)
gr.DrawLine(pn, x1 + dx +dblx, y1 + dy + dbly, x2 + dx+dblx, y2 + dy+dbly);
}
private static void DrawIntersection(Graphics gr, int x, int y, GridLinePattern up, GridLinePattern right, GridLinePattern down, GridLinePattern left)
{
if (up == GridLinePattern.Double)
if (right == GridLinePattern.Double)
if (down == GridLinePattern.Double)
if (left == GridLinePattern.Double) DrawIntersectionAllDoubles(gr, x, y);
else DrawDrawIntersection3Doubles_URD(gr, x, y);
else // Down is not double
if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_URL(gr, x, y);
else DrawDrawIntersection2Doubles_UR(gr, x, y, down, left);
else // right is not double
if (down == GridLinePattern.Double)
if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_UDL(gr, x, y);
else DrawDrawIntersection2Doubles_UD(gr, x, y, right, left);
else // Down is not double
if (left == GridLinePattern.Double) DrawIntersection2Doubles_UL(gr, x, y, right, down);
else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left);
else
if (right == GridLinePattern.Double)
if (down == GridLinePattern.Double)
if (left == GridLinePattern.Double) DrawDrawIntersection3Doubles_RDL(gr, x, y);
else DrawDrawIntersection2Doubles_RD(gr, x, y, up, left);
else // Down is not double
if (left == GridLinePattern.Double) DrawDrawIntersection2Doubles_RL(gr, x, y, up, down);
else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left);
else
graphics.DrawLine(pn, x2 - 1, y1, x2 - 1, y2 + 1 + thickAdjust);
if (down == GridLinePattern.Double)
if (left == GridLinePattern.Double) DrawDrawIntersection2Doubles_DL(gr, x, y, up, right);
else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left);
else // These both use the same function with the same parameters
if (left == GridLinePattern.Double) DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left);
else DrawIntersectionOneDoubleOrLess(gr, x, y, up, right, down, left);
}
private static Pen pnDouble = VlnBorders.LinePen(GridLinePattern.Double, BorderColor);
private static Pen pnThick = VlnBorders.LinePen(GridLinePattern.Thick, BorderColor);
private static void DrawIntersectionAllDoubles(Graphics gr, int x, int y)
{
DrawLine(gr, pnDouble, x-1, y, x, y);
DrawLine(gr, pnDouble, x, y - 2, x, y - 3);
DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1);
}
private static void DrawDrawIntersection3Doubles_URD(Graphics gr, int x, int y)
{
DrawLine(gr, pnDouble, x , y, x, y - 3);
DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1);
}
private static void DrawDrawIntersection3Doubles_URL(Graphics gr, int x, int y)
{
DrawLine(gr, pnDouble, x, y, x + 2, y);
DrawLine(gr, pnDouble, x -1, y - 2, x , y - 2);
DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2);
}
private static void DrawDrawIntersection3Doubles_UDL(Graphics gr, int x, int y)
{
DrawLine(gr, pnDouble, x-1, y, x, y);
DrawLine(gr, pnDouble, x , y - 2, x , y - 3);
DrawLine(gr, pnDouble, x + 2, y-3, x + 2, y);
}
private static void DrawDrawIntersection3Doubles_RDL(Graphics gr, int x, int y)
{
DrawLine(gr, pnDouble, x-1, y, x, y);
DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1);
}
private static void DrawDrawIntersection2Doubles_UR(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 3, y);
else
{
DrawLine(gr, pnDouble, x, y, x + 2, y);
DrawLine(gr, pnDouble, x , y, x , y - 2);
DrawLine(gr, pnDouble, x + 2, y - 2, x + 3, y - 2);
}
}
private static void DrawDrawIntersection2Doubles_UD(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 3, y);
else
{
DrawLine(gr, pnDouble, x, y, x, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2);
}
}
private static void DrawIntersection2Doubles_UL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 3, y);
else
{
DrawLine(gr, pnDouble, x, y, x + 2, y);
DrawLine(gr, pnDouble, x , y - 2, x, y - 3);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2);
}
}
private static void DrawDrawIntersection2Doubles_RD(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 3, y);
else
{
DrawLine(gr, pnDouble, x, y, x, y - 2);
DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y + 1);
}
}
private static void DrawDrawIntersection2Doubles_RL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 2, y);
else
{
DrawLine(gr, pnDouble, x, y, x + 2, y);
DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2);
}
}
private static void DrawDrawIntersection2Doubles_DL(Graphics gr, int x, int y, GridLinePattern lp1, GridLinePattern lp2)
{
if (lp1 == GridLinePattern.Thick && lp2 == GridLinePattern.Thick)
DrawLine(gr, pnThick, x, y, x + 2, y);
else
{
DrawLine(gr, pnDouble, x-1, y, x, y);
DrawLine(gr, pnDouble, x, y - 2, x + 2, y - 2);
DrawLine(gr, pnDouble, x + 2, y, x + 2, y - 2);
}
}
private static void DrawIntersectionOneDoubleOrLess(Graphics gr, int x, int y,
GridLinePattern up, GridLinePattern right, GridLinePattern down, GridLinePattern left)
{
Pen pnUp = VlnBorders.LinePen(up, BorderColor);
Pen pnLeft = VlnBorders.LinePen(left, BorderColor);
int widthUpDown = Math.Max(VlnBorders.LineWidth0(up), VlnBorders.LineWidth0(down));
int heightLeftRight = Math.Max(VlnBorders.LineWidth0(left), VlnBorders.LineWidth0(right));
if (heightLeftRight > 0 && widthUpDown > 0)
{
Pen pn = new Pen(BorderColor, widthUpDown);
if(heightLeftRight > 1)
DrawLine(gr, pn, x + 2, y + 1 - heightLeftRight, x + 2, y);
else if(up == GridLinePattern.None) // Work around to set a pixel (actually set two)
DrawLine(gr, pn, x + 2, y, x + 2, y + 1);
}
if (left != GridLinePattern.None)
{
DrawLine(gr, pnLeft, x, y, x + 2 - widthUpDown, y);
if (left == GridLinePattern.Double)
DrawLine(gr, pnLeft, x, y - 2, x + 2 - widthUpDown, y - 2);
}
if (up != GridLinePattern.None)
{
DrawLine(gr, pnUp, x + 2, y - 3 , x + 2, y +1 - heightLeftRight);
if (up == GridLinePattern.Double)
DrawLine(gr, pnUp, x, y - 3, x, y +1 - heightLeftRight);
}
}
#endregion //Grid Initialize