protected virtual void WndProc(ref Message m)
        {
            IMouseHandler handler = null;
            if ((m.Msg == 0x84) && !this.inHitTest)
            {
                this.inHitTest = true;
                Point point = new Point((short) System.Design.NativeMethods.Util.LOWORD((int) ((long) m.LParam)), (short) System.Design.NativeMethods.Util.HIWORD((int) ((long) m.LParam)));
                try
                {
                    this.liveRegion = this.GetHitTest(point);
                }
                catch (Exception exception)
                {
                    this.liveRegion = false;
                    if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
                    {
                        throw;
                    }
                }
                this.inHitTest = false;
            }
            bool flag = m.Msg == 0x7b;
            if (this.liveRegion && (this.IsMouseMessage(m.Msg) || flag))
            {
                if (m.Msg == 0x7b)
                {
                    inContextMenu = true;
                }
                try
                {
                    this.DefWndProc(ref m);
                }
                finally
                {
                    if (m.Msg == 0x7b)
                    {
                        inContextMenu = false;
                    }
                    if (m.Msg == 0x202)
                    {
                        this.OnMouseDragEnd(true);
                    }
                }
                return;
            }
            int x = 0;
            int y = 0;
            if ((((m.Msg >= 0x200) && (m.Msg <= 0x20a)) || ((m.Msg >= 160) && (m.Msg <= 0xa9))) || (m.Msg == 0x20))
            {
                if (this.eventSvc == null)
                {
                    this.eventSvc = (IEventHandlerService) this.GetService(typeof(IEventHandlerService));
                }
                if (this.eventSvc != null)
                {
                    handler = (IMouseHandler) this.eventSvc.GetHandler(typeof(IMouseHandler));
                }
            }
            if ((m.Msg >= 0x200) && (m.Msg <= 0x20a))
            {
                System.Design.NativeMethods.POINT pt = new System.Design.NativeMethods.POINT {
                    x = System.Design.NativeMethods.Util.SignedLOWORD((int) ((long) m.LParam)),
                    y = System.Design.NativeMethods.Util.SignedHIWORD((int) ((long) m.LParam))
                };
                System.Design.NativeMethods.MapWindowPoints(m.HWnd, IntPtr.Zero, pt, 1);
                x = pt.x;
                y = pt.y;
            }
            else if ((m.Msg >= 160) && (m.Msg <= 0xa9))
            {
                x = System.Design.NativeMethods.Util.SignedLOWORD((int) ((long) m.LParam));
                y = System.Design.NativeMethods.Util.SignedHIWORD((int) ((long) m.LParam));
            }
            MouseButtons none = MouseButtons.None;
            switch (m.Msg)
            {
                case 0x1f:
                    this.OnMouseDragEnd(true);
                    this.DefWndProc(ref m);
                    return;

                case 0x20:
                    goto Label_0A82;

                case 0x3d:
                    if (-4 == ((int) ((long) m.LParam)))
                    {
                        Guid refiid = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
                        try
                        {
                            IAccessible accessibilityObject = this.AccessibilityObject;
                            if (accessibilityObject == null)
                            {
                                m.Result = IntPtr.Zero;
                            }
                            else
                            {
                                IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(accessibilityObject);
                                try
                                {
                                    m.Result = System.Design.UnsafeNativeMethods.LresultFromObject(ref refiid, m.WParam, iUnknownForObject);
                                }
                                finally
                                {
                                    Marshal.Release(iUnknownForObject);
                                }
                            }
                            return;
                        }
                        catch (Exception exception2)
                        {
                            throw exception2;
                        }
                    }
                    this.DefWndProc(ref m);
                    return;

                case 15:
                    if (OleDragDropHandler.FreezePainting)
                    {
                        System.Design.NativeMethods.ValidateRect(m.HWnd, IntPtr.Zero);
                        return;
                    }
                    if (this.Control != null)
                    {
                        System.Design.NativeMethods.RECT rc = new System.Design.NativeMethods.RECT();
                        IntPtr hrgn = System.Design.NativeMethods.CreateRectRgn(0, 0, 0, 0);
                        System.Design.NativeMethods.GetUpdateRgn(m.HWnd, hrgn, false);
                        System.Design.NativeMethods.GetUpdateRect(m.HWnd, ref rc, false);
                        Region region = Region.FromHrgn(hrgn);
                        Rectangle empty = Rectangle.Empty;
                        try
                        {
                            if (this.thrownException == null)
                            {
                                this.DefWndProc(ref m);
                            }
                            using (Graphics graphics2 = Graphics.FromHwnd(m.HWnd))
                            {
                                if (m.HWnd != this.Control.Handle)
                                {
                                    System.Design.NativeMethods.POINT point3 = new System.Design.NativeMethods.POINT {
                                        x = 0,
                                        y = 0
                                    };
                                    System.Design.NativeMethods.MapWindowPoints(m.HWnd, this.Control.Handle, point3, 1);
                                    graphics2.TranslateTransform((float) -point3.x, (float) -point3.y);
                                    System.Design.NativeMethods.MapWindowPoints(m.HWnd, this.Control.Handle, ref rc, 2);
                                }
                                empty = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
                                using (PaintEventArgs args2 = new PaintEventArgs(graphics2, empty))
                                {
                                    graphics2.Clip = region;
                                    if (this.thrownException == null)
                                    {
                                        this.OnPaintAdornments(args2);
                                    }
                                    else
                                    {
                                        System.Design.UnsafeNativeMethods.PAINTSTRUCT lpPaint = new System.Design.UnsafeNativeMethods.PAINTSTRUCT();
                                        System.Design.UnsafeNativeMethods.BeginPaint(m.HWnd, ref lpPaint);
                                        this.PaintException(args2, this.thrownException);
                                        System.Design.UnsafeNativeMethods.EndPaint(m.HWnd, ref lpPaint);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            region.Dispose();
                            System.Design.NativeMethods.DeleteObject(hrgn);
                        }
                        if (this.OverlayService == null)
                        {
                            return;
                        }
                        empty.Location = this.Control.PointToScreen(empty.Location);
                        this.OverlayService.InvalidateOverlays(empty);
                    }
                    return;

                case 5:
                    if (this.thrownException != null)
                    {
                        this.Control.Invalidate();
                    }
                    this.DefWndProc(ref m);
                    return;

                case 7:
                    if ((this.host != null) && (this.host.RootComponent != null))
                    {
                        IRootDesigner designer = this.host.GetDesigner(this.host.RootComponent) as IRootDesigner;
                        if (designer == null)
                        {
                            return;
                        }
                        ViewTechnology[] supportedTechnologies = designer.SupportedTechnologies;
                        if (supportedTechnologies.Length <= 0)
                        {
                            return;
                        }
                        System.Windows.Forms.Control view = designer.GetView(supportedTechnologies[0]) as System.Windows.Forms.Control;
                        if (view == null)
                        {
                            return;
                        }
                        view.Focus();
                    }
                    return;

                case 1:
                    this.DefWndProc(ref m);
                    if (m.HWnd == this.Control.Handle)
                    {
                        this.OnCreateHandle();
                    }
                    return;

                case 0x85:
                case 0x86:
                    if (m.Msg != 0x86)
                    {
                        if (this.thrownException == null)
                        {
                            this.DefWndProc(ref m);
                        }
                        break;
                    }
                    this.DefWndProc(ref m);
                    break;

                case 0x7b:
                    if (!inContextMenu)
                    {
                        x = System.Design.NativeMethods.Util.SignedLOWORD((int) ((long) m.LParam));
                        y = System.Design.NativeMethods.Util.SignedHIWORD((int) ((long) m.LParam));
                        ToolStripKeyboardHandlingService service2 = (ToolStripKeyboardHandlingService) this.GetService(typeof(ToolStripKeyboardHandlingService));
                        bool flag2 = false;
                        if (service2 != null)
                        {
                            flag2 = service2.OnContextMenu(x, y);
                        }
                        if (flag2)
                        {
                            return;
                        }
                        if ((x == -1) && (y == -1))
                        {
                            Point position = Cursor.Position;
                            x = position.X;
                            y = position.Y;
                        }
                        this.OnContextMenu(x, y);
                    }
                    return;

                case 160:
                case 0x200:
                    if ((((int) ((long) m.WParam)) & 1) != 0)
                    {
                        none = MouseButtons.Left;
                    }
                    else if ((((int) ((long) m.WParam)) & 2) != 0)
                    {
                        none = MouseButtons.Right;
                        this.toolPassThrough = false;
                    }
                    else
                    {
                        this.toolPassThrough = false;
                    }
                    if ((this.lastMoveScreenX != x) || (this.lastMoveScreenY != y))
                    {
                        if (this.toolPassThrough)
                        {
                            System.Design.NativeMethods.SendMessage(this.Control.Parent.Handle, m.Msg, m.WParam, (IntPtr) this.GetParentPointFromLparam(m.LParam));
                            return;
                        }
                        if (handler != null)
                        {
                            handler.OnMouseMove(base.Component, x, y);
                        }
                        else if (none == MouseButtons.Left)
                        {
                            this.OnMouseDragMove(x, y);
                        }
                    }
                    this.lastMoveScreenX = x;
                    this.lastMoveScreenY = y;
                    if (m.Msg == 0x200)
                    {
                        this.BaseWndProc(ref m);
                    }
                    return;

                case 0xa1:
                case 0xa4:
                case 0x201:
                case 0x204:
                    if ((m.Msg == 0xa4) || (m.Msg == 0x204))
                    {
                        none = MouseButtons.Right;
                    }
                    else
                    {
                        none = MouseButtons.Left;
                    }
                    System.Design.NativeMethods.SendMessage(this.Control.Handle, 7, 0, 0);
                    if ((none == MouseButtons.Left) && this.IsDoubleClick(x, y))
                    {
                        if (handler != null)
                        {
                            handler.OnMouseDoubleClick(base.Component);
                            return;
                        }
                        this.OnMouseDoubleClick();
                        return;
                    }
                    this.toolPassThrough = false;
                    if (!this.EnableDragRect && (none == MouseButtons.Left))
                    {
                        if (this.toolboxSvc == null)
                        {
                            this.toolboxSvc = (IToolboxService) this.GetService(typeof(IToolboxService));
                        }
                        if ((this.toolboxSvc != null) && (this.toolboxSvc.GetSelectedToolboxItem((IDesignerHost) this.GetService(typeof(IDesignerHost))) != null))
                        {
                            this.toolPassThrough = true;
                        }
                    }
                    else
                    {
                        this.toolPassThrough = false;
                    }
                    if (this.toolPassThrough)
                    {
                        System.Design.NativeMethods.SendMessage(this.Control.Parent.Handle, m.Msg, m.WParam, (IntPtr) this.GetParentPointFromLparam(m.LParam));
                        return;
                    }
                    if (handler != null)
                    {
                        handler.OnMouseDown(base.Component, none, x, y);
                    }
                    else if (none == MouseButtons.Left)
                    {
                        this.OnMouseDragBegin(x, y);
                    }
                    else if (none == MouseButtons.Right)
                    {
                        ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
                        if (service != null)
                        {
                            service.SetSelectedComponents(new object[] { base.Component }, SelectionTypes.Click);
                        }
                    }
                    this.lastMoveScreenX = x;
                    this.lastMoveScreenY = y;
                    return;

                case 0xa2:
                case 0xa5:
                case 0x202:
                case 0x205:
                    if ((m.Msg == 0xa5) || (m.Msg == 0x205))
                    {
                        none = MouseButtons.Right;
                    }
                    else
                    {
                        none = MouseButtons.Left;
                    }
                    if (handler != null)
                    {
                        handler.OnMouseUp(base.Component, none);
                    }
                    else
                    {
                        if (this.toolPassThrough)
                        {
                            System.Design.NativeMethods.SendMessage(this.Control.Parent.Handle, m.Msg, m.WParam, (IntPtr) this.GetParentPointFromLparam(m.LParam));
                            this.toolPassThrough = false;
                            return;
                        }
                        if (none == MouseButtons.Left)
                        {
                            this.OnMouseDragEnd(false);
                        }
                    }
                    this.toolPassThrough = false;
                    this.BaseWndProc(ref m);
                    return;

                case 0xa3:
                case 0xa6:
                case 0x203:
                case 0x206:
                    if ((m.Msg == 0xa6) || (m.Msg == 0x206))
                    {
                        none = MouseButtons.Right;
                    }
                    else
                    {
                        none = MouseButtons.Left;
                    }
                    if (none == MouseButtons.Left)
                    {
                        if (handler != null)
                        {
                            handler.OnMouseDoubleClick(base.Component);
                            return;
                        }
                        this.OnMouseDoubleClick();
                    }
                    return;

                case 0xa7:
                case 0xa8:
                case 0xa9:
                case 0x207:
                case 520:
                case 0x209:
                case 0x20a:
                case 0x2a0:
                case 0x2a2:
                    return;

                case 0x2a1:
                    if (handler == null)
                    {
                        this.OnMouseHover();
                        return;
                    }
                    handler.OnMouseHover(base.Component);
                    return;

                case 0x2a3:
                    this.OnMouseLeave();
                    this.BaseWndProc(ref m);
                    return;

                case 0x318:
                {
                    using (Graphics graphics = Graphics.FromHdc(m.WParam))
                    {
                        using (PaintEventArgs args = new PaintEventArgs(graphics, this.Control.ClientRectangle))
                        {
                            this.DefWndProc(ref m);
                            this.OnPaintAdornments(args);
                        }
                        return;
                    }
                }
                default:
                    if (m.Msg == System.Design.NativeMethods.WM_MOUSEENTER)
                    {
                        this.OnMouseEnter();
                        this.BaseWndProc(ref m);
                    }
                    else if ((m.Msg < 0x100) || (m.Msg > 0x108))
                    {
                        this.DefWndProc(ref m);
                    }
                    return;
            }
            if (((this.OverlayService == null) || (this.Control == null)) || (!(this.Control.Size != this.Control.ClientSize) || (this.Control.Parent == null)))
            {
                return;
            }
            Rectangle rectangle2 = new Rectangle(this.Control.Parent.PointToScreen(this.Control.Location), this.Control.Size);
            Rectangle rectangle3 = new Rectangle(this.Control.PointToScreen(Point.Empty), this.Control.ClientSize);
            using (Region region2 = new Region(rectangle2))
            {
                region2.Exclude(rectangle3);
                this.OverlayService.InvalidateOverlays(region2);
                return;
            }
            Label_0A82:
            if (this.liveRegion)
            {
                this.DefWndProc(ref m);
            }
            else if (handler != null)
            {
                handler.OnSetCursor(base.Component);
            }
            else
            {
                this.OnSetCursor();
            }
        }
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == BehaviorService.WM_GETALLSNAPLINES)
     {
         this.behaviorService.TestHook_GetAllSnapLines(ref m);
     }
     else if (m.Msg == BehaviorService.WM_GETRECENTSNAPLINES)
     {
         this.behaviorService.TestHook_GetRecentSnapLines(ref m);
     }
     int msg = m.Msg;
     if (msg != 15)
     {
         if (msg != 0x84)
         {
             if (msg == 0x215)
             {
                 base.WndProc(ref m);
                 this.behaviorService.OnLoseCapture();
                 return;
             }
             base.WndProc(ref m);
             return;
         }
     }
     else
     {
         IntPtr hrgn = System.Design.NativeMethods.CreateRectRgn(0, 0, 0, 0);
         System.Design.NativeMethods.GetUpdateRgn(m.HWnd, hrgn, true);
         System.Design.NativeMethods.RECT rc = new System.Design.NativeMethods.RECT();
         System.Design.NativeMethods.GetUpdateRect(m.HWnd, ref rc, true);
         Rectangle clipRect = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);
         try
         {
             using (Region region = Region.FromHrgn(hrgn))
             {
                 this.DefWndProc(ref m);
                 using (Graphics graphics = Graphics.FromHwnd(m.HWnd))
                 {
                     using (PaintEventArgs args = new PaintEventArgs(graphics, clipRect))
                     {
                         graphics.Clip = region;
                         this.behaviorService.PropagatePaint(args);
                     }
                     return;
                 }
             }
         }
         finally
         {
             System.Design.NativeMethods.DeleteObject(hrgn);
         }
     }
     Point pt = new Point((short) System.Design.NativeMethods.Util.LOWORD((int) ((long) m.LParam)), (short) System.Design.NativeMethods.Util.HIWORD((int) ((long) m.LParam)));
     System.Design.NativeMethods.POINT point2 = new System.Design.NativeMethods.POINT {
         x = 0,
         y = 0
     };
     System.Design.NativeMethods.MapWindowPoints(IntPtr.Zero, base.Handle, point2, 1);
     pt.Offset(point2.x, point2.y);
     if (this.behaviorService.PropagateHitTest(pt) && !this.ProcessingDrag)
     {
         m.Result = (IntPtr) (-1);
     }
     else
     {
         m.Result = (IntPtr) 1;
     }
 }
 protected override void OnMouseDragBegin(int x, int y)
 {
     Control control = this.Control;
     if (!this.InheritanceAttribute.Equals(InheritanceAttribute.InheritedReadOnly))
     {
         if (this.toolboxService == null)
         {
             this.toolboxService = (IToolboxService) this.GetService(typeof(IToolboxService));
         }
         if (this.toolboxService != null)
         {
             this.mouseDragTool = this.toolboxService.GetSelectedToolboxItem((IDesignerHost) this.GetService(typeof(IDesignerHost)));
         }
     }
     control.Capture = true;
     System.Design.NativeMethods.RECT rect = new System.Design.NativeMethods.RECT();
     System.Design.NativeMethods.GetWindowRect(control.Handle, ref rect);
     Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
     this.mouseDragFrame = (this.mouseDragTool == null) ? FrameStyle.Dashed : FrameStyle.Thick;
     this.mouseDragBase = new Point(x, y);
     ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService));
     if (service != null)
     {
         service.SetSelectedComponents(new object[] { base.Component }, SelectionTypes.Click);
     }
     IEventHandlerService service2 = (IEventHandlerService) this.GetService(typeof(IEventHandlerService));
     if ((service2 != null) && (this.escapeHandler == null))
     {
         this.escapeHandler = new EscapeHandler(this);
         service2.PushHandler(this.escapeHandler);
     }
     this.adornerWindowToScreenOffset = base.BehaviorService.AdornerWindowToScreen();
 }
Esempio n. 4
0
 public static extern int DrawText(HandleRef hDC, string lpszString, int nCount, ref System.Design.NativeMethods.RECT lpRect, int nFormat);