示例#1
0
        /// <summary>Draw column in header control.</summary>
        /// <param name="graphicsColumn">The graphics column.</param>
        /// <param name="rectColumn">The rectangle column.</param>
        /// <param name="column">The column.</param>
        /// <param name="theme">The _theme.</param>
        /// <param name="listView">The list View.</param>
        public static void DrawColumnHeader(Graphics graphicsColumn, Rectangle rectColumn, VisualListViewColumn column, IntPtr theme, VisualListViewAdvanced listView)
        {
            DebugTraceManager.WriteDebug("ListViewRenderer::DrawColumnHeader - Name: " + column.Name, DebugTraceManager.DebugOutput.TraceListener);

            if (listView.ControlStyle == LVControlStyles.SuperFlat)
            {
                SolidBrush brush = new SolidBrush(listView.SuperFlatHeaderColor);
                graphicsColumn.FillRectangle(brush, rectColumn);
                brush.Dispose();
            }
            else if ((listView.ControlStyle == LVControlStyles.XP) && listView.ThemesAvailable)
            {
                // this is really the only thing we care about for themeing right now inside the control
                IntPtr hDC = graphicsColumn.GetHdc();

                RECT colrect  = new RECT(rectColumn.X, rectColumn.Y, rectColumn.Right, rectColumn.Bottom);
                RECT cliprect = new RECT(rectColumn.X, rectColumn.Y, rectColumn.Right, rectColumn.Bottom);

                if (column.State == ColumnStates.None)
                {
                    // Debug.WriteLine( "Normal" );
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 1, ref colrect, ref cliprect);
                }
                else if (column.State == ColumnStates.Pressed)
                {
                    // Debug.WriteLine( "Pressed" );
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 3, ref colrect, ref cliprect);
                }
                else if (column.State == ColumnStates.Hot)
                {
                    // Debug.WriteLine( "Hot" );
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 2, ref colrect, ref cliprect);
                }

                graphicsColumn.ReleaseHdc(hDC);
            }
            else
            {
                // normal state
                if (column.State != ColumnStates.Pressed)
                {
                    ControlPaint.DrawButton(graphicsColumn, rectColumn, ButtonState.Normal);
                }
                else
                {
                    ControlPaint.DrawButton(graphicsColumn, rectColumn, ButtonState.Pushed);
                }
            }

            // if there is an image, this routine will RETURN with exactly the space left for everything else after the image is drawn (or not drawn due to lack of space)
            if ((column.ImageIndex > -1) && (listView.ImageListColumns != null) && (column.ImageIndex < listView.ImageListColumns.Images.Count))
            {
                rectColumn = DrawCellGraphic(graphicsColumn, rectColumn, listView.ImageListColumns.Images[column.ImageIndex], HorizontalAlignment.Left, listView.CellPaddingSize, listView);
            }

            DrawCellText(graphicsColumn, rectColumn, column.Text, listView.Font, column.TextAlignment, listView.ForeColor, false, listView);
        }
示例#2
0
        /// <summary>
        /// Draw a themed background element.
        /// </summary>
        /// <param name="g">Graphics object reference.</param>
        /// <param name="draw">Rectangle for drawing.</param>
        /// <param name="exclude">Rectangle to exclude from drawing.</param>
        /// <param name="part">Theme part.</param>
        /// <param name="state">Theme state of part.</param>
        public void DrawThemeBackground(Graphics g, Rectangle draw, Rectangle exclude, int part, int state)
        {
            if (IsControlThemed)
            {
                // Create a Win32 version of the drawing Rectangle
                Win32.RECT drawWin32 = new Win32.RECT();
                drawWin32.left   = draw.X;
                drawWin32.top    = draw.Y;
                drawWin32.right  = draw.Right;
                drawWin32.bottom = draw.Bottom;

                // Create a Win32 version of the clipping Rectangle
                Win32.RECT excludeWin32 = new Win32.RECT();
                excludeWin32.left   = exclude.X;
                excludeWin32.top    = exclude.Y;
                excludeWin32.right  = exclude.Right;
                excludeWin32.bottom = exclude.Bottom;

                // Get access to the underlying HDC
                IntPtr hDC = g.GetHdc();

                // Make a note of the original clipping region
                IntPtr hOldClipRgn = IntPtr.Zero;
                Gdi32.GetClipRgn(hDC, ref hOldClipRgn);

                // Create region that excludes area from drawing rectangle
                IntPtr hDrawRgn    = Gdi32.CreateRectRgnIndirect(ref drawWin32);
                IntPtr hExcludeRgn = Gdi32.CreateRectRgnIndirect(ref excludeWin32);
                Gdi32.CombineRgn(hExcludeRgn, hDrawRgn, hExcludeRgn, (int)CombineFlags.RGN_DIFF);

                // Define required clipping rectangle
                Gdi32.SelectClipRgn(hDC, hExcludeRgn);

                // Perform actual drawing work
                Uxtheme.DrawThemeBackground(_hTheme, hDC, part, state, ref drawWin32, IntPtr.Zero);

                // Put clipping region back again
                Gdi32.SelectClipRgn(hDC, hOldClipRgn);

                // Delete objects no longer needed
                Gdi32.DeleteObject(hDrawRgn);
                Gdi32.DeleteObject(hExcludeRgn);

                // Must release the resource to prevent leaks!
                g.ReleaseHdc(hDC);
            }
        }
