namespace VaioxOnline
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;
    using System.Windows.Forms;

    internal class FlatTreeView : TreeView
    {
        private Color _BaseColor = Color.FromArgb(0x2d, 0x2f, 0x31);
        private Color _LineColor = Color.FromArgb(0x19, 0x1b, 0x1d);
        private TreeNodeStates State;

        public FlatTreeView()
        {
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            this.BackColor = this._BaseColor;
            this.ForeColor = Color.White;
            base.LineColor = this._LineColor;
            base.DrawMode = TreeViewDrawMode.OwnerDrawAll;
        }

        protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            try
            {
                Rectangle rect = new Rectangle(e.Bounds.Location.X, e.Bounds.Location.Y, e.Bounds.Width, e.Bounds.Height);
                TreeNodeStates state = this.State;
                switch (state)
                {
                    case TreeNodeStates.Selected:
                        break;

                    case TreeNodeStates.Checked:
                        e.Graphics.FillRectangle(Brushes.Green, rect);
                        e.Graphics.DrawString(e.Node.Text, new Font("Segoe UI", 8f), Brushes.Black, new Rectangle(rect.X + 2, rect.Y + 2, rect.Width, rect.Height), Helpers.NearSF);
                        base.Invalidate();
                        goto Label_01FB;

                    default:
                        if (state == TreeNodeStates.Default)
                        {
                            e.Graphics.FillRectangle(Brushes.Red, rect);
                            e.Graphics.DrawString(e.Node.Text, new Font("Segoe UI", 8f), Brushes.LimeGreen, new Rectangle(rect.X + 2, rect.Y + 2, rect.Width, rect.Height), Helpers.NearSF);
                            base.Invalidate();
                        }
                        goto Label_01FB;
                }
                e.Graphics.FillRectangle(Brushes.Green, rect);
                e.Graphics.DrawString(e.Node.Text, new Font("Segoe UI", 8f), Brushes.Black, new Rectangle(rect.X + 2, rect.Y + 2, rect.Width, rect.Height), Helpers.NearSF);
                base.Invalidate();
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox(exception.Message, MsgBoxStyle.ApplicationModal, null);
                ProjectData.ClearProjectError();
            }
        Label_01FB:
            base.OnDrawNode(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Helpers.B = new Bitmap(base.Width, base.Height);
            Helpers.G = Graphics.FromImage(Helpers.B);
            Rectangle rect = new Rectangle(0, 0, base.Width, base.Height);
            Graphics g = Helpers.G;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.Clear(this.BackColor);
            g.FillRectangle(new SolidBrush(this._BaseColor), rect);
            g.DrawString(this.Text, new Font("Segoe UI", 8f), Brushes.Black, new Rectangle(base.Bounds.X + 2, base.Bounds.Y + 2, base.Bounds.Width, base.Bounds.Height), Helpers.NearSF);
            g = null;
            base.OnPaint(e);
            Helpers.G.Dispose();
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0);
            Helpers.B.Dispose();
        }
    }
}

