Details for an event that provides pages and cell associated with a page dragging event.
Пример #1
0
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_visibleNotDraggedPages == -1)
            {
                // If pages are being dragged from this cell
                if (dragEndData.Navigator == _cell)
                {
                    // Create list of all the visible pages in the cell
                    KryptonPageCollection visiblePages = new KryptonPageCollection();
                    foreach (KryptonPage page in _cell.Pages)
                        if (page.LastVisibleSet)
                            visiblePages.Add(page);

                    // Remove all those that are being dragged
                    foreach (KryptonPage page in dragEndData.Pages)
                        visiblePages.Remove(page);

                    // Cache number of visible pages in target that are not part of the dragging set
                    _visibleNotDraggedPages = visiblePages.Count;
                }
                else
                {
                    // Pages not coming from this cell so we always allow the cell edge targets
                    _visibleNotDraggedPages = int.MaxValue;
                }
            }

            // If the drop leaves at least 1 page in the navigator then allow drag to edge
            if (_visibleNotDraggedPages >= 1)
                return base.IsMatch(screenPt, dragEndData);
            else
                return false;
        }
Пример #2
0
 private void EndDragging()
 {
     _dragPalette     = null;
     _dragRenderer    = null;
     _pageDragEndData = null;
     _dragging        = false;
 }
        /// <summary>
        /// Process the drag pages in the context of a target navigator.
        /// </summary>
        /// <param name="target">Target navigator instance.</param>
        /// <param name="data">Dragged page data.</param>
        /// <returns>Last page to be transferred.</returns>
        protected KryptonPage ProcessDragEndData(KryptonNavigator target,
                                                 PageDragEndData data)
        {
            KryptonPage ret = null;

            // Add each source page to the target
            foreach (KryptonPage page in data.Pages)
            {
                // Only add the page if one of the allow flags is set
                if ((page.Flags & (int)AllowFlags) != 0)
                {
                    // Use event to allow decision on if the page should be dropped
                    // (or even swap the page for a different page to be dropped)
                    PageDropEventArgs e = new PageDropEventArgs(page);
                    target.OnPageDrop(e);

                    if (!e.Cancel && (e.Page != null))
                    {
                        target.Pages.Add(e.Page);
                        ret = e.Page;
                    }
                }
            }

            return(ret);
        }
Пример #4
0
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Transfer the dragged pages into our navigator instance
            KryptonPage page = ProcessDragEndData(_navigator, data);

            // Make the last page transfer the newly selected page of the navigator
            if (page != null)
            {
                // If the navigator is allowed to have a selected page then select it
                if (_navigator.AllowTabSelect)
                {
                    _navigator.SelectedPage = page;
                }

                // Need to layout so the new cell has been added as a child control and
                // therefore can receive the focus we want to give it immediately afterwards
                _navigator.PerformLayout();

                if (!_navigator.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    _navigator.Select();
                }
            }

            return(true);
        }
        /// <summary>
        /// Add a list of drag targets from the provided interface.
        /// </summary>
        /// <param name="provider">Interface reference.</param>
        /// <param name="dragEndData">Pages data being dragged.</param>
        public void AddRange(IDragTargetProvider provider, PageDragEndData dragEndData)
        {
            DragTargetList targets = provider?.GenerateDragTargets(dragEndData);

            if ((targets != null) && (targets.Count > 0))
            {
                AddRange(targets);
            }
        }
        /// <summary>
        /// Generate a list of drag targets that are relevant to the provided end data.
        /// </summary>
        /// <param name="dragEndData">Pages data being dragged.</param>
        /// <returns>List of drag targets.</returns>
        public DragTargetList GenerateDragTargets(PageDragEndData dragEndData)
        {
            DragTargetList targets = new DragTargetList();

            // Generate the set of targets from the element hierarchy
            _manager.PropogateDragTargets(_floatingWindow, dragEndData, targets);

            // Must have at least one target
            if (targets.Count == 0)
                targets.Add(new DragTargetNull());

            return targets;
        }
Пример #7
0
        /// <summary>
        /// Find the target the first matches the provided screen point.
        /// </summary>
        /// <param name="screenPt">Point in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>First target that matches; otherwise null.</returns>
        protected virtual DragTarget FindTarget(Point screenPt, PageDragEndData dragEndData)
        {
            // Ask each target in turn if they are a match for the given screen point
            foreach (DragTarget target in DragTargets)
            {
                if (target.IsMatch(screenPt, dragEndData))
                {
                    return(target);
                }
            }

            // Nothing matches
            return(null);
        }
