예제 #1
0
        void host_MouseDown(object sender, MouseEventArgs e)
        {
            if (bounds.Contains(e.X, e.Y))
            {
                // arg is relative to this control
                MouseEventArgs    arg           = new MouseEventArgs(e.Button, e.Clicks, e.X - Left, e.Y - Top, e.Delta);
                WindowlessControl eventReciever = null;

                // Event needs to go to most-nested control than contains click
                foreach (WindowlessControl c in controls)
                {
                    if (c.bounds.Contains(arg.X, arg.Y))
                    {
                        c.host_MouseDown(this, arg);
                        eventReciever = c;
                        mouseLock     = eventReciever;
                    }
                }

                // If no nested control get click, this control gets it
                if (eventReciever == null)
                {
                    OnMouseDown(arg);
                    mouseLock = this;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Finds the control at the specified location relative to this
        /// control's bounds.
        /// </summary>
        /// <param name="point"></param>
        /// <returns>The most-nested control at the specified point. If there
        /// are overlapping controls at the point, the top-most will be
        /// returned. If the point is outside this controls bounds, the return
        /// value is null.</returns>
        private WindowlessControl FindControlAt(Point point)
        {
            if (point.X < 0 || point.Y < 0 || point.X >= Width || point.Y >= Height)
            {
                return(null);
            }

            // We loop through all controls, rather than returning first hit.
            // This way, when controls overlap, we find the top-most (will be
            // later in collection).

            WindowlessControl result = this; // If no contained controls are found, we should return this.

            foreach (WindowlessControl c in controls)
            {
                if (c.bounds.Contains(point))
                {
                    Point relativePoint = point;
                    relativePoint.Offset(-c.Left, -c.Top);

                    // Recursion finds most-nested control
                    WindowlessControl containedControl = c.FindControlAt(relativePoint);
                    if (containedControl == null)
                    {
                        result = c;
                    }
                    else
                    {
                        result = containedControl;
                    }
                }
            }

            return(result);
        }
예제 #3
0
            public void Dispose()
            {
                if (source != null)
                {
                    source.ResumePaint();
                }

                source = null;
            }
예제 #4
0
        private void ClearMouseContainer()
        {
            WindowlessControl c = mouseContainer;

            mouseContainer = null;
            if (c != null)
            {
                c.OnMouseLeave();
            }
        }
예제 #5
0
        private void SwitchMouseFocus(WindowlessControl newMouseContainer)
        {
            WindowlessControl oldMouseContainer = mouseContainer;

            mouseContainer = newMouseContainer;
            if (oldMouseContainer != null)
            {
                oldMouseContainer.OnMouseLeave();
            }
            if (newMouseContainer != null)
            {
                newMouseContainer.OnMouseEnter();
            }
        }
예제 #6
0
        /// <summary>
        /// Causes the MouseLeave event to raised if necessary by removing this control as the mouse container.
        /// </summary>
        private void FreeMouse()
        {
            WindowlessControl root = Root;

            if (root.mouseContainer == this)
            {
                root.ClearMouseContainer();
            }

            foreach (WindowlessControl c in controls)
            {
                if (root.mouseContainer == c)
                {
                    root.ClearMouseContainer();
                }
            }
        }
예제 #7
0
        void host_MouseUp(object sender, MouseEventArgs e)
        {
            MouseEventArgs arg = new MouseEventArgs(e.Button, e.Clicks, e.X - Left, e.Y - Top, e.Delta);

            if (mouseLock == null)
            {
                // If there is no lock, route event normally.

                if (bounds.Contains(e.X, e.Y))
                {
                    WindowlessControl eventReciever = null;

                    // Event needs to go to most-nested control than contains mouse
                    foreach (WindowlessControl c in controls)
                    {
                        if (c.bounds.Contains(arg.X, arg.Y))
                        {
                            c.host_MouseUp(this, arg);
                            eventReciever = c;
                        }
                    }

                    // If no nested control get click, this control gets it
                    if (eventReciever == null)
                    {
                        OnMouseUp(arg);
                    }
                }
            }
            else if (mouseLock == this)
            {
                OnMouseUp(arg);
            }
            else
            {
                mouseLock.host_MouseUp(this, arg);
            }


            mouseLock = null;
        }
예제 #8
0
 public SuspendPaintOperation(WindowlessControl source)
 {
     this.source = source;
 }
예제 #9
0
 protected virtual void OnParentChanged(WindowlessControl oldParent)
 {
 }
예제 #10
0
        void host_MouseMove(object sender, MouseEventArgs e)
        {
            if (!visible)
            {
                return;
            }

            MouseEventArgs arg = new MouseEventArgs(e.Button, e.Clicks, e.X - Left, e.Y - Top, e.Delta);

            if (mouseLock == null)
            {
                // Root control manages mouse focus
                if (isRoot)
                {
                    WindowlessControl newMouseContainer = FindControlAt(e.Location);
                    if (newMouseContainer != mouseContainer)
                    {
                        SwitchMouseFocus(newMouseContainer);
                    }
                }

                // If there is no lock, route event normally.
                if (!bounds.Contains(e.X, e.Y))
                {
                    //LoseMouse();
                }
                else
                {
                    WindowlessControl eventReciever = null;

                    // Event needs to go to most-nested control than contains mouse
                    foreach (WindowlessControl c in controls)
                    {
                        if (!c.bounds.Contains(arg.X, arg.Y))
                        {
                            //c.LoseMouse();
                        }
                        else
                        {
                            c.host_MouseMove(this, arg);
                            eventReciever = c;
                        }
                    }

                    // If no nested control gets click, this control gets it
                    if (eventReciever == null)
                    {
                        OnMouseMove(arg);
                    }
                    //GetMouse();
                }
            }
            else if (mouseLock == this)
            {
                OnMouseMove(arg);
            }
            else
            {
                mouseLock.host_MouseMove(this, arg);
            }
        }