⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xtabcontrol.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 4 页
字号:
namespace Imps.Client.Pc.XControls
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Globalization;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    [Designer(typeof(XTabContorlDesigner))]
    public class XTabControl : Control
    {
        private bool _actionInAnimation;
        private TabAlignment _alignment;
        private volatile bool _animating;
        private Color _borderColor;
        private int _borderWidth;
        private ScrollDirection _currentDirection;
        private volatile int _distancePerTick;
        protected IXTabDrawer _drawer;
        private bool _enableToolTip;
        private bool _hideTabWhenOneTab;
        private System.Windows.Forms.ImageList _hoverImageList;
        private int _hoverIndex;
        private Color _hoverTabBackColor;
        private System.Windows.Forms.ImageList _imageList;
        private bool _mouseInRectA;
        private bool _mouseInRectB;
        private Queue<ScrollDirection> _scrollActions;
        private Rectangle _scrollARect;
        private Rectangle _scrollBRect;
        private Image _scrollImageButton;
        private int _selectedIndex;
        private Color _selectedTabBackColor;
        private Imps.Client.Pc.XControls.ShowScrollMode _showScrollMode;
        private static XTabContorlStyle _style;
        private object _syncRoot;
        private XTabPageCollection _tabCollection;
        private int _tabHeight;
        private int _tabWidth;
        private bool _themeEnabled;
        private volatile int _tickCounter;
        private Imps.Client.Pc.XControls.XTabStyle _xTabStyle;
        private Timer AnimationTimer;
        private IContainer components;
        private int tabPageCount;
        private XTabPage[] tabPages;
        private ToolTip TabTip;

        public event EventHandler<Imps.Client.Pc.XControls.ScrollEventArgs> OnScroll;

        public event EventHandler SelectedIndexChanged;

        public XTabControl() : this(string.Empty)
        {
        }

        public XTabControl(string text) : this(null, text)
        {
        }

        public XTabControl(Control parent, string text) : this(parent, text, 0, 0, 100, 100)
        {
        }

        public XTabControl(string text, int left, int top, int width, int height) : this(null, text, left, top, width, height)
        {
        }

        public XTabControl(Control parent, string text, int left, int top, int width, int height) : base(parent, text, left, top, width, height)
        {
            this._alignment = TabAlignment.Left;
            this._tabWidth = 0x20;
            this._tabHeight = 0x2d;
            this._showScrollMode = Imps.Client.Pc.XControls.ShowScrollMode.Auto;
            this._scrollARect = Rectangle.Empty;
            this._scrollBRect = Rectangle.Empty;
            this._selectedIndex = -1;
            this._hoverIndex = -1;
            this._distancePerTick = 8;
            this._hoverTabBackColor = Color.Transparent;
            this._selectedTabBackColor = Color.White;
            this._borderColor = Color.Black;
            this._borderWidth = 1;
            this._themeEnabled = true;
            this._syncRoot = new object();
            this._enableToolTip = true;
            this._xTabStyle = Imps.Client.Pc.XControls.XTabStyle.Msn;
            this._tabCollection = new XTabPageCollection(this);
            base.SetStyle(0x22812, true);
            this.InitializeComponent();
            this.InitEventHandlers();
        }

        private void AnimationTimer_Tick(object sender, EventArgs e)
        {
            int tickCounter;
            if (this.ScrollActions.get_Count() <= 0)
            {
                this.DistancePerTick = 8;
                this.AnimationTimer.Enabled = false;
                base.Invalidate(this.AnimateRectangle);
                this.Animating = false;
                return;
            }
            lock (this.SyncRoot)
            {
                this.CurrentDirection = this.ScrollActions.Peek();
            }
            this.TickCounter = (tickCounter = this.TickCounter) + 1;
            if (tickCounter <= (this.TabHeight / this.DistancePerTick))
            {
                switch (this.CurrentDirection)
                {
                    case ScrollDirection.Up:
                    case ScrollDirection.Left:
                        this.ScrollUp();
                        goto Label_00D6;

                    case ScrollDirection.Down:
                    case ScrollDirection.Right:
                        goto Label_00D6;
                }
            }
            else
            {
                lock (this.SyncRoot)
                {
                    this.ScrollActions.Dequeue();
                }
                switch (this.CurrentDirection)
                {
                    case ScrollDirection.Down:
                    case ScrollDirection.Right:
                        this.ScrollDown();
                        break;
                }
                this.TickCounter = 0;
                this._actionInAnimation = false;
            }
        Label_00D6:
            this.DistancePerTick++;
            base.Invalidate(this.TabRectangle);
        }

        protected override Control.ControlCollection CreateControlsInstance()
        {
            return new ControlCollection(this);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this._imageList != null))
            {
                this._imageList.Dispose();
                if (this._hoverImageList != null)
                {
                    this._hoverImageList.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        internal int FindTabPage(XTabPage tabPage)
        {
            if (this.tabPages != null)
            {
                for (int i = 0; i < this.tabPageCount; i++)
                {
                    if (this.tabPages[i].Equals(tabPage))
                    {
                        return i;
                    }
                }
            }
            return -1;
        }

        private IXTabDrawer GetDrawer(Imps.Client.Pc.XControls.XTabStyle style)
        {
            switch (style)
            {
                case Imps.Client.Pc.XControls.XTabStyle.Default:
                    return new DefaultDrawer();

                case Imps.Client.Pc.XControls.XTabStyle.Msn:
                    return new MsnStyleDrawer();
            }
            return null;
        }

        private Image GetImageFromImageList(System.Windows.Forms.ImageList list, int index, string key)
        {
            Image image = null;
            if (list != null)
            {
                if ((index >= 0) && (index < list.Images.Count))
                {
                    image = list.Images[index];
                }
                if (image == null)
                {
                    image = list.Images.get_Item(key);
                }
            }
            return image;
        }

        protected virtual object[] GetItems()
        {
            TabPage[] destinationArray = new TabPage[this.tabPageCount];
            if (this.tabPageCount > 0)
            {
                Array.Copy(this.tabPages, 0, destinationArray, 0, this.tabPageCount);
            }
            return destinationArray;
        }

        public XTabPage GetTabByPoint(Point p)
        {
            for (int i = 0; i < this.TabCount; i++)
            {
                XTabPage page2 = this.TabPages[i];
                if ((page2 != null) && page2.TabRectangle.Contains(p))
                {
                    return page2;
                }
            }
            return null;
        }

        public Image GetTabImage(XTabPage page)
        {
            Image image = null;
            int index = this.TabPages.IndexOf(page);
            System.Windows.Forms.ImageList hoverImageList = null;
            if (this.HoverIndex == index)
            {
                hoverImageList = this.HoverImageList;
            }
            else
            {
                hoverImageList = this.ImageList;
            }
            image = this.GetImageFromImageList(hoverImageList, page.ImageIndex, page.ImageKey);
            if (image == null)
            {
                image = page.Image;
            }
            return image;
        }

        internal XTabPage GetTabPage(int index)
        {
            if ((index < 0) || (index >= this.tabPageCount))
            {
                return null;
            }
            if (this.tabPages == null)
            {
                return null;
            }
            return this.tabPages[index];
        }

        internal TabPage[] GetTabPages()
        {
            return (TabPage[]) this.GetItems();
        }

        private void InitEventHandlers()
        {
            this.OnScroll = (EventHandler<Imps.Client.Pc.XControls.ScrollEventArgs>) Delegate.Combine(this.OnScroll, new EventHandler<Imps.Client.Pc.XControls.ScrollEventArgs>(this, (IntPtr) this.XTab_OnScroll));
            this.SelectedIndexChanged = (EventHandler) Delegate.Combine(this.SelectedIndexChanged, new EventHandler(this.XTabControl_SelectedIndexChanged));
            Style.StyleChanged += new EventHandler(this.Style_StyleChanged);
            base.Disposed += new EventHandler(this.XTabControl_Disposed);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.AnimationTimer = new Timer(this.components);
            this.TabTip = new ToolTip(this.components);
            base.SuspendLayout();
            this.AnimationTimer.Tick += new EventHandler(this.AnimationTimer_Tick);
            base.ResumeLayout(false);
        }

        internal void Insert(int index, XTabPage tabPage)
        {
            if (this.tabPages == null)
            {
                this.tabPages = new XTabPage[4];
            }
            else if (this.tabPages.Length == this.tabPageCount)
            {
                XTabPage[] destinationArray = new XTabPage[this.tabPageCount * 2];
                Array.Copy(this.tabPages, 0, destinationArray, 0, this.tabPageCount);
                this.tabPages = destinationArray;
            }
            if (index < this.tabPageCount)
            {
                Array.Copy(this.tabPages, index, this.tabPages, index + 1, this.tabPageCount - index);
            }
            this.tabPages[index] = tabPage;
            this.tabPageCount++;
            base.Invalidate();
        }

        internal bool IsScorllNeed(ScrollDirection direction)
        {
            bool flag = false;
            switch (direction)
            {
                case ScrollDirection.Up:
                case ScrollDirection.Left:
                    for (int i = 0; i < this.TabCount; i++)
                    {
                        XTabPage page = this.TabPages[i];
                        if (page == null)
                        {
                            return flag;
                        }
                        if (page.Hided)
                        {
                            flag = true;
                        }
                    }
                    return flag;

                case ScrollDirection.Down:
                case ScrollDirection.Right:
                    return true;
            }
            return flag;
        }

        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);
            XTabPage tabByPoint = this.GetTabByPoint(e.get_Location());
            if (tabByPoint != null)
            {
                int index = this.TabPages.IndexOf(tabByPoint);
                if (this.SelectedIndex != index)
                {
                    this.SelectedIndex = index;
                    base.Invalidate();
                }
            }
            else
            {
                if (this.ScrollRectA.Contains(e.X, e.Y) && (this.OnScroll != null))
                {
                    ScrollDirection up = ScrollDirection.Up;
                    if ((this.Alignment == TabAlignment.Left) || (this.Alignment == TabAlignment.Right))
                    {
                        up = ScrollDirection.Up;
                    }
                    else
                    {
                        up = ScrollDirection.Left;
                    }
                    this.OnScroll.Invoke(this, new Imps.Client.Pc.XControls.ScrollEventArgs(up));
                }
                if (this.ScrollRectB.Contains(e.X, e.Y) && (this.OnScroll != null))
                {
                    ScrollDirection direction = ScrollDirection.Up;
                    if ((this.Alignment == TabAlignment.Left) || (this.Alignment == TabAlignment.Right))
                    {
                        direction = ScrollDirection.Down;
                    }
                    else
                    {
                        direction = ScrollDirection.Right;
                    }
                    this.OnScroll.Invoke(this, new Imps.Client.Pc.XControls.ScrollEventArgs(direction));
                }
            }
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            this.MouseInRectA = false;
            this.MouseInRectB = false;
            if (this.HoverIndex > 0)
            {
                Rectangle rc = Rectangle.Empty;
                XTabPage page = this.TabPages[this.HoverIndex];
                if (page != null)
                {
                    rc = page.TabRectangle;
                }
                this.HoverIndex = -1;
                if (rc != Rectangle.Empty)
                {
                    base.Invalidate(rc);
                }
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            XTabPage tabByPoint = this.GetTabByPoint(e.get_Location());
            if (tabByPoint != null)
            {
                int index = this.TabPages.IndexOf(tabByPoint);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -