Example #1
0
        private bool Unparent(DragDataWrapper dw, UIElement uie)
        {
            bool success = false;

            if (dw != null)
            {
                if (dw.AllowChildrenRemove)
                {
                    dw.Shim.UnParent();
                }
            }

            if (!success) // BRUTE FORCE
            {
                if (uie is FrameworkElement)
                {
                    FrameworkElement fe = uie as FrameworkElement;

                    if (fe.Parent != null)
                    {
                        if (fe.Parent is Panel)
                        {
                            try
                            {
                                ((Panel)(fe.Parent)).Children.Remove(uie);
                                success = true;
                            }
                            catch (Exception)
                            {
#if DEBUG
                                System.Diagnostics.Debug.Assert(false);
#endif
                            }
                        }
                    }
                    else if (fe.Parent is ContentControl)
                    {
                        ContentControl cc = fe.Parent as ContentControl;

                        cc.Content = null;
                        success    = true;
                    }
                }
            }

            return(success);
        }
Example #2
0
        private void DropTarget_Drop(object sender, DragEventArgs e)
        {
            IDataObject     data            = e.Data;
            DragDataWrapper dw              = null;
            bool            isDataOperation = false;

            Debug.Assert(data != null);

            if (data.GetDataPresent(typeof(DragDataWrapper).ToString()))
            {
                dw = data.GetData(typeof(DragDataWrapper).ToString()) as DragDataWrapper;

                Debug.Assert(dw.Shim != null);

                if ((dw.Shim.SupportedActions & DragDropProviderActions.Data) != 0)
                {
                    isDataOperation = true;
                }
            }

            // Try a BRUTE FORCE APPROACH on UIElement just to show how it could be done
            // BUT NOT ENDORSING IT!!!
            if (!isDataOperation)
            {
                if (this.dropTarget is Canvas)
                {
                    if (e.Data.GetDataPresent(DataFormats.FileDrop))
                    {
                        this.DropFileLink(e);
                    }
                    else if (e.Data.GetDataPresent(UrlDataFormat))
                    {
                        this.DropUrl(e);
                    }
                }
            }
            else
            {
                Debug.Assert(dw != null);
                Debug.Assert(dw.Shim != null);

                object rawdata = dw.Data;

                if (this.dropTarget is ItemsControl)
                {
                    this.DropItemsControlHandler(e, rawdata);
                }
                else if (dropTarget is Canvas)
                {
                    if (rawdata is IWidget)
                    {
                        this.DropCanvasWidget(e, rawdata as IWidget);
                    }
                    else if (rawdata is SiteMapNode)
                    {
                        this.DropCanvasInternalLink(e, rawdata as NavigationNode);
                    }
                }
            }

            e.Handled = true;
        }
Example #3
0
        private void StartDrag(MouseEventArgs args)
        {
            IDataObject data        = null;
            UIElement   dragelement = null;

            // ADD THE DATA
            if (this.Callback != null)
            {
                DragDataWrapper dw = new DragDataWrapper();

                data = new DataObject(typeof(DragDataWrapper).ToString(), dw);

                if ((this.Callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0)
                {
                    this.Callback.AppendData(ref data, args);
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Data) != 0)
                {
                    dw.Data = this.Callback.GetData();
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    dragelement = this.Callback.GetVisual(args);
                }
                else
                {
                    dragelement = args.OriginalSource as UIElement;
                }

                dw.Source   = this.DragSource;
                dw.Shim     = this.Callback;

                Debug.Assert(this.DragScope == null, "The DragDataWrapper is meant for in-proc...  Sorry for asserting, just wanted to confirm.. comment out assertion if needed");
            }
            else
            {
                dragelement = args.OriginalSource as UIElement;
                data        = new DataObject(typeof(UIElement).ToString(), dragelement);
            }

            if (dragelement == null || data == null || dragelement == this.DragSource)
            {
                return;
            }

            DragEventHandler                dragOver        = null;
            DragEventHandler                dragLeave       = null;
            QueryContinueDragEventHandler   queryContinue   = null;
            GiveFeedbackEventHandler        giveFeedback    = null;
            DragDropEffects                 effects         = this.GetDragDropEffects();
            DragDropEffects                 resultEffects;

            // Inprocess Drag  ...
            if (this.DragScope != null)
            {
                bool previousAllowDrop = this.DragScope.AllowDrop;

                this.adorner    = new DragAdorner(this.DragScope, (UIElement)dragelement, true, this.Opacity);
                this.layer      = AdornerLayer.GetAdornerLayer(this.DragScope as Visual);

                this.layer.Add(this.adorner);

                if (this.DragScope != this.DragSource)
                {
                    this.DragScope.AllowDrop = true;

                    DragDrop.AddPreviewDragOverHandler((DependencyObject)this.DragScope, dragOver = new DragEventHandler(DragScope_DragOver));
                    DragDrop.AddPreviewDragLeaveHandler(this.DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave));
                    DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag));
                }

                try
                {
                    this.IsDragging     = true;
                    this.mouseLeftScope = false;
                    resultEffects       = DragDrop.DoDragDrop(this.DragSource, data, effects);

                    this.DragFinished(resultEffects);
                }
                catch
                {
                    Debug.Assert(false);
                }

                if (this.DragScope != this.DragSource)
                {
                    this.DragScope.AllowDrop = previousAllowDrop;

                    DragDrop.RemovePreviewDragOverHandler(this.DragScope, dragOver);
                    DragDrop.RemovePreviewDragLeaveHandler(this.DragScope, dragLeave);
                    DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, queryContinue);
                }
            }
            else
            {
                DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag));
                DragDrop.AddGiveFeedbackHandler(this.DragSource, giveFeedback = new GiveFeedbackEventHandler(OnGiveFeedback));

                this.IsDragging = true;

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    this.CreateDragDropWindow(dragelement);
                    this.dragdropWindow.Show();
                }

                try
                {
                    resultEffects = DragDrop.DoDragDrop(this.DragSource, data, effects);
                }
                finally
                {
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    this.DestroyDragDropWindow();
                }

                DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, OnQueryContinueDrag);
                DragDrop.AddGiveFeedbackHandler(this.DragSource, OnGiveFeedback);

                this.IsDragging = false;
                this.DragFinished(resultEffects);
            }
        }
Example #4
0
        private void StartDrag(MouseEventArgs args)
        {
            IDataObject data        = null;
            UIElement   dragelement = null;

            // ADD THE DATA
            if (this.Callback != null)
            {
                DragDataWrapper dw = new DragDataWrapper();

                data = new DataObject(typeof(DragDataWrapper).ToString(), dw);

                if ((this.Callback.SupportedActions & DragDropProviderActions.MultiFormatData) != 0)
                {
                    this.Callback.AppendData(ref data, args);
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Data) != 0)
                {
                    dw.Data = this.Callback.GetData();
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    dragelement = this.Callback.GetVisual(args);
                }
                else
                {
                    dragelement = args.OriginalSource as UIElement;
                }

                dw.Source = this.DragSource;
                dw.Shim   = this.Callback;

                Debug.Assert(this.DragScope == null, "The DragDataWrapper is meant for in-proc...  Sorry for asserting, just wanted to confirm.. comment out assertion if needed");
            }
            else
            {
                dragelement = args.OriginalSource as UIElement;
                data        = new DataObject(typeof(UIElement).ToString(), dragelement);
            }

            if (dragelement == null || data == null || dragelement == this.DragSource)
            {
                return;
            }

            DragEventHandler dragOver  = null;
            DragEventHandler dragLeave = null;
            QueryContinueDragEventHandler queryContinue = null;
            GiveFeedbackEventHandler      giveFeedback  = null;
            DragDropEffects effects = this.GetDragDropEffects();
            DragDropEffects resultEffects;

            // Inprocess Drag  ...
            if (this.DragScope != null)
            {
                bool previousAllowDrop = this.DragScope.AllowDrop;

                this.adorner = new DragAdorner(this.DragScope, (UIElement)dragelement, true, this.Opacity);
                this.layer   = AdornerLayer.GetAdornerLayer(this.DragScope as Visual);

                this.layer.Add(this.adorner);

                if (this.DragScope != this.DragSource)
                {
                    this.DragScope.AllowDrop = true;

                    DragDrop.AddPreviewDragOverHandler((DependencyObject)this.DragScope, dragOver = new DragEventHandler(DragScope_DragOver));
                    DragDrop.AddPreviewDragLeaveHandler(this.DragScope, dragLeave = new DragEventHandler(DragScope_DragLeave));
                    DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag));
                }

                try
                {
                    this.IsDragging     = true;
                    this.mouseLeftScope = false;
                    resultEffects       = DragDrop.DoDragDrop(this.DragSource, data, effects);

                    this.DragFinished(resultEffects);
                }
                catch
                {
                    Debug.Assert(false);
                }

                if (this.DragScope != this.DragSource)
                {
                    this.DragScope.AllowDrop = previousAllowDrop;

                    DragDrop.RemovePreviewDragOverHandler(this.DragScope, dragOver);
                    DragDrop.RemovePreviewDragLeaveHandler(this.DragScope, dragLeave);
                    DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, queryContinue);
                }
            }
            else
            {
                DragDrop.AddPreviewQueryContinueDragHandler(this.DragSource, queryContinue = new QueryContinueDragEventHandler(OnQueryContinueDrag));
                DragDrop.AddGiveFeedbackHandler(this.DragSource, giveFeedback = new GiveFeedbackEventHandler(OnGiveFeedback));

                this.IsDragging = true;

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    this.CreateDragDropWindow(dragelement);
                    this.dragdropWindow.Show();
                }

                try
                {
                    resultEffects = DragDrop.DoDragDrop(this.DragSource, data, effects);
                }
                finally
                {
                }

                if ((this.Callback.SupportedActions & DragDropProviderActions.Visual) != 0)
                {
                    this.DestroyDragDropWindow();
                }

                DragDrop.RemovePreviewQueryContinueDragHandler(this.DragSource, OnQueryContinueDrag);
                DragDrop.AddGiveFeedbackHandler(this.DragSource, OnGiveFeedback);

                this.IsDragging = false;
                this.DragFinished(resultEffects);
            }
        }