Beispiel #1
0
        /// <summary>
        /// Provides core functionality for all the <see cref="M:System.Windows.Forms.Design.ParentControlDesigner.CreateTool(System.Drawing.Design.ToolboxItem)" /> methods.
        /// </summary>
        /// <param name="tool">The <see cref="T:System.Drawing.Design.ToolboxItem" /> to create a component from.</param>
        /// <param name="x">The horizontal position, in design-time view coordinates, of the location of the left edge of the tool, if a size is specified; the horizontal position of the center of the tool, if no size is specified.</param>
        /// <param name="y">The vertical position, in design-time view coordinates, of the location of the top edge of the tool, if a size is specified; the vertical position of the center of the tool, if no size is specified.</param>
        /// <param name="width">The width of the tool. This parameter is ignored if the <paramref name="hasSize" /> parameter is set to false.</param>
        /// <param name="height">The height of the tool. This parameter is ignored if the <paramref name="hasSize" /> parameter is set to false.</param>
        /// <param name="hasLocation">true if a location for the component is specified; false if the component is to be positioned in the center of the currently selected control.</param>
        /// <param name="hasSize">true if a size for the component is specified; false if the default height and width values for the component are to be used.</param>
        /// <returns>An array of components created from the tool.</returns>
        /// <exception cref="System.ArgumentException"></exception>
        protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
        {
            TabList       control;
            IDesignerHost host;

            control = this.TabListControl;

            // prevent controls from being created directly on the TabList
            if (control.SelectedPage == null)
            {
                throw new ArgumentException(string.Format("Cannot add control '{0}', no page is selected.", tool.DisplayName));
            }

            host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
            if (host != null)
            {
                ParentControlDesigner childDesigner;

                childDesigner = (ParentControlDesigner)host.GetDesigner(control.SelectedPage);

                // add controls onto the TabListPage control instead of the TabList
                ParentControlDesigner.InvokeCreateTool(childDesigner, tool);
            }

            return(null);
        }
        // parent null denodes parenting to the root component
        //
        public Control CreateControl(Type controlType, Control parent)
        {
            if (_surface == null)
            {
                throw new Exception("Helper designer surface not initialized.");
            }

            if (parent == null)
            {
                parent = IDesignerHost.RootComponent as Control;
            }

            ParentControlDesigner parentDesigner = IDesignerHost.GetDesigner(parent) as ParentControlDesigner;

            if (parentDesigner == null)
            {
                throw new Exception("parent is not handled by a ParentControlDesigner.");
            }

            ToolboxItem tbItem = new ToolboxItem(controlType);

            tbItem.ComponentsCreated += new ToolboxComponentsCreatedEventHandler(OnToolboxComponentCreated);
            tbItem.CreateComponents(this.IDesignerHost);
            parent.Controls.Add(_parentedControl);
            tbItem.ComponentsCreated -= new ToolboxComponentsCreatedEventHandler(OnToolboxComponentCreated);
            return(_parentedControl);
        }
Beispiel #3
0
    protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
    {
        ParentControlDesigner panelDesigner = this.designerHost.GetDesigner(((MyUserControl)Control).PanelContent) as ParentControlDesigner;

        InvokeCreateTool(panelDesigner, tool);
        return(null);
    }
        public void CreateToolTest()
        {
            // essentially a DesignerTestHelper.CreateControl test, because of the code I use there
            ParentControlDesigner rootPanel  = (ParentControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestPanel), null));
            ParentControlDesigner childPanel = (ParentControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestPanel), rootPanel.Control));

            Assert.IsNotNull(rootPanel, "#1");
            Assert.IsNotNull(childPanel, "#2");
        }
Beispiel #5
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="p"></param>
 public CanParentProvider(ParentControlDesigner p)
 {
     this.parentControlDesigner = p;
     container = p.Component as ICanParent;
     if (container == null && p.Control != null)
     {
         container = p.Control.Parent as ICanParent;
     }
 }
Beispiel #6
0
		protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
		{
			if(this.Selected==null)
			{
				this.Selected=this.collapsibleContainerPanel;
			}
			CollapsibleContainerPanelDesigner toInvoke=(CollapsibleContainerPanelDesigner)this.designerHost.GetDesigner(this.Selected);
			ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
			return null;
		}
Beispiel #7
0
        protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
        {
            WizardPageDesigner pageDes = GetSelectedWizardPageDesigner();

            if (pageDes != null)
            {
                ParentControlDesigner.InvokeCreateTool(pageDes, tool);
            }
            return(null);
        }
Beispiel #8
0
        internal DesignerHost(BrowserTree objTree, Panel imagePanel)
        {
            _imagePanel = imagePanel;
            if (_host == null)
            {
                _host             = this;
                _serviceContainer = new ServiceContainer();
                _serviceContainer.AddService(typeof(IDesignerHost), _host);
                _serviceContainer.AddService(typeof(IUIService), _host);
                _serviceContainer.AddService(typeof(ISelectionService), _host);
                _serviceContainer.AddService(typeof(IToolboxService), new ToolboxService());
            }

            _container   = new DesignerContainer(this);
            _defaultSite = new DesignerSite(this, null, _container, "Default site");

            _designSurfaceSite = (DesignerSite)_container.CreateSite(_imagePanel, "Design Surface");

            // Hook the design surface to the ParentControlDesigner
            _parentControlDesigner      = new DummyDesigner();
            _imagePanel.Site            = _designSurfaceSite;
            _designSurfaceSite.Designer = _parentControlDesigner;
            _parentControlDesigner.Initialize(_imagePanel);

            // Used to make sure we don't give a designer for anything higher
            // than the design surface (GetDesigner is called on the
            // surface's parent)
            _designSurfaceParent = ((Control)_imagePanel).Parent;

            // Get the type for the UI selection service, since its private
            // the compiler will not let us see it
            _typeISelectionUIService = ReflectionHelper.GetType("System.Windows.Forms.Design.ISelectionUIService");

            // This is required to get an instance of the selection
            // UI service installed, we don't actually use this
            // designer for anything
            _fakePanel = new Panel();
            IDesigner compDes = new ComponentDocumentDesigner();

            _fakePanel.Site = _container.CreateSite(_fakePanel, "Fake Design Surface");
            compDes.Initialize(_fakePanel);

            // Make the size of the selection service cover the design
            // surface panel so that it will see all of the events
            _selUIService = (Control)GetService(_typeISelectionUIService);
            ObjectBrowser.ImagePanel.ResetSize(_selUIService);
            _imagePanel.Controls.Add(_selUIService);
            _imagePanel.SizeChanged += new EventHandler(ImagePanelSizeChange);

            DesignMode = true;

            // So we change the object selected when a control is selected
            SelectionChanged += new EventHandler(objTree.ControlSelectionChanged);
        }
Beispiel #9
0
        public override void OnDragDrop(Glyph g, DragEventArgs e)
        {
            System.Windows.Forms.Design.Behavior.ControlBodyGlyph cbg = g as System.Windows.Forms.Design.Behavior.ControlBodyGlyph;
            IToolboxService   tbsvc  = designerHost.GetService(typeof(IToolboxService)) as IToolboxService;
            ISelectionService selsvc = designerHost.GetService(typeof(ISelectionService)) as ISelectionService;

            if (cbg != null && cbg.RelatedComponent != null && cbg.RelatedComponent is Control)
            {
                ToolboxItem item = e.Data.GetData(typeof(ToolboxItem)) as ToolboxItem;

                IToolboxUser tbu = designerHost.GetDesigner(designerHost.RootComponent) as IToolboxUser;

                (designerHost.RootComponent as Control).SuspendLayout();

                tbu.ToolPicked(item);

                if (selsvc.PrimarySelection != null && selsvc.PrimarySelection is Control)
                {
                    Control createdControl = selsvc.PrimarySelection as Control;

                    PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(createdControl)["Parent"];
                    //获取粘贴到的父容器
                    ParentControlDesigner parentDesigner = null;
                    parentDesigner = designerHost.GetDesigner(cbg.RelatedComponent) as ParentControlDesigner;
                    if (parentDesigner == null)
                    {
                        parentDesigner = designerHost.GetDesigner(designerHost.RootComponent) as DocumentDesigner;
                    }

                    if (parentDesigner != null && parentDesigner.CanParent(createdControl))
                    {
                        parentProperty.SetValue(createdControl, parentDesigner.Control);

                        Point p1 = bhsvc.AdornerWindowToScreen();
                    }

                    tbsvc.SelectedToolboxItemUsed();


                    Point adroP = bhsvc.AdornerWindowToScreen();

                    createdControl.Left = e.X - adroP.X - (cbg.RelatedComponent as Control).Left;
                    createdControl.Top  = e.Y - adroP.Y - (cbg.RelatedComponent as Control).Top;
                }

                (designerHost.RootComponent as Control).ResumeLayout();
            }

            bhsvc.PopBehavior(this);
        }
        public void CanParentTest()
        {
            ParentControlDesigner rootPanel        = (ParentControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestPanel), null));
            ParentControlDesigner childPanel       = (ParentControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestPanel), rootPanel.Control));
            ControlDesigner       childPanelButton = (ControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestButton), childPanel.Control));
            ControlDesigner       rootPanelButton  = (ControlDesigner)_helper.IDesignerHost.GetDesigner(_helper.CreateControl(typeof(TestButton), rootPanel.Control));

            Assert.IsFalse(childPanel.CanParent((Control)_helper.IDesignerHost.RootComponent), "#1");
            Assert.IsTrue(childPanel.CanParent(childPanel), "#2");
            Assert.IsTrue(childPanel.CanParent(childPanelButton), "#3");
            Assert.IsTrue(childPanel.CanParent(rootPanelButton), "#4");
            Assert.IsFalse(childPanel.CanParent(rootPanel), "#5");
            Assert.IsTrue(rootPanel.CanParent(childPanel), "#6");
            Assert.IsTrue(rootPanel.CanParent(rootPanelButton), "#7");
        }
Beispiel #11
0
        protected override IComponent[] CreateToolCore(ToolboxItem tool, int x, int y, int width, int height, bool hasLocation, bool hasSize)
        {
            TabControl control = (TabControl)this.Control;

            if (control.SelectedTab == null)
            {
                throw new ArgumentException("TabControlInvalidTabPageType");
            }
            IDesignerHost service = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (service != null)
            {
                TabPageDesigner toInvoke = (TabPageDesigner)service.GetDesigner(control.SelectedTab);
                ParentControlDesigner.InvokeCreateTool(toInvoke, tool);
            }
            return(null);
        }
Beispiel #12
0
        private void EndDragDrop(bool allowSetChildIndexOnDrop)
        {
            Control target = this.data.Target as Control;

            if (target != null)
            {
                if (this.serviceProviderTarget == null)
                {
                    this.serviceProviderTarget = target.Site;
                    if (this.serviceProviderTarget == null)
                    {
                        return;
                    }
                }
                if (this.destHost == null)
                {
                    this.destHost = (IDesignerHost)this.serviceProviderTarget.GetService(typeof(IDesignerHost));
                    if (this.destHost == null)
                    {
                        return;
                    }
                }
                if (this.behaviorServiceTarget == null)
                {
                    this.behaviorServiceTarget = (BehaviorService)this.serviceProviderTarget.GetService(typeof(BehaviorService));
                    if (this.behaviorServiceTarget == null)
                    {
                        return;
                    }
                }
                ArrayList               list        = null;
                bool                    flag        = this.lastEffect == DragDropEffects.Copy;
                Control                 source      = this.data.Source;
                bool                    localDrag   = source.Equals(target);
                PropertyDescriptor      member      = TypeDescriptor.GetProperties(target)["Controls"];
                PropertyDescriptor      descriptor2 = TypeDescriptor.GetProperties(source)["Controls"];
                IComponentChangeService service     = (IComponentChangeService)this.serviceProviderSource.GetService(typeof(IComponentChangeService));
                IComponentChangeService service2    = (IComponentChangeService)this.serviceProviderTarget.GetService(typeof(IComponentChangeService));
                if (this.dragAssistanceManager != null)
                {
                    this.dragAssistanceManager.OnMouseUp();
                }
                ISelectionService service3 = null;
                if (flag || ((this.srcHost != this.destHost) && (this.destHost != null)))
                {
                    service3 = (ISelectionService)this.serviceProviderTarget.GetService(typeof(ISelectionService));
                }
                try
                {
                    if ((this.dragComponents != null) && (this.dragComponents.Length > 0))
                    {
                        string str;
                        DesignerTransaction transaction  = null;
                        DesignerTransaction transaction2 = null;
                        if (this.dragComponents.Length == 1)
                        {
                            string componentName = TypeDescriptor.GetComponentName(this.dragComponents[0].dragComponent);
                            if ((componentName == null) || (componentName.Length == 0))
                            {
                                componentName = this.dragComponents[0].dragComponent.GetType().Name;
                            }
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControl" : "BehaviorServiceMoveControl", new object[] { componentName });
                        }
                        else
                        {
                            str = System.Design.SR.GetString(flag ? "BehaviorServiceCopyControls" : "BehaviorServiceMoveControls", new object[] { this.dragComponents.Length });
                        }
                        if ((this.srcHost != null) && (((this.srcHost == this.destHost) || (this.destHost == null)) || !flag))
                        {
                            transaction = this.srcHost.CreateTransaction(str);
                        }
                        if ((this.srcHost != this.destHost) && (this.destHost != null))
                        {
                            transaction2 = this.destHost.CreateTransaction(str);
                        }
                        try
                        {
                            ComponentTray tray = null;
                            int           num  = 0;
                            if (flag)
                            {
                                tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                num  = (tray != null) ? tray.Controls.Count : 0;
                                ArrayList objects = new ArrayList();
                                for (int j = 0; j < this.dragComponents.Length; j++)
                                {
                                    objects.Add(this.dragComponents[j].dragComponent);
                                }
                                objects = DesignerUtils.CopyDragObjects(objects, this.serviceProviderTarget) as ArrayList;
                                if (objects == null)
                                {
                                    return;
                                }
                                list = new ArrayList();
                                for (int k = 0; k < objects.Count; k++)
                                {
                                    list.Add(this.dragComponents[k].dragComponent);
                                    this.dragComponents[k].dragComponent = objects[k];
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanging(target, member);
                                if (!flag)
                                {
                                    service.OnComponentChanging(source, descriptor2);
                                }
                            }
                            int num4 = ParentControlDesigner.DetermineTopChildIndex(target);
                            this.DropControl(this.primaryComponentIndex, target, source, localDrag);
                            Point p = this.behaviorServiceSource.AdornerWindowPointToScreen(this.dragComponents[this.primaryComponentIndex].draggedLocation);
                            p = ((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.PointToClient(p);
                            if (((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Parent.IsMirrored)
                            {
                                p.Offset(-((Control)this.dragComponents[this.primaryComponentIndex].dragComponent).Width, 0);
                            }
                            Control            dragComponent = this.dragComponents[this.primaryComponentIndex].dragComponent as Control;
                            PropertyDescriptor descriptor3   = TypeDescriptor.GetProperties(dragComponent)["Location"];
                            if ((dragComponent != null) && (descriptor3 != null))
                            {
                                try
                                {
                                    service2.OnComponentChanging(dragComponent, descriptor3);
                                }
                                catch (CheckoutException exception)
                                {
                                    if (exception != CheckoutException.Canceled)
                                    {
                                        throw;
                                    }
                                    return;
                                }
                            }
                            this.SetLocationPropertyAndChildIndex(this.primaryComponentIndex, target, p, this.shareParent ? (num4 + this.dragComponents[this.primaryComponentIndex].zorderIndex) : num4, allowSetChildIndexOnDrop);
                            if (service3 != null)
                            {
                                service3.SetSelectedComponents(new object[] { this.dragComponents[this.primaryComponentIndex].dragComponent }, SelectionTypes.Click | SelectionTypes.Replace);
                            }
                            for (int i = 0; i < this.dragComponents.Length; i++)
                            {
                                if (i != this.primaryComponentIndex)
                                {
                                    this.DropControl(i, target, source, localDrag);
                                    Point dropPoint = new Point(p.X + this.dragComponents[i].positionOffset.X, p.Y + this.dragComponents[i].positionOffset.Y);
                                    this.SetLocationPropertyAndChildIndex(i, target, dropPoint, this.shareParent ? (num4 + this.dragComponents[i].zorderIndex) : num4, allowSetChildIndexOnDrop);
                                    if (service3 != null)
                                    {
                                        service3.SetSelectedComponents(new object[] { this.dragComponents[i].dragComponent }, SelectionTypes.Add);
                                    }
                                }
                            }
                            if ((!localDrag || flag) && ((service != null) && (service2 != null)))
                            {
                                service2.OnComponentChanged(target, member, target.Controls, target.Controls);
                                if (!flag)
                                {
                                    service.OnComponentChanged(source, descriptor2, source.Controls, source.Controls);
                                }
                            }
                            if (list != null)
                            {
                                for (int m = 0; m < list.Count; m++)
                                {
                                    this.dragComponents[m].dragComponent = list[m];
                                }
                                list = null;
                            }
                            if (flag)
                            {
                                if (tray == null)
                                {
                                    tray = this.serviceProviderTarget.GetService(typeof(ComponentTray)) as ComponentTray;
                                }
                                if (tray != null)
                                {
                                    int num7 = tray.Controls.Count - num;
                                    if (num7 > 0)
                                    {
                                        ArrayList components = new ArrayList();
                                        for (int n = 0; n < num7; n++)
                                        {
                                            components.Add(tray.Controls[num + n]);
                                        }
                                        tray.UpdatePastePositions(components);
                                    }
                                }
                            }
                            this.CleanupDrag(false);
                            if (transaction != null)
                            {
                                transaction.Commit();
                                transaction = null;
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Commit();
                                transaction2 = null;
                            }
                        }
                        finally
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            if (transaction2 != null)
                            {
                                transaction2.Cancel();
                            }
                        }
                    }
                }
                finally
                {
                    if (list != null)
                    {
                        for (int num9 = 0; num9 < list.Count; num9++)
                        {
                            this.dragComponents[num9].dragComponent = list[num9];
                        }
                    }
                    this.CleanupDrag(false);
                    if (this.statusCommandUITarget != null)
                    {
                        this.statusCommandUITarget.SetStatusInformation((service3 == null) ? (this.dragComponents[this.primaryComponentIndex].dragComponent as Component) : (service3.PrimarySelection as Component));
                    }
                }
                this.lastFeedbackLocation = new Point(-1, -1);
            }
        }
Beispiel #13
0
        /// <summary>
        /// 粘贴
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void Paste(object sender, EventArgs args)
        {
            IDesignerSerializationService serialService = this.GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService;
            IDesignerHost           host          = GetService(typeof(IDesignerHost)) as IDesignerHost;
            ISelectionService       selection     = GetService(typeof(ISelectionService)) as ISelectionService;
            IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (host == null || serialService == null || clipboardData == null)
            {
                return;
            }

            //从获取上次剪切/复制的数据并反序列化
            ICollection components = serialService.Deserialize(clipboardData);

            //如果当前选中的控件是容器控件则添加到容器中
            //否则添加到根设计器中
            if (components != null && components.Count > 0)
            {
                DesignerTransaction transaction = host.CreateTransaction("Paste");

                foreach (Component item in components)
                {
                    Control control = item as Control;
                    if (control == null)
                    {
                        continue;
                    }

                    //if (control is IDBColProperty)
                    //{
                    //    (control as IDBColProperty).DBColName = string.Empty;
                    //}

                    PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(control)["Parent"];

                    //获取粘贴到的父容器
                    ParentControlDesigner parentDesigner = null;
                    if (selection != null && selection.PrimarySelection != null)
                    {
                        parentDesigner = host.GetDesigner((IComponent)selection.PrimarySelection) as ParentControlDesigner;
                    }

                    if (parentDesigner == null)
                    {
                        parentDesigner = host.GetDesigner(host.RootComponent) as DocumentDesigner;
                    }

                    if (parentDesigner != null && parentDesigner.CanParent(control))
                    {
                        //粘贴时粘贴到父容器中间
                        //control.Location = new Point(parentDesigner.Control.Width / 2 - control.Width / 2, parentDesigner.Control.Height / 2 - control.Height / 2);
                        parentProperty.SetValue(control, parentDesigner.Control);
                    }
                }

                clipboardData = null;
                transaction.Commit();
                ((IDisposable)transaction).Dispose();

                selection.SetSelectedComponents(components);
                this.GlobalInvoke(StandardCommands.BringToFront);
            }
        }
		// Called by the parent ParentControlDesigner when it is populating the grid-related
		// design-time properties changes
		//
		private void OnParentGridPropertiesChanged (ParentControlDesigner parentDesigner)
		{
			SetValue (this.Component, "DrawGrid", (bool) GetValue (parentDesigner.Component, "DrawGrid"));
			SetValue (this.Component, "SnapToGrid", (bool) GetValue (parentDesigner.Component, "SnapToGrid"));
			SetValue (this.Component, "GridSize", (Size) GetValue (parentDesigner.Component, "GridSize"));

			// Set also the default values to be those, because we should
			// match the parent ParentControlDesigner values.
			// called recursivly, so I will rather go for slower, but no stack-overflowable code
			// 
			_defaultDrawGrid = (bool) GetValue (parentDesigner.Component, "DrawGrid");
			_defaultSnapToGrid = (bool) GetValue (parentDesigner.Component, "SnapToGrid");
			_defaultGridSize = (Size) GetValue (parentDesigner.Component, "GridSize");

			this.PopulateGridProperties ();
		}
		// This is the code that is executed when you drop a tool from the Toolbox in the designer.
		//

		protected static void InvokeCreateTool (ParentControlDesigner toInvoke, ToolboxItem tool)
		{
			if (toInvoke != null)
				toInvoke.CreateTool (tool);
		}
Beispiel #16
0
        // Reminder: We set control.Parent so that it gets serialized for Undo/Redo
        //
        private void Paste(object sender, EventArgs args)
        {
            IDesignerSerializationService stateSerializer = GetService(typeof(IDesignerSerializationService)) as IDesignerSerializationService;
            ISelectionService             selection       = GetService(typeof(ISelectionService)) as ISelectionService;
            IDesignerHost           host          = GetService(typeof(IDesignerHost)) as IDesignerHost;
            IComponentChangeService changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            if (host == null || stateSerializer == null)
            {
                return;
            }
            //
            // TODO: MWF X11 doesn't seem to support custom clipboard formats - bug #357642
            //
            // IDataObject dataObject = Clipboard.GetDataObject ();
            // byte[] data = dataObject == null ? null : dataObject.GetData (DT_DATA_FORMAT) as byte[];
            // if (data != null) {
            //  MemoryStream stream = new MemoryStream (data);
            //  stateSerializer.Deserialize (new BinaryFormatter().Deserialize (stream));
            // .....
            // }
            //
            if (_clipboard == null)
            {
                return;
            }

            DesignerTransaction transaction = host.CreateTransaction("Paste");
            ICollection         components  = stateSerializer.Deserialize(_clipboard);

            // Console.WriteLine ("Pasted components: ");
            // foreach (object c in components)
            //  Console.WriteLine (((IComponent)c).Site.Name);
            System.Collections.Generic.List <object> sel = new System.Collections.Generic.List <object>(components.Count);
            foreach (object component in components)
            {
                sel.Add(component);
                Control control = component as Control;
                if (control == null)
                {
                    continue;                     // pure Components are added to the ComponentTray by the DocumentDesigner
                }
                PropertyDescriptor parentProperty = TypeDescriptor.GetProperties(control)["Parent"];
                if (control.Parent != null)
                {
                    // Already parented during deserialization?
                    // In that case explicitly raise component changing/ed for the Parent property,
                    // so it get's cought by the UndoEngine
                    if (changeService != null)
                    {
                        changeService.OnComponentChanging(control, parentProperty);
                        changeService.OnComponentChanged(control, parentProperty, null, control.Parent);
                    }
                }
                else
                {
                    ParentControlDesigner parentDesigner = null;
                    if (selection != null && selection.PrimarySelection != null)
                    {
                        parentDesigner = host.GetDesigner((IComponent)selection.PrimarySelection) as ParentControlDesigner;
                    }
                    if (parentDesigner == null)
                    {
                        parentDesigner = host.GetDesigner(host.RootComponent) as DocumentDesigner;
                    }
                    if (parentDesigner != null && parentDesigner.CanParent(control))
                    {
                        parentProperty.SetValue(control, parentDesigner.Control);
                        control.Name = null;
                        (host as IContainer).Add(control);
                        (host as SampleDesignerHost).AddDesignedComponent(control);
                        //parentDesigner.Control.Controls.Add(control);
                    }
                }
            }
            //_clipboard = null;
            //(host as SampleDesignerHost).SetSelectedComponents(components.);
            selection.SetSelectedComponents(sel.ToArray(), SelectionTypes.Primary);
            transaction.Commit();
            ((IDisposable)transaction).Dispose();
        }
Beispiel #17
0
        /// <summary>
        /// Return true if the dragged component is toolbox Item
        /// </summary>
        /// <returns></returns>
#if !PocketPC
        public static bool GetIsDroppedFromToolbox(ParentControlDesigner designer)
        {
            FieldInfo fi = typeof(ParentControlDesigner).GetField("mouseDragTool", BindingFlags.Instance | BindingFlags.NonPublic);

            return(fi.GetValue(designer) is ToolboxItem);
        }