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

📄 chatrichtextbox.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
namespace Imps.Client.Pc.BizControls
{
    using DynamicGifCtlLib;
    using Imps.Client.Pc;
    using Imps.Client.Utils;
    using Imps.Utils;
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class ChatRichTextBox : RichTextBox
    {
        private Color _borderColor = Color.Empty;
        private Dictionary<REOBJECT, IDynGifCtl> _IDynaCtrlLib = new Dictionary<REOBJECT, IDynGifCtl>();
        private Dictionary<int, REOBJECT> _reObjDict = new Dictionary<int, REOBJECT>();
        private const uint CFE_AUTOCOLOR = 0x40000000;
        private const uint CFE_BOLD = 1;
        private const uint CFE_ITALIC = 2;
        private const uint CFE_LINK = 0x20;
        private const uint CFE_PROTECTED = 0x10;
        private const uint CFE_STRIKEOUT = 8;
        private const uint CFE_SUBSCRIPT = 0x10000;
        private const uint CFE_SUPERSCRIPT = 0x20000;
        private const uint CFE_UNDERLINE = 4;
        private const int CFM_ALLCAPS = 0x80;
        private const int CFM_ANIMATION = 0x40000;
        private const int CFM_BACKCOLOR = 0x4000000;
        private const uint CFM_BOLD = 1;
        private const uint CFM_CHARSET = 0x8000000;
        private const uint CFM_COLOR = 0x40000000;
        private const int CFM_DISABLED = 0x2000;
        private const int CFM_EMBOSS = 0x800;
        private const uint CFM_FACE = 0x20000000;
        private const int CFM_HIDDEN = 0x100;
        private const int CFM_IMPRINT = 0x1000;
        private const uint CFM_ITALIC = 2;
        private const int CFM_KERNING = 0x100000;
        private const int CFM_LCID = 0x2000000;
        private const uint CFM_LINK = 0x20;
        private const uint CFM_OFFSET = 0x10000000;
        private const int CFM_OUTLINE = 0x200;
        private const uint CFM_PROTECTED = 0x10;
        private const int CFM_REVAUTHOR = 0x8000;
        private const int CFM_REVISED = 0x4000;
        private const int CFM_SHADOW = 0x400;
        private const uint CFM_SIZE = 0x80000000;
        private const int CFM_SMALLCAPS = 0x40;
        private const int CFM_SPACING = 0x200000;
        private const uint CFM_STRIKEOUT = 8;
        private const int CFM_STYLE = 0x80000;
        private const uint CFM_SUBSCRIPT = 0x30000;
        private const uint CFM_SUPERSCRIPT = 0x30000;
        private const uint CFM_UNDERLINE = 4;
        private const int CFM_UNDERLINETYPE = 0x800000;
        private const int CFM_WEIGHT = 0x400000;
        private const byte CFU_UNDERLINE = 1;
        private const byte CFU_UNDERLINEDASH = 5;
        private const byte CFU_UNDERLINEDASHDOT = 6;
        private const byte CFU_UNDERLINEDASHDOTDOT = 7;
        private const byte CFU_UNDERLINEDOTTED = 4;
        private const byte CFU_UNDERLINEDOUBLE = 3;
        private const byte CFU_UNDERLINEHAIRLINE = 10;
        private const byte CFU_UNDERLINENONE = 0;
        private const byte CFU_UNDERLINETHICK = 9;
        private const byte CFU_UNDERLINEWAVE = 8;
        private const byte CFU_UNDERLINEWORD = 2;
        private const int EM_GETCHARFORMAT = 0x43a;
        public const int EM_GETOLEINTERFACE = 0x43c;
        public const int EM_GETTEXTRANGE = 0x44b;
        public const int EM_HIDESELECTION = 0x43f;
        public const int EM_REPLACESEL = 0xc2;
        private const int EM_SETCHARFORMAT = 0x444;
        private const int EM_SETEVENTMASK = 0x431;
        public const int EM_SETTEXTEX = 0x461;
        private const string OleObjectProgID = "AmigoOleObject.Object.1";
        private const int SCF_ALL = 4;
        private const int SCF_DEFAULT = 0;
        private const int SCF_SELECTION = 1;
        private const int SCF_WORD = 2;
        public const int ST_DEFAULT = 0;
        public const int ST_KEEPUNDO = 1;
        public const int ST_NEWCHARS = 4;
        public const int ST_SELECTION = 2;
        private const int WM_SETREDRAW = 11;
        private const int WM_USER = 0x400;

        public bool DeleteImage(int index)
        {
            REOBJECT reobject = this.GetObject(index);
            if (reobject == null)
            {
                return false;
            }
            IDynGifCtl objectForIUnknown = (IDynGifCtl) Marshal.GetObjectForIUnknown(reobject.poleobj);
            return true;
        }

        [DllImport("gdi32.dll")]
        public static extern bool DeleteObject(IntPtr hObject);
        private bool DoMouseUp(ref System.Windows.Forms.Message m)
        {
            System.Drawing.Point hitTestPoint = new System.Drawing.Point();
            hitTestPoint.X = (m.LParam.ToInt32() << 0x10) >> 0x10;
            hitTestPoint.Y = m.LParam.ToInt32() >> 0x10;
            REOBJECT oleObjectFromPosition = this.GetOleObjectFromPosition(hitTestPoint);
            if (base.SelectionType == RichTextBoxSelectionTypes.Object)
            {
                REOBJECT selectedObject = this.GetSelectedObject();
                System.Drawing.Point[] pts = new System.Drawing.Point[] { new System.Drawing.Point(selectedObject.sizel.Width / 100, selectedObject.sizel.Height / 100) };
                using (Graphics graphics = Graphics.FromHwnd(base.Handle))
                {
                    graphics.PageUnit = GraphicsUnit.Millimeter;
                    graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, pts);
                }
                Rectangle rectangle = new Rectangle(this.GetPositionFromCharIndex(base.SelectionStart), new Size(pts[0]));
                if (!rectangle.Contains(hitTestPoint) && (oleObjectFromPosition != null))
                {
                    this.SelectionLength = 0;
                    base.SelectionStart = oleObjectFromPosition.cp;
                    this.SelectionLength = 1;
                    return false;
                }
                return false;
            }
            if (base.SelectionType == RichTextBoxSelectionTypes.Empty)
            {
                if (oleObjectFromPosition != null)
                {
                    base.SelectionStart = oleObjectFromPosition.cp;
                    this.SelectionLength = 1;
                    return false;
                }
                return false;
            }
            int charIndexFromPosition = this.GetCharIndexFromPosition(hitTestPoint);
            if (((charIndexFromPosition < base.SelectionStart) || (charIndexFromPosition > (base.SelectionStart + this.SelectionLength))) && (oleObjectFromPosition != null))
            {
                this.SelectionLength = 0;
                base.SelectionStart = oleObjectFromPosition.cp;
                this.SelectionLength = 1;
                return false;
            }
            return false;
        }

