Beispiel #1
0
        private void IsEnabled(object obj)
        {
            if (!(obj is BooleanClass))
            {
                return;
            }

            BooleanClass boolean = (BooleanClass)obj;

            IDataObject iData;

            try
            {
                iData = Clipboard.GetDataObject();
            }
            catch
            {
                boolean.Value = false;
                return;
            }
            if (iData == null)
            {
                boolean.Value = false;
                return;
            }
            foreach (string format in iData.GetFormats())
            {
                if (!format.Contains("gView.Plugins.MapTools.ExtensionSerializer") &&
                    !format.Contains("gView.Framework.system.ExplorerObjectSerialization") &&
                    !format.Contains("gView.Framework.UI.IExplorerObjectSerialization"))
                {
                    continue;
                }

                object ob = null;
                try
                {
                    ob = iData.GetData(format);
                }
                catch { }
                if (ob is IEnumerable <IExplorerObjectSerialization> && _exapp != null && _exapp.SelectedObjects != null && _exapp.SelectedObjects.Count == 1)
                {
                    IExplorerObject exObject = _exapp.SelectedObjects[0];
                    if (exObject is IExplorerObjectContentDragDropEvents)
                    {
                        IExplorerObjectContentDragDropEvents ddEvents = exObject as IExplorerObjectContentDragDropEvents;
                        DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                        ddEvents.Content_DragEnter(e);
                        if (e.Effect == DragDropEffects.Copy)
                        {
                            boolean.Value = true;
                            return;
                        }
                    }
                }
            }

            boolean.Value = false;
            return;
        }
Beispiel #2
0
        private void OnEvent()
        {
            if (_exapp != null)
            {
                _exapp.SetCursor(Cursors.WaitCursor);
            }
            try
            {
                if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.Display != null)
                {
                    IDataObject iData = Clipboard.GetDataObject();
                    if (iData == null)
                    {
                        return;
                    }

                    foreach (string format in iData.GetFormats())
                    {
                        if (!format.Contains("gView.Plugins.MapTools.ExtensionSerializer") &&
                            !format.Contains("gView.Framework.system.ExplorerObjectSerialization") &&
                            !format.Contains("gView.Framework.UI.IExplorerObjectSerialization"))
                        {
                            continue;
                        }

                        object ob = iData.GetData(format);
                        if (ob is IEnumerable <ExtensionSerializer> )
                        {
                            foreach (ExtensionSerializer ser in (IEnumerable <ExtensionSerializer>)ob)
                            {
                                object extension = ser.Object;

                                if (extension is IGraphicElement2)
                                {
                                    IGraphicElement2 element = extension as IGraphicElement2;

                                    if (element.Geometry != null)
                                    {
                                        Point point = new Point(
                                            (_doc.FocusMap.Display.Envelope.minx + _doc.FocusMap.Display.Envelope.maxx) / 2.0 - (element.Geometry.Envelope.Width) / 2.0,
                                            (_doc.FocusMap.Display.Envelope.miny + _doc.FocusMap.Display.Envelope.maxy) / 2.0 - (element.Geometry.Envelope.Height) / 2.0);

                                        element.Translation(point.X, point.Y);
                                    }
                                    _doc.FocusMap.Display.GraphicsContainer.Elements.Add(element);
                                    _doc.FocusMap.Display.GraphicsContainer.SelectedElements.Add(element);
                                }
                            }
                        }
                    }

                    if (_doc.Application is IMapApplication)
                    {
                        ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.Graphics);
                    }
                }
                if (_context != null && _context.Count == 1)
                {
                    IExplorerObjectContentDragDropEvents ddEvents = _context[0] as IExplorerObjectContentDragDropEvents;
                    _context = null;
                    if (ddEvents == null)
                    {
                        return;
                    }

                    IDataObject iData = Clipboard.GetDataObject();
                    if (iData == null)
                    {
                        return;
                    }

                    if (_exapp != null && _exapp.InvokeRequired)
                    {
                    }
                    else
                    {
                        foreach (string format in iData.GetFormats())
                        {
                            object ob = iData.GetData(format);
                            if (ob is List <IExplorerObjectSerialization> )
                            {
                                DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                                ddEvents.Content_DragDrop(e);
                            }
                        }

                        if (_exapp != null)
                        {
                            _exapp.RefreshContents();
                        }
                    }
                }
                else if (_exapp != null && _exapp.SelectedObjects != null && _exapp.SelectedObjects.Count == 1)
                {
                    IExplorerObjectContentDragDropEvents ddEvents = null;
                    // Try some times -> await all async treenode events after copy to:   I hate async windows programming!!!
                    for (int i = 0; i < 5; i++)
                    {
                        ddEvents = _exapp.SelectedObjects[0] as IExplorerObjectContentDragDropEvents;
                        if (ddEvents == null)
                        {
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (ddEvents == null)
                    {
                        return;
                    }

                    if (_exapp.InvokeRequired)
                    {
                        _exapp.Invoke((MethodInvoker) delegate
                        {
                            IDataObject iData = Clipboard.GetDataObject();
                            if (iData == null)
                            {
                                return;
                            }

                            foreach (string format in iData.GetFormats())
                            {
                                object ob = iData.GetData(format);
                                if (ob is IEnumerable <IExplorerObjectSerialization> )
                                {
                                    DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                                    ddEvents.Content_DragDrop(e);
                                }
                            }
                            _exapp.RefreshContents();
                        });
                    }
                    else
                    {
                        IDataObject iData = Clipboard.GetDataObject();
                        if (iData == null)
                        {
                            return;
                        }

                        foreach (string format in iData.GetFormats())
                        {
                            object ob = iData.GetData(format);
                            if (ob is IEnumerable <IExplorerObjectSerialization> )
                            {
                                DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                                ddEvents.Content_DragDrop(e);
                            }
                        }
                        _exapp.RefreshContents();
                    }
                }
            }
            finally
            {
                if (_exapp != null)
                {
                    _exapp.SetCursor(Cursors.Default);
                }
            }
        }
Beispiel #3
0
        private void OnEvent()
        {
            if (_doc != null && _doc.FocusMap != null && _doc.FocusMap.Display != null)
            {
                IDataObject iData = Clipboard.GetDataObject();
                if (iData == null)
                {
                    return;
                }

                foreach (string format in iData.GetFormats())
                {
                    if (!format.Contains("gView.Plugins.MapTools.ExtensionSerializer") &&
                        !format.Contains("gView.Framework.system.ExplorerObjectSerialization") &&
                        !format.Contains("gView.Framework.UI.IExplorerObjectSerialization"))
                    {
                        continue;
                    }

                    object ob = iData.GetData(format);
                    if (ob is IEnumerable <ExtensionSerializer> )
                    {
                        foreach (ExtensionSerializer ser in (IEnumerable <ExtensionSerializer>)ob)
                        {
                            object extension = ser.Object;

                            if (extension is IGraphicElement2)
                            {
                                IGraphicElement2 element = extension as IGraphicElement2;

                                if (element.Geometry != null)
                                {
                                    Point point = new Point(
                                        (_doc.FocusMap.Display.Envelope.minx + _doc.FocusMap.Display.Envelope.maxx) / 2.0 - (element.Geometry.Envelope.Width) / 2.0,
                                        (_doc.FocusMap.Display.Envelope.miny + _doc.FocusMap.Display.Envelope.maxy) / 2.0 - (element.Geometry.Envelope.Height) / 2.0);

                                    element.Translation(point.X, point.Y);
                                }
                                _doc.FocusMap.Display.GraphicsContainer.Elements.Add(element);
                                _doc.FocusMap.Display.GraphicsContainer.SelectedElements.Add(element);
                            }
                        }
                    }
                }

                if (_doc.Application is IMapApplication)
                {
                    ((IMapApplication)_doc.Application).RefreshActiveMap(DrawPhase.Graphics);
                }
            }
            if (_context != null && _context.Count == 1)
            {
                IExplorerObjectContentDragDropEvents ddEvents = _context[0] as IExplorerObjectContentDragDropEvents;
                _context = null;
                if (ddEvents == null)
                {
                    return;
                }

                IDataObject iData = Clipboard.GetDataObject();
                if (iData == null)
                {
                    return;
                }

                foreach (string format in iData.GetFormats())
                {
                    object ob = iData.GetData(format);
                    if (ob is List <IExplorerObjectSerialization> )
                    {
                        DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                        ddEvents.Content_DragDrop(e);
                    }
                }

                if (_exapp != null)
                {
                    _exapp.RefreshContents();
                }
            }
            else if (_exapp != null && _exapp.SelectedObjects != null && _exapp.SelectedObjects.Count == 1)
            {
                IExplorerObjectContentDragDropEvents ddEvents = _exapp.SelectedObjects[0] as IExplorerObjectContentDragDropEvents;
                if (ddEvents == null)
                {
                    return;
                }

                IDataObject iData = Clipboard.GetDataObject();
                if (iData == null)
                {
                    return;
                }

                foreach (string format in iData.GetFormats())
                {
                    object ob = iData.GetData(format);
                    if (ob is IEnumerable <IExplorerObjectSerialization> )
                    {
                        DragEventArgs e = new DragEventArgs(iData, 0, 0, 0, DragDropEffects.Copy, DragDropEffects.Copy);
                        ddEvents.Content_DragDrop(e);
                    }
                }
                _exapp.RefreshContents();
            }
        }