Пример #8
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public virtual void Start(IPaletteDragDrop paletteDragDrop,
                                  IRenderer renderer,
                                  PageDragEndData pageDragEndData,
                                  DragTargetList dragTargets)
        {
            Debug.Assert(paletteDragDrop != null);
            Debug.Assert(renderer != null);
            Debug.Assert(pageDragEndData != null);
            Debug.Assert(dragTargets != null);

            _paletteDragDrop = paletteDragDrop;
            _renderer        = renderer;
            _pageDragEndData = pageDragEndData;
            _dragTargets     = dragTargets;
        }
Пример #9
0
        /// <summary>
        /// Release unmanaged and optionally managed resources.
        /// </summary>
        /// <param name="disposing">Called from Dispose method.</param>
        protected virtual void Dispose(bool disposing)
        {
            // If called from explicit call to Dispose
            if (disposing)
            {
                // No need to call destructor once dispose has occured
                GC.SuppressFinalize(this);

                _pageDragEndData = null;
                _dragTargets     = null;
            }

            // Mark as disposed
            _disposed = true;
        }
Пример #10
0
        /// <summary>
        /// Occurs when dragging starts.
        /// </summary>
        /// <param name="screenPt">Mouse screen point at start of drag.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if dragging waas started; otherwise false.</returns>
        public virtual bool DragStart(Point screenPt, PageDragEndData dragEndData)
        {
            if (IsDisposed)
            {
                throw new InvalidOperationException("Cannot DragStart when instance have been disposed.");
            }

            if (IsDragging)
            {
                throw new InvalidOperationException("Cannot DragStart when already performing dragging operation.");
            }

            if (dragEndData == null)
            {
                throw new ArgumentNullException("Cannot provide an empty DragEndData.");
            }

            // Generate drag targets from the set of target provides
            ClearTargets();
            foreach (IDragTargetProvider provider in DragTargetProviders)
            {
                _dragTargets.AddRange(provider, dragEndData);
            }

            // We only drag if we have at least one page and one target
            _dragging = ((_dragTargets.Count > 0) && (dragEndData.Pages.Count > 0));

            // Do we really need to start dragging?
            if (_dragging)
            {
                // We cache the palette/renderer at start of drag and use the same ones for the
                // whole duration of the drag as changing drawing info during drag would be hard!
                ResolvePaletteRenderer();

                // Cache page data for duration of dragging operation
                _pageDragEndData = dragEndData;

                // Create correct drag feedback class and start it up
                ResolveDragFeedback();
                _dragFeedback.Start(_stateCommon, _dragRenderer, _pageDragEndData, _dragTargets);
            }
            else
            {
                ClearTargets();
            }

            return(_dragging);
        }
Пример #11
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public override void Start(IPaletteDragDrop paletteDragDrop,
                                   IRenderer renderer,
                                   PageDragEndData pageDragEndData, 
                                   DragTargetList dragTargets)
        {
            base.Start(paletteDragDrop, renderer, pageDragEndData, dragTargets);

            if (_solid == null)
            {
                // Create and show a window without it taking focus
                _solid = new DropSolidWindow(PaletteDragDrop, Renderer);
                _solid.SetBounds(0, 0, 1, 1, BoundsSpecified.All);
                _solid.ShowWithoutActivate();
                _solid.Refresh();
            }
        }
Пример #12
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public override void Start(IPaletteDragDrop paletteDragDrop,
                                   IRenderer renderer,
                                   PageDragEndData pageDragEndData,
                                   DragTargetList dragTargets)
        {
            base.Start(paletteDragDrop, renderer, pageDragEndData, dragTargets);

            if (_solid == null)
            {
                // Create and show a window without it taking focus
                _solid = new DropSolidWindow(PaletteDragDrop, Renderer);
                _solid.SetBounds(0, 0, 1, 1, BoundsSpecified.All);
                _solid.ShowWithoutActivate();
                _solid.Refresh();
            }
        }
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_notDraggedPagesFromNavigator == -1)
            {
                // Search for any pages that are not from this navigator
                _notDraggedPagesFromNavigator = 0;
                foreach (KryptonPage page in dragEndData.Pages)
                {
                    if (!_navigator.Pages.Contains(page))
                    {
                        _notDraggedPagesFromNavigator = 1;
                        break;
                    }
                }
            }

            // If 1 or more pages are not from this navigator then allow transfer into the target
            return(_notDraggedPagesFromNavigator > 0 && base.IsMatch(screenPt, dragEndData));
        }
        /// <summary>
        /// Is this target a match for the provided screen position.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if a match; otherwise false.</returns>
        public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
        {
            // First time around...
            if (_notDraggedPagesFromNavigator == -1)
            {
                // Search for any pages that are not from this navigator
                _notDraggedPagesFromNavigator = 0;
                foreach (KryptonPage page in dragEndData.Pages)
                    if (!_navigator.Pages.Contains(page))
                    {
                        _notDraggedPagesFromNavigator = 1;
                        break;
                    }
            }

            // If 1 or more pages are not from this navigator then allow transfer into the target
            if (_notDraggedPagesFromNavigator > 0)
                return base.IsMatch(screenPt, dragEndData);
            else
                return false;
        }