        [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
        internal static extern bool GetClientRect(IntPtr hWnd, [In, Out] ref Rectangle rect);
        internal REOBJECT GetObject(int index)
        {
            RichEditOle ole = new RichEditOle(this);
            ole.IRichEditOle.GetObjectCount();
            if (this._reObjDict.ContainsKey(index))
            {
                new REOBJECT();
                REOBJECT reobject = this._reObjDict.get_Item(index);
                if (reobject.dwUser == index)
                {
                    return reobject;
                }
            }
            return null;
        }

        internal REOBJECT GetOleObject(int iPos)
        {
            RichEditOle ole = new RichEditOle(this);
            IRichEditOle iRichEditOle = ole.IRichEditOle;
            int objectCount = iRichEditOle.GetObjectCount();
            REOBJECT lpreobject = new REOBJECT();
            for (int i = 0; i < objectCount; i++)
            {
                iRichEditOle.GetObject(i, lpreobject, GETOBJECTOPTIONS.REO_GETOBJ_POLEOBJ);
                if (lpreobject.cp == iPos)
                {
                    return lpreobject;
                }
            }
            return null;
        }

        internal REOBJECT GetOleObjectByDwUser(int iDwUser)
        {
            RichEditOle ole = new RichEditOle(this);
            IRichEditOle iRichEditOle = ole.IRichEditOle;
            int objectCount = iRichEditOle.GetObjectCount();
            REOBJECT lpreobject = new REOBJECT();
            for (int i = 0; i < objectCount; i++)
            {
                iRichEditOle.GetObject(i, lpreobject, GETOBJECTOPTIONS.REO_GETOBJ_POLEOBJ);
                if (lpreobject.dwUser == iDwUser)
                {
                    return lpreobject;
                }
            }
            return null;
        }

        internal REOBJECT GetOleObjectFromPosition(System.Drawing.Point hitTestPoint)
        {
            RichEditOle ole = new RichEditOle(this);
            IRichEditOle iRichEditOle = ole.IRichEditOle;
            int objectCount = iRichEditOle.GetObjectCount();
            REOBJECT lpreobject = new REOBJECT();
            using (Graphics graphics = Graphics.FromHwnd(base.Handle))
            {
                System.Drawing.Point[] pts = new System.Drawing.Point[1];
                graphics.PageUnit = GraphicsUnit.Millimeter;
                for (int i = 0; i < objectCount; i++)
                {
                    iRichEditOle.GetObject(i, lpreobject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES);
                    pts[0] = new System.Drawing.Point(lpreobject.sizel.Width / 100, lpreobject.sizel.Height / 100);
                    graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, pts);
                    Rectangle rectangle = new Rectangle(this.GetPositionFromCharIndex(lpreobject.cp), new Size(pts[0]));
                    if (rectangle.Contains(hitTestPoint))
                    {
                        return lpreobject;
                    }
                }
            }
            return null;
        }

