using System.Drawing;
using System.Windows.Forms;
using FastReport.Utils;

namespace FastReport
{
    partial class ContainerObject
    {
        #region Public Methods
        /// <inheritdoc/>
        public override void DrawSelection(FRPaintEventArgs e)
        {
            base.DrawSelection(e);
            if (Report == null)
                return;
            float m = Report.Designer.DpiMultiplier();
            e.Graphics.DrawImage(Report.Designer.GetImage(75), (int)(AbsLeft * e.ScaleX + 8 * m), (int)(AbsTop * e.ScaleY - 8 * m));
        }

        /// <inheritdoc/>
        public override void HandleMouseDown(FRMouseEventArgs e)
        {
            HandleMouseHover(e);
            if (e.handled)
                e.mode = WorkspaceMode2.Move;
            else
            {
                base.HandleMouseDown(e);
                if (e.handled)
                {
                    if (e.modifierKeys != Keys.Shift)
                    {
                        e.mode = WorkspaceMode2.SelectionRect;
                        e.activeObject = this;
                    }
                }
            }
        }

        /// <inheritdoc/>
        public override void HandleMouseHover(FRMouseEventArgs e)
        {
            if (IsSelected)
            {
                float m = 1 / Report.Designer.Zoom;
                if (new RectangleF(AbsLeft + 8 * m, AbsTop - 8 * m, 16 * m, 16 * m).Contains(new PointF(e.x, e.y)))
                {
                    e.handled = true;
                    e.cursor = Cursors.SizeAll;
                }
            }
        }

        /// <inheritdoc/>
        public override void HandleMouseUp(FRMouseEventArgs e)
        {
            base.HandleMouseUp(e);
            if (e.activeObject == this && e.mode == WorkspaceMode2.SelectionRect)
            {
                ObjectCollection selectedList = new ObjectCollection();
                // find objects inside the selection rect
                foreach (ReportComponentBase c in Objects)
                {
                    e.handled = false;
                    c.HandleMouseUp(e);
                    // object is inside
                    if (e.handled)
                        selectedList.Add(c);
                }
                if (selectedList.Count > 0)
                    selectedList.CopyTo(Report.Designer.SelectedObjects);
            }
        }
        #endregion
    }
}