Пример #15
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public override void Start(IPaletteDragDrop paletteDragDrop,
                                   IRenderer renderer,
                                   PageDragEndData pageDragEndData,
                                   DragTargetList dragTargets)
        {
            base.Start(paletteDragDrop, renderer, pageDragEndData, dragTargets);

            if (_solid == null)
            {
                // Create and show a solid feedback window without it taking focus
                _solid = new DropSolidWindow(PaletteDragDrop, Renderer);
                _solid.SetBounds(0, 0, 1, 1, BoundsSpecified.All);
                _solid.ShowWithoutActivate();
                _solid.Refresh();
            }

            ClearClusters();

            // Create clusters of related drag targets
            foreach (DragTarget target in dragTargets)
            {
                // Check if the target is actually able to drop inside itself
                if (target.IsMatch(target.HotRect.Location, pageDragEndData))
                {
                    // Find the existing cluster for the targets screen rectangle
                    DockCluster cluster = FindTargetCluster(target);

                    // Is the target allowed to be added to the found cluster (if there is one found)
                    if ((cluster == null) || cluster.ExcludeCluster || ((target.Hint & DragTargetHint.ExcludeCluster) == DragTargetHint.ExcludeCluster))
                    {
                        _clusters.Add(new DockCluster(PaletteDragDrop, Renderer, target));
                    }
                    else
                    {
                        cluster.Add(target);
                    }
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Find our docking edge
            KryptonDockingEdge dockingEdge = null;
            switch (Edge)
            {
                case VisualOrientation.Left:
                    dockingEdge = ControlElement["Left"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Right:
                    dockingEdge = ControlElement["Right"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Top:
                    dockingEdge = ControlElement["Top"] as KryptonDockingEdge;
                    break;
                case VisualOrientation.Bottom:
                    dockingEdge = ControlElement["Bottom"] as KryptonDockingEdge;
                    break;
            }

            if (dockingEdge != null)
            {
                // Find the docked edge
                KryptonDockingEdgeDocked dockedEdge = dockingEdge["Docked"] as KryptonDockingEdgeDocked;
                if (dockingEdge != null)
                {
                    KryptonDockingManager manager = dockedEdge.DockingManager;
                    if (manager != null)
                    {
                        // Create a list of pages that are allowed to be transferred into the dockspace
                        List<KryptonPage> transferPages = new List<KryptonPage>();
                        List<string> transferUniqueNames = new List<string>();
                        foreach (KryptonPage page in data.Pages)
                            if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                            {
                                // Use event to indicate the page is becoming docked and allow it to be cancelled
                                CancelUniqueNameEventArgs args = new CancelUniqueNameEventArgs(page.UniqueName, false);
                                manager.RaisePageDockedRequest(args);

                                if (!args.Cancel)
                                {
                                    transferPages.Add(page);
                                    transferUniqueNames.Add(page.UniqueName);
                                }
                            }

                        // Transfer valid pages into the new dockspace
                        if (transferPages.Count > 0)
                        {
                            // Convert the incoming pages into store pages for restoring later
                            manager.PropogateAction(DockingPropogateAction.StorePages, transferUniqueNames.ToArray());

                            // Create a new dockspace at the start of the list so it is closest to the control edge
                            KryptonDockingDockspace dockspace = (_outsideEdge ? dockedEdge.InsertDockspace(0) : dockedEdge.AppendDockspace());

                            // Add pages into the target
                            dockspace.Append(transferPages.ToArray());

                            return true;
                        }
                    }
                }
            }

            return false;
        }
Пример #17
0
 /// <summary>
 /// Perform the drop action associated with the target.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="data">Data to pass to the target to process drop.</param>
 /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
 public override bool PerformDrop(Point screenPt, PageDragEndData data)
 {
     return true;
 }
Пример #18
0
        /// <summary>
        /// Process the drag pages in the context of a target navigator.
        /// </summary>
        /// <param name="workspace">Target workspace instance.</param>
        /// <param name="target">Target workspace cell instance.</param>
        /// <param name="data">Dragged page data.</param>
        /// <returns>Last page to be transferred.</returns>
        protected KryptonPage ProcessDragEndData(KryptonWorkspace workspace,
                                                 KryptonWorkspaceCell target,
                                                 PageDragEndData data)
        {
            KryptonPage ret = null;

            // Add each source page to the target
            foreach (KryptonPage page in data.Pages)
            {
                // Only add the page if one of the allow flags is set
                if ((page.Flags & (int)AllowFlags) != 0)
                {
                    // Use event to allow decision on if the page should be dropped
                    // (or even swap the page for a different page to be dropped)
                    PageDropEventArgs e = new PageDropEventArgs(page);
                    workspace.OnPageDrop(e);

                    if (!e.Cancel && (e.Page != null))
                    {
                        target.Pages.Add(e.Page);
                        ret = e.Page;
                    }
                }
            }

            return ret;
        }
Пример #19
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
 {
     return true;
 }
Пример #20
0
        /// <summary>
        /// Find the target the first matches the provided screen point.
        /// </summary>
        /// <param name="screenPt">Point in screen coordinates.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>First target that matches; otherwise null.</returns>
        protected virtual DragTarget FindTarget(Point screenPt, PageDragEndData dragEndData)
        {
            // Ask each target in turn if they are a match for the given screen point
            foreach (DragTarget target in DragTargets)
                if (target.IsMatch(screenPt, dragEndData))
                    return target;

            // Nothing matches
            return null;
        }
Пример #21
0
        /// <summary>
        /// Propogates a request for drag targets down the hierarchy of docking elements.
        /// </summary>
        /// <param name="floatingWindow">Reference to window being dragged.</param>
        /// <param name="dragData">Set of pages being dragged.</param>
        /// <param name="targets">Collection of drag targets.</param>
        public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
            PageDragEndData dragData,
            DragTargetList targets)
        {
            if (DockspaceControl.CellVisibleCount > 0)
            {
                // Create list of the pages that are allowed to be dropped into this dockspace
                KryptonPageCollection pages = new KryptonPageCollection();
                foreach (KryptonPage page in dragData.Pages)
                    if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                        pages.Add(page);

                // Do we have any pages left for dragging?
                if (pages.Count > 0)
                {
                    DragTargetList dockspaceTargets = DockspaceControl.GenerateDragTargets(new PageDragEndData(this, pages), KryptonPageFlags.DockingAllowDocked);
                    targets.AddRange(dockspaceTargets.ToArray());
                }
            }
        }
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Transfer the dragged pages into the existing cell
            KryptonPage page = ProcessDragEndData(Workspace, _cell, data);

            // Make the last page transfer the newly selected page of the cell
            if (page != null)
            {
                // Does the cell allow the selection of tabs?
                if (_cell.AllowTabSelect)
                    _cell.SelectedPage = page;

                if (!_cell.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    _cell.Select();
                }
            }

            return true;
        }
Пример #23
0
        /// <summary>
        /// Release unmanaged and optionally managed resources.
        /// </summary>
        /// <param name="disposing">Called from Dispose method.</param>
        protected virtual void Dispose(bool disposing)
        {
            // If called from explicit call to Dispose
            if (disposing)
            {
                // No need to call destructor once dispose has occured
                GC.SuppressFinalize(this);

                _pageDragEndData = null;
                _dragTargets = null;
            }

            // Mark as disposed
            _disposed = true;
        }
Пример #24
0
 /// <summary>
 /// Called to cleanup when dragging has finished.
 /// </summary>
 public virtual void Quit()
 {
     _pageDragEndData = null;
     _dragTargets = null;
 }
Пример #25
0
        /// <summary>
        /// Propogates a request for drag targets down the hierarchy of docking elements.
        /// </summary>
        /// <param name="floatingWindow">Reference to window being dragged.</param>
        /// <param name="dragData">Set of pages being dragged.</param>
        /// <param name="targets">Collection of drag targets.</param>
        public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                                  PageDragEndData dragData,
                                                  DragTargetList targets)
        {
            // Create a list of pages that are allowed to be transferred into a dockspace
            List<KryptonPage> transferPages = new List<KryptonPage>();
            foreach (KryptonPage page in dragData.Pages)
                if (page.AreFlagsSet(KryptonPageFlags.DockingAllowDocked))
                    transferPages.Add(page);

            // Only generate targets if we have some valid pages to transfer
            if (transferPages.Count > 0)
            {
                // Generate targets for the four control edges
                Rectangle screenRect = Control.RectangleToScreen(Control.ClientRectangle);
                Rectangle[] rectsDraw = SubdivideRectangle(screenRect, 3, int.MaxValue);
                Rectangle[] rectsHot = SubdivideRectangle(screenRect, 10, 20);

                // Must insert at start of target list as they are higher priority than cell targets
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[0], rectsDraw[0], DragTargetHint.EdgeLeft | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[1], rectsDraw[1], DragTargetHint.EdgeRight | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[2], rectsDraw[2], DragTargetHint.EdgeTop | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));
                targets.Add(new DragTargetControlEdge(screenRect, rectsHot[3], rectsDraw[3], DragTargetHint.EdgeBottom | DragTargetHint.ExcludeCluster, this, KryptonPageFlags.DockingAllowDocked, true));

                // If we have no designated inner element when we have to decide if we can place edge drag drop targets based on the
                // available space at the center of the control after taking into account any edge docked controls already in place.
                if (_innerElement == null)
                {
                    // Find the inner rectangle after taking docked controls into account
                    Size tl = Size.Empty;
                    Size br = Control.ClientSize;
                    foreach (Control c in Control.Controls)
                        if (c.Visible)
                        {
                            switch (c.Dock)
                            {
                                case DockStyle.Left:
                                    tl.Width = Math.Max(tl.Width, c.Right);
                                    break;
                                case DockStyle.Right:
                                    br.Width = Math.Min(br.Width, c.Left);
                                    break;
                                case DockStyle.Top:
                                    tl.Height = Math.Max(tl.Height, c.Bottom);
                                    break;
                                case DockStyle.Bottom:
                                    br.Height = Math.Min(br.Height, c.Top);
                                    break;
                            }
                        }

                    // If there is inner space available
                    Rectangle innerRect = new Rectangle(tl.Width, tl.Height, br.Width - tl.Width, br.Height - tl.Height);
                    if ((innerRect.Width > 0) && (innerRect.Height > 0))
                    {
                        Rectangle innerScreenRect = Control.RectangleToScreen(innerRect);
                        Rectangle[] innerRectsDraw = SubdivideRectangle(innerScreenRect, 3, int.MaxValue);
                        Rectangle[] innerRectsHot = SubdivideRectangle(innerScreenRect, 10, 20);
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[0], innerRectsDraw[0], DragTargetHint.EdgeLeft, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[1], innerRectsDraw[1], DragTargetHint.EdgeRight, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[2], innerRectsDraw[2], DragTargetHint.EdgeTop, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[3], innerRectsDraw[3], DragTargetHint.EdgeBottom, this, KryptonPageFlags.DockingAllowDocked, false));
                    }
                }
                else if (_innerElement is KryptonDockingNavigator)
                {
                    KryptonDockingNavigator dockingNavigator = (KryptonDockingNavigator)_innerElement;

                    // If there is inner space available
                    Rectangle innerScreenRect = dockingNavigator.DockableNavigatorControl.RectangleToScreen(dockingNavigator.DockableNavigatorControl.ClientRectangle);
                    if ((innerScreenRect.Width > 0) && (innerScreenRect.Height > 0))
                    {
                        Rectangle[] innerRectsDraw = SubdivideRectangle(innerScreenRect, 3, int.MaxValue);
                        Rectangle[] innerRectsHot = SubdivideRectangle(innerScreenRect, 10, 20);
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[0], innerRectsDraw[0], DragTargetHint.EdgeLeft, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[1], innerRectsDraw[1], DragTargetHint.EdgeRight, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[2], innerRectsDraw[2], DragTargetHint.EdgeTop, this, KryptonPageFlags.DockingAllowDocked, false));
                        targets.Add(new DragTargetControlEdge(innerScreenRect, innerRectsHot[3], innerRectsDraw[3], DragTargetHint.EdgeBottom, this, KryptonPageFlags.DockingAllowDocked, false));
                    }
                }

                // Let base class generate targets for contained elements
                base.PropogateDragTargets(floatingWindow, dragData, targets);
            }
        }
