Пример #1
0
        private static Control _ParentContains(Control control, PointF mousePosition, Control currentControl, ref bool ok)
        {
            //Application.Log(control.Name);
            if (control == null || control.Parent == null)
            {
                return(currentControl);
            }

            var parentLocation = control.Parent.PointToScreen(global::UWinForms.System.Drawing.Point.Empty);
            var parentRect     = new global::UWinForms.System.Drawing.RectangleF(parentLocation.X, parentLocation.Y, control.Parent.Width, control.Parent.Height);

            if (parentRect.Contains(mousePosition) == true)
            {
                currentControl = control.Parent;
            }
            else
            {
                ok = false; // Control is not visible due to groups;
            }
            return(_ParentContains(control.Parent, mousePosition, currentControl, ref ok));
        }
Пример #2
0
        private static bool _ProcessControl(PointF mousePosition, Control control, bool ignore_rect)
        {
            // ignore_rect will call mouse_up & mouse_move in any case.
            var c_location = control.PointToScreen(global::UWinForms.System.Drawing.Point.Empty);
            var clientRect = new global::UWinForms.System.Drawing.RectangleF(c_location.X, c_location.Y, control.Width, control.Height);
            var contains   = clientRect.Contains(mousePosition);

            if (contains && (mouseEvent == MouseEvents.Down) || mouseEvent == MouseEvents.Up)
            {
                if (control.Parent != null)
                {
                    bool ok             = true;
                    var  clickedControl = _ParentContains(control, mousePosition, control, ref ok);
                    if (clickedControl != null && ok == false)
                    {
                        control = clickedControl;
                    }
                }
            }

            if (ignore_rect || contains)
            {
                var client_mpos = control.PointToClient(new Point((int)mousePosition.X, (int)mousePosition.Y));
                if (mousePositionChanged)
                {
                    if (dragData != null)
                    {
                        dragndrop = true;
                    }
                }

                if (!contains && mouseEvent != MouseEvents.Up)
                {
                    return(true);
                }
                switch (mouseEvent)
                {
                case MouseEvents.Down:
                    var md_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseDown(md_args);
                    mouseLastClickControl = control;
                    return(true);

                case MouseEvents.Up:
                    if (dragndrop)
                    {
                        if (control.AllowDrop)
                        {
                            DataObject    dnd_data = new DataObject(dragData);
                            DragEventArgs dnd_args = new DragEventArgs(dnd_data, 0, (int)client_mpos.X, (int)client_mpos.Y, DragDropEffects.None, dragControlEffects);
                            control.RaiseOnDragDrop(dnd_args);
                        }
                        dragData  = null;
                        dragndrop = false;
                        return(true);
                    }
                    var mu_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseUp(mu_args);
                    if (mouseLastClickControl == control)
                    {
                        control.RaiseOnMouseClick(mu_args);
                    }
                    if (mouseLastClickControl != null && control != mouseLastClickControl)
                    {
                        mouseLastClickControl.RaiseOnMouseUp(mu_args);
                    }
                    return(true);

                case MouseEvents.DoubleClick:
                    var mdc_args = new MouseEventArgs(mouseButton, 2, (int)client_mpos.X, (int)client_mpos.Y, 0);
                    control.RaiseOnMouseDoubleClick(mdc_args);
                    return(true);

                case MouseEvents.Wheel:
                    var mw_args = new MouseEventArgs(MouseButtons.Middle, 0, (int)client_mpos.X, (int)client_mpos.Y, (int)(-mouseWheelDelta * 4));
                    control.RaiseOnMouseWheel(mw_args);
                    return(true);
                }
            }
            if (!contains)
            {
                control.RaiseOnMouseLeave(null);
            }
            return(false);
        }