CheckBoxPopupAdapter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / WinForms / Managed / System / WinForms / ButtonInternal / CheckBoxPopupAdapter.cs / 1305376 / 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 = (int)(checkSize * GetDpiScaleRatio(g) + 1);
            } 
            else {
                layout.checkSize = (int)(checkSize * GetDpiScaleRatio(g));
                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 = (int)(flatCheckSize * GetDpiScaleRatio(e.Graphics) + 1); 
            }
            else { 
                layout.checkSize = (int)(flatCheckSize * GetDpiScaleRatio(e.Graphics)); 
                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 = (int)(checkSize * GetDpiScaleRatio(g) + 1);
            } 
            else {
                layout.checkSize = (int)(checkSize * GetDpiScaleRatio(g));
                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 = (int)(flatCheckSize * GetDpiScaleRatio(e.Graphics) + 1); 
            }
            else { 
                layout.checkSize = (int)(flatCheckSize * GetDpiScaleRatio(e.Graphics)); 
                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