Пример #26
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public virtual bool IsMatch(Point screenPt, PageDragEndData dragEndData)
 {
     // Default to matching if the mouse is inside the targets hot area
     return(HotRect.Contains(screenPt));
 }
Пример #27
0
            /// <summary>
            /// Perform the drop action associated with the target.
            /// </summary>
            /// <param name="screenPt">Position in screen coordinates.</param>
            /// <param name="data">Data to pass to the target to process drop.</param>
            /// <returns>True if the drop was performed and the source can remove any pages.</returns>
            public override bool PerformDrop(Point screenPt, PageDragEndData data)
            {
                // Create a node for each page
                foreach (KryptonPage page in data.Pages)
                {
                    // Create node and populate with page details
                    TreeNode node = new TreeNode();
                    node.Text = page.Text;
                    node.ImageIndex = int.Parse((string)page.Tag);
                    node.SelectedImageIndex = node.ImageIndex;
                    node.Tag = page.Tag;

                    // Add to end of root nodes
                    _treeView.Nodes.Add(node);
                }

                // Take focus and select the last node added
                if (_treeView.Nodes.Count > 0)
                {
                    _treeView.SelectedNode = _treeView.Nodes[_treeView.Nodes.Count - 1];
                    _treeView.Select();
                }

                return true;
            }
