Exemplo n.º 1
0
        /// <summary>
        /// Occurs when dragging ends because of dropping.
        /// </summary>
        /// <param name="screenPt">Ending screen point when dropping.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public virtual bool DragEnd(Point screenPt)
        {
            if (IsDisposed)
            {
                throw new InvalidOperationException("Cannot DragEnd when instance have been disposed.");
            }

            if (!IsDragging)
            {
                throw new InvalidOperationException("Cannot DragEnd when DragStart has not been called.");
            }

            // Different feedback objects implement visual feeback differently and so only the feedback
            // instance knows the correct target to use for the given screen point and drag data.
            _currentTarget = _dragFeedback.Feedback(screenPt, _currentTarget);

            // Remove visual feedback
            _dragFeedback.Quit();

            // Inform target it needs to perform the drop action
            bool ret = false;

            if (_currentTarget != null)
            {
                ret = _currentTarget.PerformDrop(screenPt, _pageDragEndData);
            }

            ClearTargets();
            RestoreCursor();
            EndDragging();

            return(ret);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initialize a new instance of the DockCluster class.
 /// </summary>
 /// <param name="paletteDragDrop">Drawing palette.</param>
 /// <param name="renderer">Drawing renderer.</param>
 /// <param name="target">Initial target for the cluster.</param>
 public DockCluster(IPaletteDragDrop paletteDragDrop,
                    IRenderer renderer,
                    DragTarget target)
 {
     _paletteDragDrop = paletteDragDrop;
     _renderer        = renderer;
     _screenRect      = target.ScreenRect;
     _drawRect        = target.DrawRect;
     _hintToTarget    = new HintToTarget();
     _hintToTarget.Add(target.Hint & DragTargetHint.ExcludeFlags, target);
     _excludeCluster = (target.Hint & DragTargetHint.ExcludeCluster) == DragTargetHint.ExcludeCluster;
 }
Exemplo n.º 3
0
        private DockCluster FindTargetCluster(DragTarget target)
        {
            foreach (DockCluster cluster in _clusters)
            {
                if (!cluster.ExcludeCluster && cluster.ScreenRect.Equals(target.ScreenRect))
                {
                    return(cluster);
                }
            }

            return(null);
        }
Exemplo n.º 4
0
            /// <summary>
            /// Add the new target to the cluster.
            /// </summary>
            /// <param name="target">Target to add into cluster.</param>
            public void Add(DragTarget target)
            {
                // Find the hint that excludes extra flags
                DragTargetHint hint = target.Hint & DragTargetHint.ExcludeFlags;

                // Can only add one of each hint value
                if (!_hintToTarget.ContainsKey(hint))
                {
                    _hintToTarget.Add(hint, target);

                    // Make sure the drawing rectangle encloses all targets
                    _drawRect = Rectangle.Union(_drawRect, target.DrawRect);
                }
            }
Exemplo n.º 5
0
        private void ClearTargets()
        {
            if (_dragTargets != null)
            {
                // Dispose the targets to ensure references are removed to prevent memory leaks
                foreach (DragTarget target in _dragTargets)
                {
                    target.Dispose();
                }

                _dragTargets.Clear();
            }

            _currentTarget = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Occurs on dragging movement.
        /// </summary>
        /// <param name="screenPt">Latest screen point during dragging.</param>
        public virtual void DragMove(Point screenPt)
        {
            if (IsDisposed)
            {
                throw new InvalidOperationException("Cannot DragMove when instance have been disposed.");
            }

            if (!IsDragging)
            {
                throw new InvalidOperationException("Cannot DragMove when DragStart has not been called.");
            }

            // Different feedback objects implement visual feeback differently and so only the feedback
            // instance knows the correct target to use for the given screen point and drag data.
            _currentTarget = _dragFeedback.Feedback(screenPt, _currentTarget);

            // Check if we need a cursor to indicate the drag state
            UpdateCursor();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called to request feedback be shown for the specified target.
        /// </summary>
        /// <param name="screenPt">Current screen point of mouse.</param>
        /// <param name="target">Target that needs feedback.</param>
        /// <returns>Updated drag target.</returns>
        public override DragTarget Feedback(Point screenPt, DragTarget target)
        {
            // If the current target no longer matches the new point, we need a new target.
            if ((target != null) && !target.IsMatch(screenPt, PageDragEndData))
            {
                target = null;
            }

            // Only find a new target if we do not already have a target
            if (target == null)
            {
                target = FindTarget(screenPt, PageDragEndData);
            }

            if (_solid != null)
            {
                _solid.SolidRect = (target != null) ? target.DrawRect : Rectangle.Empty;
            }

            return(target);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Called to request feedback be shown for the specified target.
        /// </summary>
        /// <param name="screenPt">Current screen point of mouse.</param>
        /// <param name="target">Target that needs feedback.</param>
        /// <returns>Updated drag target.</returns>
        public override DragTarget Feedback(Point screenPt, DragTarget target)
        {
            DragTarget matchTarget = null;

            // Update each cluster so it shows/hides docking indicators based on mouse position
            foreach (DockCluster cluster in _clusters)
            {
                DragTarget clusterTarget = cluster.Feedback(screenPt, _dragFeedback);

                // We use the first matching target found in a cluster
                if ((clusterTarget != null) && (matchTarget == null))
                {
                    matchTarget = clusterTarget;
                }
            }

            // Update the solid feedback rectangle with area of the specific target
            if (_solid != null)
            {
                _solid.SolidRect = (matchTarget != null) ? matchTarget.DrawRect : Rectangle.Empty;
            }

            return(matchTarget);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Called to request feedback be shown for the specified target.
 /// </summary>
 /// <param name="screenPt">Current screen point of mouse.</param>
 /// <param name="target">Target that needs feedback.</param>
 /// <returns>Updated drag target.</returns>
 public abstract DragTarget Feedback(Point screenPt, DragTarget target);