示例#3
0
        /// <summary>
        /// Draw a themed background element.
        /// </summary>
        /// <param name="g">Graphics object reference.</param>
        /// <param name="draw">Rectangle for drawing.</param>
        /// <param name="part">Theme part.</param>
        /// <param name="state">Theme state of part.</param>
        public void DrawThemeBackground(Graphics g, Rectangle draw, int part, int state)
        {
            if (IsControlThemed)
            {
                // Create a Win32 version of the drawing Rectangle
                Win32.RECT drawWin32 = new Win32.RECT();
                drawWin32.left   = draw.X;
                drawWin32.top    = draw.Y;
                drawWin32.right  = draw.Right;
                drawWin32.bottom = draw.Bottom;

                // Get access to the underlying HDC
                IntPtr hDC = g.GetHdc();

                // Perform actual drawing work
                Uxtheme.DrawThemeBackground(_hTheme, hDC, part, state, ref drawWin32, IntPtr.Zero);

                // Must release the resource to prevent leaks!
                g.ReleaseHdc(hDC);
            }
        }
示例#4
0
        /// <summary>Draw the column header.</summary>
        /// <param name="graphicsColumn">The graphics column.</param>
        /// <param name="columnRectangle">The rectangle column.</param>
        /// <param name="column">The column.</param>
        /// <param name="theme">The theme.</param>
        /// <param name="listView">The list View.</param>
        public static void DrawColumnHeader(Graphics graphicsColumn, Rectangle columnRectangle, VisualListViewColumn column, IntPtr theme, VisualListView listView)
        {
            ConsoleEx.WriteDebug("ListViewRenderer::DrawColumnHeader - Text: " + column.Text);

            if (listView.ControlStyle == LVControlStyles.SuperFlat)
            {
                SolidBrush columnRectangleBrush;

                if (column.State == ColumnStates.None)
                {
                    columnRectangleBrush = new SolidBrush(listView.ColumnColorState.Enabled);
                    graphicsColumn.FillRectangle(columnRectangleBrush, columnRectangle);
                }
                else if (column.State == ColumnStates.Pressed)
                {
                    columnRectangleBrush = new SolidBrush(listView.ColumnColorState.Pressed);
                    graphicsColumn.FillRectangle(columnRectangleBrush, columnRectangle);
                }
                else if (column.State == ColumnStates.Hover)
                {
                    columnRectangleBrush = new SolidBrush(listView.ColumnColorState.Hover);
                    graphicsColumn.FillRectangle(columnRectangleBrush, columnRectangle);
                }
            }
            else if ((listView.ControlStyle == LVControlStyles.XP) && listView.ThemesAvailable)
            {
                // This is really the only thing we care about for theme right now inside the control.
                IntPtr hDC = graphicsColumn.GetHdc();

                RECT _columnRect = new RECT(columnRectangle.X, columnRectangle.Y, columnRectangle.Right, columnRectangle.Bottom);
                RECT _clipRect   = new RECT(columnRectangle.X, columnRectangle.Y, columnRectangle.Right, columnRectangle.Bottom);

                if (column.State == ColumnStates.None)
                {
                    // Normal.
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 1, ref _columnRect, ref _clipRect);
                }
                else if (column.State == ColumnStates.Pressed)
                {
                    // Pressed
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 3, ref _columnRect, ref _clipRect);
                }
                else if (column.State == ColumnStates.Hover)
                {
                    // Hover
                    Uxtheme.DrawThemeBackground(theme, hDC, 1, 2, ref _columnRect, ref _clipRect);
                }

                graphicsColumn.ReleaseHdc(hDC);
            }
            else
            {
                // Normal state.
                if (column.State != ColumnStates.Pressed)
                {
                    ControlPaint.DrawButton(graphicsColumn, columnRectangle, ButtonState.Normal);
                }
                else
                {
                    ControlPaint.DrawButton(graphicsColumn, columnRectangle, ButtonState.Pushed);
                }
            }

            // Check if we need checkboxes in this column.
            if (column.CheckBox)
            {
                columnRectangle = DrawCheckBox(graphicsColumn, columnRectangle, column.Checked, ListViewConstants.CHECKBOX_SIZE, listView);
            }

            // If there is an image, this routine will RETURN with exactly the space left for everything else after the image is drawn (or not drawn due to lack of space).
            if ((column.ImageIndex > -1) && (listView.ImageListColumns != null) && (column.ImageIndex < listView.ImageListColumns.Images.Count))
            {
                columnRectangle = DrawCellGraphic(graphicsColumn, columnRectangle, listView.ImageListColumns.Images[column.ImageIndex], HorizontalAlignment.Left, listView.CellPaddingSize, listView);
            }

            DrawCellText(graphicsColumn, columnRectangle, column.Text, listView.Font, column.TextAlignment, listView.ForeColor, false, listView);
        }