Пример #28
0
 /// <summary>
 /// Is this target a match for the provided screen position.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>True if a match; otherwise false.</returns>
 public override bool IsMatch(Point screenPt, PageDragEndData dragEndData)
 {
     // Cannot drag back to ourself
     if ((dragEndData.Source != null) &&
         (dragEndData.Source is PageDragTreeView) &&
         (dragEndData.Source == _treeView))
         return false;
     else
         return base.IsMatch(screenPt, dragEndData);
 }
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Transfer the dragged pages into a new cell
            KryptonWorkspaceCell cell = new KryptonWorkspaceCell();
            KryptonPage page = ProcessDragEndData(Workspace, cell, data);

            // If no pages are transferred then we do nothing and no longer need cell instance
            if (page == null)
                cell.Dispose();
            else
            {
                // If the root is not the same direction as that needed for the drop then...
                bool dropHorizontal = (Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Right);
                if ((dropHorizontal && (Workspace.Root.Orientation == Orientation.Vertical)) ||
                    (!dropHorizontal && (Workspace.Root.Orientation == Orientation.Horizontal)))
                {
                    // Create a new sequence and place all existing root items into it
                    KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(Workspace.Root.Orientation);
                    for (int i = Workspace.Root.Children.Count - 1; i >= 0; i--)
                    {
                        Component child = Workspace.Root.Children[i];
                        Workspace.Root.Children.RemoveAt(i);
                        sequence.Children.Insert(0, child);
                    }

                    // Put the new sequence in the root so all items are now grouped together
                    Workspace.Root.Children.Add(sequence);

                    // Switch the direction of the root
                    if (Workspace.Root.Orientation == Orientation.Horizontal)
                        Workspace.Root.Orientation = Orientation.Vertical;
                    else
                        Workspace.Root.Orientation = Orientation.Horizontal;
                }

                // Add to the start or the end of the root sequence?
                if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                    Workspace.Root.Children.Insert(0, cell);
                else
                    Workspace.Root.Children.Add(cell);

                // Make the last page transfer the newly selected page of the cell
                if (page != null)
                {
                    // Does the cell allow the selection of tabs?
                    if (cell.AllowTabSelect)
                        cell.SelectedPage = page;

                    // Need to layout so the new cell has been added as a child control and
                    // therefore can receive the focus we want to give it immediately afterwards
                    Workspace.PerformLayout();

                    if (!cell.IsDisposed)
                    {
                        // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                        // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                        // change activation is causing the source workspace control to dispose to earlier.
                        Application.DoEvents();
                        cell.Select();
                    }
                }
            }

            return true;
        }
 /// <summary>
 /// Propogates a request for drag targets down the hierarchy of docking elements.
 /// </summary>
 /// <param name="floatingWindow">Reference to window being dragged.</param>
 /// <param name="dragData">Set of pages being dragged.</param>
 /// <param name="targets">Collection of drag targets.</param>
 public override void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                           PageDragEndData dragData,
                                           DragTargetList targets)
 {
     // Can only generate targets for a floating window that is actually visible and not the one being dragged
     if (FloatingWindow.Visible && (floatingWindow != FloatingWindow))
         base.PropogateDragTargets(floatingWindow, dragData, targets);
 }
Пример #31
0
 /// <summary>
 /// Generate a list of drag targets that are relevant to the provided end data.
 /// </summary>
 /// <param name="dragEndData">Pages data being dragged.</param>
 /// <returns>List of drag targets.</returns>
 public virtual DragTargetList GenerateDragTargets(PageDragEndData dragEndData)
 {
     return GenerateDragTargets(dragEndData, KryptonPageFlags.All);
 }
Пример #32
0
        /// <summary>
        /// Called to initialize the implementation when dragging starts.
        /// </summary>
        /// <param name="paletteDragDrop">Drawing palette.</param>
        /// <param name="renderer">Drawing renderer.</param>
        /// <param name="pageDragEndData">Drag data associated with drag operation.</param>
        /// <param name="dragTargets">List of all drag targets.</param>
        public virtual void Start(IPaletteDragDrop paletteDragDrop,
                                  IRenderer renderer,
                                  PageDragEndData pageDragEndData, 
                                  DragTargetList dragTargets)
        {
            Debug.Assert(paletteDragDrop != null);
            Debug.Assert(renderer != null);
            Debug.Assert(pageDragEndData != null);
            Debug.Assert(dragTargets != null);

            _paletteDragDrop = paletteDragDrop;
            _renderer = renderer;
            _pageDragEndData = pageDragEndData;
            _dragTargets = dragTargets;
        }
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // Transfer the dragged pages into our navigator instance
            KryptonPage page = ProcessDragEndData(_navigator, data);

            // Make the last page transfer the newly selected page of the navigator
            if (page != null)
            {
                // If the navigator is allowed to have a selected page then select it
                if (_navigator.AllowTabSelect)
                    _navigator.SelectedPage = page;

                // Need to layout so the new cell has been added as a child control and
                // therefore can receive the focus we want to give it immediately afterwards
                _navigator.PerformLayout();

                if (!_navigator.IsDisposed)
                {
                    // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                    // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                    // change activation is causing the source workspace control to dispose to earlier.
                    Application.DoEvents();
                    _navigator.Select();
                }
            }

            return true;
        }
Пример #34
0
 /// <summary>
 /// Create the actual drop data based on the proposed data provided.
 /// </summary>
 /// <param name="dropData">Proposed drop data.</param>
 /// <returns>Actual drop data</returns>
 protected virtual PageDragEndData CreateDropData(PageDragEndData dropData)
 {
     return(dropData);
 }
Пример #35
0
 /// <summary>
 /// Called to cleanup when dragging has finished.
 /// </summary>
 public virtual void Quit()
 {
     _pageDragEndData = null;
     _dragTargets     = null;
 }
Пример #36
0
        /// <summary>
        /// Perform the drop action associated with the target.
        /// </summary>
        /// <param name="screenPt">Position in screen coordinates.</param>
        /// <param name="data">Data to pass to the target to process drop.</param>
        /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
        public override bool PerformDrop(Point screenPt, PageDragEndData data)
        {
            // We need a parent sequence in order to perform drop
            KryptonWorkspaceSequence parent = Cell.WorkspaceParent as KryptonWorkspaceSequence;
            if (parent != null)
            {
                // Transfer the dragged pages into a new cell
                KryptonWorkspaceCell cell = new KryptonWorkspaceCell();
                KryptonPage page = ProcessDragEndData(Workspace, cell, data);

                // If no pages are transferred then we do nothing and no longer need cell instance
                if (page == null)
                    cell.Dispose();
                else
                {
                    // If the parent sequence is not the same direction as that needed for the drop then...
                    bool dropHorizontal = (Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Right);
                    if ((dropHorizontal && (parent.Orientation == Orientation.Vertical)) ||
                        (!dropHorizontal && (parent.Orientation == Orientation.Horizontal)))
                    {
                        // Find opposite direction to the parent sequence
                        Orientation sequenceOrientation;
                        if (parent.Orientation == Orientation.Horizontal)
                            sequenceOrientation = Orientation.Vertical;
                        else
                            sequenceOrientation = Orientation.Horizontal;

                        // Create a new sequence and transfer the target cell into it
                        KryptonWorkspaceSequence sequence = new KryptonWorkspaceSequence(sequenceOrientation);
                        int index = parent.Children.IndexOf(_cell);
                        parent.Children.RemoveAt(index);
                        sequence.Children.Add(_cell);

                        // Put the sequence into the place where the target cell used to be
                        parent.Children.Insert(index, sequence);

                        // Add new cell to the start or the end of the new sequence?
                        if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                            sequence.Children.Insert(0, cell);
                        else
                            sequence.Children.Add(cell);
                    }
                    else
                    {
                        // Find position of the target cell
                        int index = parent.Children.IndexOf(_cell);

                        // Add new cell before or after the target cell?
                        if ((Edge == VisualOrientation.Left) || (Edge == VisualOrientation.Top))
                            parent.Children.Insert(index, cell);
                        else
                            parent.Children.Insert(index + 1, cell);
                    }

                    // Make the last page transfered the newly selected page of the cell
                    if (page != null)
                    {
                        // Does the cell allow the selection of tabs?
                        if (cell.AllowTabSelect)
                            cell.SelectedPage = page;

                        // Need to layout so the new cell has been added as a child control and
                        // therefore can receive the focus we want to give it immediately afterwards
                        Workspace.PerformLayout();

                        if (!cell.IsDisposed)
                        {
                            // Without this DoEvents() call the dropping of multiple pages in a complex arrangement causes an exception for
                            // a complex reason that is hard to work out (i.e. I'm not entirely sure). Something to do with using select to
                            // change activation is causing the source workspace control to dispose to earlier.
                            Application.DoEvents();
                            cell.Select();
                        }
                    }
                }
            }

            return true;
        }