        internal REOBJECT GetOleObjectFromPosition(int iPos)
        {
            RichEditOle ole = new RichEditOle(this);
            IRichEditOle iRichEditOle = ole.IRichEditOle;
            REOBJECT lpreobject = new REOBJECT();
            lpreobject.cp = iPos;
            if (iRichEditOle.GetObject(-2, lpreobject, GETOBJECTOPTIONS.REO_GETOBJ_POLEOBJ) == 0)
            {
                return lpreobject;
            }
            return null;
        }

        internal List<REOBJECT> GetOleObjects()
        {
            List<REOBJECT> list = new List<REOBJECT>();
            RichEditOle ole = new RichEditOle(this);
            IRichEditOle iRichEditOle = ole.IRichEditOle;
            int objectCount = iRichEditOle.GetObjectCount();
            for (int i = 0; i < objectCount; i++)
            {
                REOBJECT lpreobject = new REOBJECT();
                iRichEditOle.GetObject(i, lpreobject, GETOBJECTOPTIONS.REO_GETOBJ_POLEOBJ);
                list.Add(lpreobject);
            }
            return list;
        }

        public System.Drawing.Point GetOleObjectTopLeft(int index)
        {
            REOBJECT reobject = new REOBJECT();
            reobject = this.GetObject(index);
            return this.GetPositionFromCharIndex(reobject.cp);
        }

        [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
        internal static extern IntPtr GetParent(IntPtr hWnd);
        private REOBJECT GetSelectedObject()
        {
            if (base.SelectionType == RichTextBoxSelectionTypes.Object)
            {
                int iPos = base.SelectionStart;
                return this.GetOleObject(iPos);
            }
            return null;
        }

        internal int GetSelectedObjectIndex()
        {
            REOBJECT selectedObject = this.GetSelectedObject();
            if (selectedObject != null)
            {
                return Convert.ToUInt16(selectedObject.dwUser);
            }
            return -1;
        }

        internal string GetSelectedText(int nStart, int nEnd)
        {
            this.HideFocusSelection(true, false);
            base.Select(nStart, nEnd);
            return this.SelectedText;
        }

⌨️ 快捷键说明

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