Exemplo n.º 1
0
        /// <summary>Draw row at specified coordinates.</summary>
        /// <param name="graphicsRow">The graphics row.</param>
        /// <param name="rectRow">The rectangle row.</param>
        /// <param name="item">The item.</param>
        /// <param name="itemIndex">The item index.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="_newLiveControls">The _new Live Controls.</param>
        /// <param name="_liveControls">The _live Controls.</param>
        /// <param name="checkBoxSize">The check Box Size.</param>
        public static void DrawRow(Graphics graphicsRow, Rectangle rectRow, VisualListViewItem item, int itemIndex, VisualListView listView, ManagedHScrollBar hPanelScrollBar, ArrayList _newLiveControls, ArrayList _liveControls, int checkBoxSize)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawRow");

            // If its selected, that trumps all, if not then see if we are using alternating colors, if not draw normal
            // this can all be overridden by the sub item background property make sure anything can even be selected before drawing selection rectangles
            if (item.Selected && listView.Selectable)
            {
                using (SolidBrush _brushBackground = new SolidBrush(Color.FromArgb(255, listView.ItemSelectedColor.R, listView.ItemSelectedColor.G, listView.ItemSelectedColor.B)))
                {
                    if (!listView.FullRowSelect)
                    {
                        // Calculate how far into the control it goes
                        int _widthDepth = -hPanelScrollBar.Value + listView.Columns.Width;
                        graphicsRow.FillRectangle(_brushBackground, listView.RowsInnerClientRect.X, rectRow.Y, _widthDepth, rectRow.Height);
                    }
                    else
                    {
                        graphicsRow.FillRectangle(_brushBackground, listView.RowsInnerClientRect.X, rectRow.Y, listView.RowsInnerClientRect.Width, rectRow.Height);
                    }
                }
            }
            else
            {
                // If the back color of the list doesn't match the back color of the item (AND) the back color isn't white, then override it
                if ((item.BackColor.ToArgb() != listView.BackColor.ToArgb()) && (item.BackColor != Color.White))
                {
                    using (SolidBrush _backgroundBrush = new SolidBrush(item.BackColor))
                    {
                        graphicsRow.FillRectangle(_backgroundBrush, listView.RowsInnerClientRect.X, rectRow.Y, listView.RowsInnerClientRect.Width, rectRow.Height);
                    }
                }
                else if (listView.AlternatingColors)
                {
                    // Check for full row alternate color alternating colors are only shown if the row isn't selected.
                    int _alternateItemIndex = listView.Items.FindItemIndex(item);
                    if (_alternateItemIndex % 2 > 0)
                    {
                        using (SolidBrush _backgroundBrush = new SolidBrush(listView.AlternateBackground))
                        {
                            if (!listView.FullRowSelect)
                            {
                                // Calculate how far into the control it goes
                                int _widthDepth = -hPanelScrollBar.Value + listView.Columns.Width;
                                graphicsRow.FillRectangle(_backgroundBrush, listView.RowsInnerClientRect.X, rectRow.Y, _widthDepth, rectRow.Height);
                            }
                            else
                            {
                                graphicsRow.FillRectangle(_backgroundBrush, listView.RowsInnerClientRect.X, rectRow.Y, listView.RowsInnerClientRect.Width, rectRow.Height);
                            }
                        }
                    }
                }
            }

            int _xCursor = -hPanelScrollBar.Value + listView.Border.Thickness;

            for (var subItemIndex = 0; subItemIndex < listView.Columns.Count; subItemIndex++)
            {
                Rectangle _subItemRectangle = new Rectangle(_xCursor, rectRow.Y, listView.Columns[subItemIndex].Width, rectRow.Height);

                // Avoid drawing items that are not in the visible region
                if ((_subItemRectangle.Right < 0) || (_subItemRectangle.Left > listView.RowsInnerClientRect.Right))
                {
                    Debug.Write(string.Empty);
                }
                else
                {
                    DrawSubItem(graphicsRow, _subItemRectangle, item, item.SubItems[subItemIndex], subItemIndex, listView.Font, listView, _newLiveControls, _liveControls, listView.CellPaddingSize, checkBoxSize);
                }

                _xCursor += listView.Columns[subItemIndex].Width;
            }

            // Post draw for focus rect and hot tracking
            if ((itemIndex == listView.HoverItemIndex) && listView.HoverItemTracking)
            {
                // handle hot tracking of items
                Color transparentColor = Color.FromArgb(75, listView.HoverTrackingColor.R, listView.HoverTrackingColor.G, listView.HoverTrackingColor.B); // 182, 189, 210 );
                using (Brush hotBrush = new SolidBrush(transparentColor))
                {
                    graphicsRow.FillRectangle(hotBrush, listView.RowsInnerClientRect.X, rectRow.Y, listView.RowsInnerClientRect.Width, rectRow.Height);
                }
            }

            // Draw row borders
            if (item.RowBorderSize > 0)
            {
                using (Pen _borderPen = new Pen(item.RowBorderColor, item.RowBorderSize)
                {
                    Alignment = PenAlignment.Inset
                })
                {
                    graphicsRow.DrawRectangle(_borderPen, rectRow);
                }
            }

            // Make sure anything can even be selected before drawing selection rects
            if (listView.Selectable)
            {
                if (listView.ShowFocusRectangle && (listView.FocusedItem == item))
                {
                    // Deal with focus rect
                    ControlPaint.DrawFocusRectangle(graphicsRow, new Rectangle(listView.RowsInnerClientRect.X + 1, rectRow.Y, listView.RowsInnerClientRect.Width - 1, rectRow.Height));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Draw client rows of list control.</summary>
        /// <param name="graphicsRows">The graphics row.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="backColor">The back Color.</param>
        /// <param name="vPanelScrollBar">The v Panel Scroll Bar.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="_newLiveControls">The new Live Controls.</param>
        /// <param name="_liveControls">The live Controls.</param>
        /// <param name="checkBoxSize">The check Box Size.</param>
        public static void DrawRows(Graphics graphicsRows, VisualListView listView, Color backColor, ManagedVScrollBar vPanelScrollBar, ManagedHScrollBar hPanelScrollBar, ArrayList _newLiveControls, ArrayList _liveControls, int checkBoxSize)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawRows");

            using (SolidBrush _clientRowsViewBrush = new SolidBrush(backColor))
            {
                graphicsRows.FillRectangle(_clientRowsViewBrush, listView.RowsClientRectangle);
            }

            // Draw background image.
            if (listView.BackgroundImage != null)
            {
                if (listView.BackgroundStretchToFit)
                {
                    graphicsRows.DrawImage(listView.BackgroundImage, listView.RowsInnerClientRect.X, listView.RowsInnerClientRect.Y, listView.RowsInnerClientRect.Width, listView.RowsInnerClientRect.Height);
                }
                else
                {
                    graphicsRows.DrawImage(listView.BackgroundImage, listView.RowsInnerClientRect.X, listView.RowsInnerClientRect.Y);
                }
            }

            // Determine start item based on whether or not we have a vertical scrollbar present. Which item to start with in this visible view.
            int _startItem;

            if (vPanelScrollBar.Visible)
            {
                _startItem = vPanelScrollBar.Value;
            }
            else
            {
                _startItem = 0;
            }

            Rectangle _rectangleRow = listView.RowsRectangle;

            _rectangleRow.Height = listView.ItemHeight;

            // Draw rows.
            for (var item = 0; (item < listView.RowsVisible + 1) && (item + _startItem < listView.Items.Count); item++)
            {
                DrawRow(graphicsRows, _rectangleRow, listView.Items[item + _startItem], item + _startItem, listView, hPanelScrollBar, _newLiveControls, _liveControls, checkBoxSize);
                _rectangleRow.Y += listView.ItemHeight;
            }

            if (listView.GridLineStyle != GridLineStyle.None)
            {
                // TODO: DrawGridLines also vertical when sub-items exist.
                DrawGridLines(graphicsRows, vPanelScrollBar, hPanelScrollBar, listView);
            }

            // Draw hot tracking column overlay.
            if (listView.HoverColumnTracking && (listView.HoverColumnIndex != -1) && (listView.HoverColumnIndex < listView.Columns.Count))
            {
                int _xCursor = -hPanelScrollBar.Value;
                for (var _columnIndex = 0; _columnIndex < listView.HoverColumnIndex; _columnIndex++)
                {
                    _xCursor += listView.Columns[_columnIndex].Width;
                }

                using (Brush hotBrush = new SolidBrush(Color.FromArgb(75, listView.HoverTrackingColor.R, listView.HoverTrackingColor.G, listView.HoverTrackingColor.B)))
                {
                    graphicsRows.FillRectangle(hotBrush, _xCursor, listView.RowsInnerClientRect.Y, listView.Columns[listView.HoverColumnIndex].Width + 1, listView.RowsInnerClientRect.Height - 1);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>Draw grid lines in client area.</summary>
        /// <param name="rowsDC">Graphics dc.</param>
        /// <param name="vPanelScrollBar">The v Panel Scroll Bar.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="listView">The list View.</param>
        public static void DrawGridLines(Graphics rowsDC, ManagedVScrollBar vPanelScrollBar, ManagedHScrollBar hPanelScrollBar, VisualListView listView)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawGridLines");

            int _yCursor = listView.RowsInnerClientRect.Y;

            using (Pen _gridPen = new Pen(listView.GridColor))
            {
                // Determine the grid line style.
                if (listView.GridLineStyle == GridLineStyle.Dashed)
                {
                    _gridPen.DashStyle = DashStyle.Dash;
                }
                else if (listView.GridLineStyle == GridLineStyle.Solid)
                {
                    _gridPen.DashStyle = DashStyle.Solid;
                }
                else
                {
                    _gridPen.DashStyle = DashStyle.Solid;
                }

                // Draw horizontal grid lines.
                if ((listView.GridLines == GridLines.Both) || (listView.GridLines == GridLines.Horizontal))
                {
                    int _rowsToDraw = listView.RowsVisible + 1;
                    if (listView.GridTypes == GridTypes.Exists)
                    {
                        if (listView.RowsVisible > listView.Count)
                        {
                            _rowsToDraw = listView.Count;
                        }
                    }

                    for (var _item = 0; _item < _rowsToDraw; _item++)
                    {
                        _yCursor += listView.ItemHeight;

                        // Draw horizontal line.
                        rowsDC.DrawLine(_gridPen, 0, _yCursor, listView.RowsInnerClientRect.Width, _yCursor);
                    }
                }

                // Draw vertical grid lines.
                if ((listView.GridLines == GridLines.Both) || (listView.GridLines == GridLines.Vertical))
                {
                    int _xCursor = -hPanelScrollBar.Value;
                    for (var column = 0; column < listView.Columns.Count; column++)
                    {
                        _xCursor += listView.Columns[column].Width;

                        // Draw vertical line.
                        rowsDC.DrawLine(_gridPen, _xCursor + 1, listView.RowsInnerClientRect.Y, _xCursor + 1, listView.RowsInnerClientRect.Bottom); // draw vertical line
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>Draw the column headers.</summary>
        /// <param name="graphicHeader">The graphics header.</param>
        /// <param name="sizeHeader">The size header.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="theme">The theme.</param>
        public static void DrawColumnHeaders(Graphics graphicHeader, Size sizeHeader, VisualListView listView, ManagedHScrollBar hPanelScrollBar, IntPtr theme)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawColumnHeaders - Count: " + listView.Columns.Count);

            // Draw the column header background.
            if (listView.ControlStyle == LVControlStyles.SuperFlat)
            {
                SolidBrush _headerRectangleBrush = new SolidBrush(listView.ColumnColorState.Enabled);
                graphicHeader.FillRectangle(_headerRectangleBrush, listView.HeaderRectangle);
                _headerRectangleBrush.Dispose();
            }
            else
            {
                graphicHeader.FillRectangle(SystemBrushes.Control, listView.HeaderRectangle);
            }

            if (listView.Columns.Count <= 0)
            {
                return;
            }

            // Draw vertical lines first then horizontal lines.
            int _currentX = -hPanelScrollBar.Value + listView.HeaderRectangle.X;

            foreach (VisualListViewColumn column in listView.Columns)
            {
                // Cull columns that won't be drawn first.
                if (_currentX + column.Width < 0)
                {
                    _currentX += column.Width;

                    // Skip this column, its not being drawn.
                    continue;
                }

                if (_currentX > listView.HeaderRectangle.Right)
                {
                    // Were past the end of the visible column, stop drawing.
                    return;
                }

                if (column.Width > 0)
                {
                    DrawColumnHeader(graphicHeader, new Rectangle(_currentX, listView.HeaderRectangle.Y, column.Width, listView.HeaderHeight), column, theme, listView);
                }

                // Move the parser.
                _currentX += column.Width;
            }
        }
Exemplo n.º 5
0
        /// <summary>Draw client rows of list control.</summary>
        /// <param name="graphicsRows">The graphics row.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="vPanelScrollBar">The v Panel Scroll Bar.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="_newLiveControls">The new Live Controls.</param>
        /// <param name="_liveControls">The live Controls.</param>
        /// <param name="checkBoxSize">The check Box Size.</param>
        public static void DrawRows(Graphics graphicsRows, VisualListViewEx listView, ManagedVScrollBar vPanelScrollBar, ManagedHScrollBar hPanelScrollBar, ArrayList _newLiveControls, ArrayList _liveControls, int checkBoxSize)
        {
            DebugTraceManager.WriteDebug("ListViewRenderer::DrawRows", DebugTraceManager.DebugOutput.TraceListener);

            SolidBrush brush = new SolidBrush(listView.BackColor);

            graphicsRows.FillRectangle(brush, listView.RowsClientRect);
            brush.Dispose();

            // if they have a background image, then display it
            if (listView.BackgroundImage != null)
            {
                if (listView.BackgroundStretchToFit)
                {
                    graphicsRows.DrawImage(listView.BackgroundImage, listView.RowsInnerClientRect.X, listView.RowsInnerClientRect.Y, listView.RowsInnerClientRect.Width, listView.RowsInnerClientRect.Height);
                }
                else
                {
                    graphicsRows.DrawImage(listView.BackgroundImage, listView.RowsInnerClientRect.X, listView.RowsInnerClientRect.Y);
                }
            }

            // determine start item based on whether or not we have a vertical scrollbar present
            int nStartItem; // which item to start with in this visible pane

            if (vPanelScrollBar.Visible)
            {
                nStartItem = vPanelScrollBar.Value;
            }
            else
            {
                nStartItem = 0;
            }

            Rectangle rectRow = listView.RowsRect;

            rectRow.Height = listView.ItemHeight;

            /* Draw Rows */
            for (var item = 0; (item < listView.VisibleRowsCount + 1) && (item + nStartItem < listView.Items.Count); item++)
            {
                DrawRow(graphicsRows, rectRow, listView.Items[item + nStartItem], item + nStartItem, listView, hPanelScrollBar, _newLiveControls, _liveControls, checkBoxSize);
                rectRow.Y += listView.ItemHeight;
            }

            if (listView.GridLineStyle != GridLineStyle.None)
            {
                DrawGridLines(graphicsRows, vPanelScrollBar, hPanelScrollBar, listView);
            }

            // draw hot tracking column overlay
            if (listView.HotColumnTracking && (listView.HotColumnIndex != -1) && (listView.HotColumnIndex < listView.Columns.Count))
            {
                int nXCursor = -hPanelScrollBar.Value;
                for (int nColumnIndex = 0; nColumnIndex < listView.HotColumnIndex; nColumnIndex++)
                {
                    nXCursor += listView.Columns[nColumnIndex].Width;
                }

                using (Brush hotBrush = new SolidBrush(Color.FromArgb(75, listView.HotTrackingColor.R, listView.HotTrackingColor.G, listView.HotTrackingColor.B)))
                {
                    graphicsRows.FillRectangle(hotBrush, nXCursor, listView.RowsInnerClientRect.Y, listView.Columns[listView.HotColumnIndex].Width + 1, listView.RowsInnerClientRect.Height - 1);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>Draw grid lines in client area.</summary>
        /// <param name="rowsDC">Graphics dc.</param>
        /// <param name="vPanelScrollBar">The v Panel Scroll Bar.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="listView">The list View.</param>
        public static void DrawGridLines(Graphics rowsDC, ManagedVScrollBar vPanelScrollBar, ManagedHScrollBar hPanelScrollBar, VisualListViewEx listView)
        {
            DebugTraceManager.WriteDebug("ListViewRenderer::DrawGridLines", DebugTraceManager.DebugOutput.TraceListener);

            // int _startItem = vPanelScrollBar.Value;
            // int _yCursor = rect.Y;
            int _yCursor = listView.RowsInnerClientRect.Y;

            using (Pen _gridPen = new Pen(listView.GridColor))
            {
                if (listView.GridLineStyle == GridLineStyle.Dashed)
                {
                    _gridPen.DashStyle = DashStyle.Dash;
                }
                else if (listView.GridLineStyle == GridLineStyle.Solid)
                {
                    _gridPen.DashStyle = DashStyle.Solid;
                }
                else
                {
                    _gridPen.DashStyle = DashStyle.Solid;
                }

                if ((listView.GridLines == GridLines.Both) || (listView.GridLines == GridLines.Horizontal))
                {
                    int _rowsToDraw = listView.VisibleRowsCount + 1;
                    if (listView.GridTypes == GridTypes.Exists)
                    {
                        if (listView.VisibleRowsCount > listView.Count)
                        {
                            _rowsToDraw = listView.Count;
                        }
                    }

                    for (var _item = 0; _item < _rowsToDraw; _item++)
                    {
                        _yCursor += listView.ItemHeight;

                        // draw horizontal line
                        rowsDC.DrawLine(_gridPen, 0, _yCursor, listView.RowsInnerClientRect.Width, _yCursor);
                    }
                }

                if ((listView.GridLines == GridLines.Both) || (listView.GridLines == GridLines.Vertical))
                {
                    int _xCursor = -hPanelScrollBar.Value;
                    for (var column = 0; column < listView.Columns.Count; column++)
                    {
                        _xCursor += listView.Columns[column].Width;
                        rowsDC.DrawLine(_gridPen, _xCursor + 1, listView.RowsInnerClientRect.Y, _xCursor + 1, listView.RowsInnerClientRect.Bottom); // draw vertical line
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>Draw the column header.</summary>
        /// <param name="graphicHeader">The graphics header.</param>
        /// <param name="sizeHeader">The size header.</param>
        /// <param name="listView">The list View.</param>
        /// <param name="hPanelScrollBar">The h Panel Scroll Bar.</param>
        /// <param name="theme">The theme.</param>
        public static void DrawColumnHeader(Graphics graphicHeader, Size sizeHeader, VisualListViewEx listView, ManagedHScrollBar hPanelScrollBar, IntPtr theme)
        {
            DebugTraceManager.WriteDebug("ListViewRenderer::DrawHeader", DebugTraceManager.DebugOutput.TraceListener);

            if (listView.ControlStyle == LVControlStyles.SuperFlat)
            {
                SolidBrush brush = new SolidBrush(listView.SuperFlatHeaderColor);
                graphicHeader.FillRectangle(brush, listView.HeaderRect);
                brush.Dispose();
            }
            else
            {
                graphicHeader.FillRectangle(SystemBrushes.Control, listView.HeaderRect);
            }

            if (listView.Columns.Count <= 0)
            {
                return;
            }

            // Draw vertical lines first, then horizontal lines
            int _currentX = -hPanelScrollBar.Value + listView.HeaderRect.X;

            foreach (VisualListViewColumn column in listView.Columns)
            {
                // cull columns that won't be drawn first
                if (_currentX + column.Width < 0)
                {
                    _currentX += column.Width;
                    continue; // skip this column, its not being drawn
                }

                if (_currentX > listView.HeaderRect.Right)
                {
                    return; // were past the end of the visible column, stop drawing
                }

                if (column.Width > 0)
                {
                    DrawColumnHeader(graphicHeader, new Rectangle(_currentX, listView.HeaderRect.Y, column.Width, listView.HeaderHeight), column, theme, listView);
                }

                _currentX += column.Width; // move the parser
            }
        }