Пример #37
0
        /// <summary>
        /// Generate a list of drag targets that are relevant to the provided end data.
        /// </summary>
        /// <param name="dragEndData">Pages data being dragged.</param>
        /// <returns>List of drag targets.</returns>
        public DragTargetList GenerateDragTargets(PageDragEndData dragEndData)
        {
            DragTargetList targets = new DragTargetList();

            // Generate target for the entire navigator client area
            targets.Add(new DragTargetTreeViewTransfer(RectangleToScreen(ClientRectangle), this));

            return targets;
        }
Пример #38
0
        /// <summary>
        /// Generate a list of drag targets that are relevant to the provided end data.
        /// </summary>
        /// <param name="dragEndData">Pages data being dragged.</param>
        /// <param name="allowFlags">Only drop pages that have one of these flags set.</param>
        /// <returns>List of drag targets.</returns>
        public virtual DragTargetList GenerateDragTargets(PageDragEndData dragEndData, KryptonPageFlags allowFlags)
        {
            DragTargetList targets = new DragTargetList();

            // Generate target for the entire navigator client area
            targets.Add(new DragTargetNavigatorTransfer(RectangleToScreen(ClientRectangle), this, allowFlags));

            return targets;
        }
Пример #39
0
 /// <summary>
 /// Perform the drop action associated with the target.
 /// </summary>
 /// <param name="screenPt">Position in screen coordinates.</param>
 /// <param name="dragEndData">Data to be dropped at destination.</param>
 /// <returns>Drop was performed and the source can perform any removal of pages as required.</returns>
 public abstract bool PerformDrop(Point screenPt, PageDragEndData dragEndData);
Пример #40
0
 /// <summary>
 /// Propogates a request for drag targets down the hierarchy of docking elements.
 /// </summary>
 /// <param name="floatingWindow">Reference to window being dragged.</param>
 /// <param name="dragData">Set of pages being dragged.</param>
 /// <param name="targets">Collection of drag targets.</param>
 public virtual void PropogateDragTargets(KryptonFloatingWindow floatingWindow,
                                          PageDragEndData dragData,
                                          DragTargetList targets)
 {
     // Propogate the request to all child elements
     foreach (IDockingElement child in this)
         child.PropogateDragTargets(floatingWindow, dragData, targets);
 }
Пример #41
0
 private DragTarget FindTarget(Point screenPt, PageDragEndData dragEndData)
 {
     // Nothing matches
     return(null);
 }
Пример #42
0
        /// <summary>
        /// Occurs when dragging starts.
        /// </summary>
        /// <param name="screenPt">Mouse screen point at start of drag.</param>
        /// <param name="dragEndData">Data to be dropped at destination.</param>
        /// <returns>True if dragging waas started; otherwise false.</returns>
        public override bool DragStart(Point screenPt, PageDragEndData dragEndData)
        {
            if (FloatingWindow != null)
                FloatingWindow.Capture = true;

            AddFilter();
            return base.DragStart(screenPt, dragEndData);
        }