CheckBoxPopupAdapter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / ButtonInternal / CheckBoxPopupAdapter.cs / 1 / CheckBoxPopupAdapter.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms.ButtonInternal { 
    using System; 
    using System.Diagnostics;
    using System.Drawing; 
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Drawing.Text;
    using System.Windows.Forms; 
    using System.Windows.Forms.Layout;
    using System.Diagnostics.CodeAnalysis; 
 

    internal class CheckBoxPopupAdapter : CheckBoxBaseAdapter { 

        internal CheckBoxPopupAdapter(ButtonBase control) : base(control) {}

        internal override void PaintUp(PaintEventArgs e, CheckState state) { 
            if (Control.Appearance == Appearance.Button) {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control); 
                adapter.PaintUp(e, Control.CheckState); 
            }
            else { 
                System.Drawing.Graphics g = e.Graphics;
                ColorData colors = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout = PaintPopupLayout(e, false).Layout();
 
                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null); 
 
                PaintImage(e, layout);
 
                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true, colors);
                DrawFlatBorder(e.Graphics, layout.checkBounds, colors.buttonShadow);
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight, true);
 
                PaintField(e, layout, colors, colors.windowText, true);
            } 
        } 

        internal override void PaintOver(PaintEventArgs e, CheckState state) { 
            System.Drawing.Graphics g = e.Graphics;
            if (Control.Appearance == Appearance.Button) {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintOver(e, Control.CheckState); 
            }
            else { 
                ColorData colors = PaintPopupRender(e.Graphics).Calculate(); 
                LayoutData layout = PaintPopupLayout(e, true).Layout();
 
                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout); 

                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true, colors); 
                DrawPopupBorder(g, layout.checkBounds, colors); 
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight, true);
 
                e.Graphics.Clip = original;
                e.Graphics.ExcludeClip(layout.checkArea);

                PaintField(e, layout, colors, colors.windowText, true); 
            }
        } 
 
        internal override void PaintDown(PaintEventArgs e, CheckState state) {
            if (Control.Appearance == Appearance.Button) { 
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintDown(e, Control.CheckState);
            }
            else { 
                System.Drawing.Graphics g = e.Graphics;
                ColorData colors = PaintPopupRender(e.Graphics).Calculate(); 
                LayoutData layout = PaintPopupLayout(e, true).Layout(); 

                Region original = e.Graphics.Clip; 
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);
 
                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.buttonFace, true, colors);
                DrawPopupBorder(g, layout.checkBounds, colors); 
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.buttonFace, true); 

                PaintField(e, layout, colors, colors.windowText, true); 
            }
        }

        #region Layout 

        protected override ButtonBaseAdapter CreateButtonAdapter() { 
            return new ButtonPopupAdapter(Control); 
        }
 
        protected override LayoutOptions Layout(PaintEventArgs e) {
            LayoutOptions layout = PaintPopupLayout(e, /* up = */ true);
            Debug.Assert(layout.GetPreferredSizeCore(LayoutUtils.MaxSize)
                == PaintPopupLayout(e, /* up = */ false).GetPreferredSizeCore(LayoutUtils.MaxSize), 
                "The state of show3D should not effect PreferredSize");
            return layout; 
        } 

 
        [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")]  // removed graphics, may have to put it back
        internal static LayoutOptions PaintPopupLayout(Graphics g, bool show3D, int checkSize, Rectangle clientRectangle, Padding padding,
                                                       bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl)
        { 
            LayoutOptions layout = CommonLayout(clientRectangle, padding, isDefault, font, text, enabled, textAlign, rtl);
            layout.shadowedText = false; 
            if (show3D) { 
                layout.checkSize = checkSize + 1;
            } 
            else {
                layout.checkSize = checkSize;
                layout.checkPaddingSize = 1;
            } 
            return layout;
        } 
 
        [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")]  // removed graphics, may have to put it back
        private LayoutOptions PaintPopupLayout(PaintEventArgs e, bool show3D) { 
            LayoutOptions layout = CommonLayout();
            layout.shadowedText = false;
            if (show3D) {
                layout.checkSize = flatCheckSize + 1; 
            }
            else { 
                layout.checkSize = flatCheckSize; 
                layout.checkPaddingSize = 1;
            } 
            return layout;
        }

        #endregion 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//----------------------------------------------------------------------------- 

namespace System.Windows.Forms.ButtonInternal { 
    using System; 
    using System.Diagnostics;
    using System.Drawing; 
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Drawing.Text;
    using System.Windows.Forms; 
    using System.Windows.Forms.Layout;
    using System.Diagnostics.CodeAnalysis; 
 

    internal class CheckBoxPopupAdapter : CheckBoxBaseAdapter { 

        internal CheckBoxPopupAdapter(ButtonBase control) : base(control) {}

        internal override void PaintUp(PaintEventArgs e, CheckState state) { 
            if (Control.Appearance == Appearance.Button) {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control); 
                adapter.PaintUp(e, Control.CheckState); 
            }
            else { 
                System.Drawing.Graphics g = e.Graphics;
                ColorData colors = PaintPopupRender(e.Graphics).Calculate();
                LayoutData layout = PaintPopupLayout(e, false).Layout();
 
                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null); 
 
                PaintImage(e, layout);
 
                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true, colors);
                DrawFlatBorder(e.Graphics, layout.checkBounds, colors.buttonShadow);
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight, true);
 
                PaintField(e, layout, colors, colors.windowText, true);
            } 
        } 

        internal override void PaintOver(PaintEventArgs e, CheckState state) { 
            System.Drawing.Graphics g = e.Graphics;
            if (Control.Appearance == Appearance.Button) {
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintOver(e, Control.CheckState); 
            }
            else { 
                ColorData colors = PaintPopupRender(e.Graphics).Calculate(); 
                LayoutData layout = PaintPopupLayout(e, true).Layout();
 
                Region original = e.Graphics.Clip;
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout); 

                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true, colors); 
                DrawPopupBorder(g, layout.checkBounds, colors); 
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.highlight, true);
 
                e.Graphics.Clip = original;
                e.Graphics.ExcludeClip(layout.checkArea);

                PaintField(e, layout, colors, colors.windowText, true); 
            }
        } 
 
        internal override void PaintDown(PaintEventArgs e, CheckState state) {
            if (Control.Appearance == Appearance.Button) { 
                ButtonPopupAdapter adapter = new ButtonPopupAdapter(Control);
                adapter.PaintDown(e, Control.CheckState);
            }
            else { 
                System.Drawing.Graphics g = e.Graphics;
                ColorData colors = PaintPopupRender(e.Graphics).Calculate(); 
                LayoutData layout = PaintPopupLayout(e, true).Layout(); 

                Region original = e.Graphics.Clip; 
                PaintButtonBackground(e, Control.ClientRectangle, null);

                PaintImage(e, layout);
 
                DrawCheckBackground(e, layout.checkBounds, colors.windowText, colors.buttonFace, true, colors);
                DrawPopupBorder(g, layout.checkBounds, colors); 
                DrawCheckOnly(e, layout, colors, colors.windowText, colors.buttonFace, true); 

                PaintField(e, layout, colors, colors.windowText, true); 
            }
        }

        #region Layout 

        protected override ButtonBaseAdapter CreateButtonAdapter() { 
            return new ButtonPopupAdapter(Control); 
        }
 
        protected override LayoutOptions Layout(PaintEventArgs e) {
            LayoutOptions layout = PaintPopupLayout(e, /* up = */ true);
            Debug.Assert(layout.GetPreferredSizeCore(LayoutUtils.MaxSize)
                == PaintPopupLayout(e, /* up = */ false).GetPreferredSizeCore(LayoutUtils.MaxSize), 
                "The state of show3D should not effect PreferredSize");
            return layout; 
        } 

 
        [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")]  // removed graphics, may have to put it back
        internal static LayoutOptions PaintPopupLayout(Graphics g, bool show3D, int checkSize, Rectangle clientRectangle, Padding padding,
                                                       bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl)
        { 
            LayoutOptions layout = CommonLayout(clientRectangle, padding, isDefault, font, text, enabled, textAlign, rtl);
            layout.shadowedText = false; 
            if (show3D) { 
                layout.checkSize = checkSize + 1;
            } 
            else {
                layout.checkSize = checkSize;
                layout.checkPaddingSize = 1;
            } 
            return layout;
        } 
 
        [SuppressMessage("Microsoft.Performance", "CA1801:AvoidUnusedParameters")]  // removed graphics, may have to put it back
        private LayoutOptions PaintPopupLayout(PaintEventArgs e, bool show3D) { 
            LayoutOptions layout = CommonLayout();
            layout.shadowedText = false;
            if (show3D) {
                layout.checkSize = flatCheckSize + 1; 
            }
            else { 
                layout.checkSize = flatCheckSize; 
                layout.checkPaddingSize = 1;
            } 
            return layout;
        }

        #endregion 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK