예제 #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost));
         if (host != null)
         {
             host.RemoveService(typeof(IInheritanceService));
             host.RemoveService(typeof(IEventHandlerService));
             host.RemoveService(typeof(ISelectionUIService));
             host.RemoveService(typeof(ComponentTray));
             IComponentChangeService service = (IComponentChangeService)this.GetService(typeof(IComponentChangeService));
             if (service != null)
             {
                 service.ComponentAdded   -= new ComponentEventHandler(this.OnComponentAdded);
                 service.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
             }
         }
         if (this.selectionUIService != null)
         {
             this.selectionUIService.Dispose();
             this.selectionUIService = null;
         }
         if (this.commandSet != null)
         {
             this.commandSet.Dispose();
             this.commandSet = null;
         }
         if (this.pbrsFwd != null)
         {
             this.pbrsFwd.Dispose();
             this.pbrsFwd = null;
         }
         if (this.compositionUI != null)
         {
             this.compositionUI.Dispose();
             this.compositionUI = null;
         }
         if (this.designerExtenders != null)
         {
             this.designerExtenders.Dispose();
             this.designerExtenders = null;
         }
         if (this.inheritanceService != null)
         {
             this.inheritanceService.Dispose();
             this.inheritanceService = null;
         }
     }
     base.Dispose(disposing);
 }
예제 #2
0
        ///     Disposes the entire selection manager.
        internal void Dispose()
        {
            // We've got to be careful here.  We're one of the last things to go away when
            // a form is being torn down, and we've got to be wary if things have pulled out
            // already.
            host.RemoveService(typeof(ISelectionService));
            host.TransactionOpened -= new EventHandler(this.DesignerHost_TransactionOpened);
            host.TransactionClosed -= new DesignerTransactionCloseEventHandler(this.DesignerHost_TransactionClosed);
            if (host.InTransaction)
            {
                DesignerHost_TransactionClosed(host, new DesignerTransactionCloseEventArgs(true));
            }
            host.LoadComplete -= new EventHandler(this.DesignerHost_LoadComplete);

            IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));

            if (cs != null)
            {
                cs.ComponentAdded   -= new ComponentEventHandler(this.DesignerHost_ComponentAdd);
                cs.ComponentRemoved -= new ComponentEventHandler(this.DesignerHost_ComponentRemove);
                cs.ComponentChanged -= new ComponentChangedEventHandler(this.DesignerHost_ComponentChanged);
            }

            SampleSelectionItem[] sels = new SampleSelectionItem[selectionsByComponent.Values.Count];
            selectionsByComponent.Values.CopyTo(sels, 0);

            for (int i = 0; i < sels.Length; i++)
            {
                sels[i].Dispose();
            }

            selectionsByComponent.Clear();
            primarySelection = null;
        }
예제 #3
0
 // Loads a ButtonDesignerFilterService ITypeDescriptorFilterService
 // to add ColorCycleButtonDesigner designers to each button.
 private void LoadService()
 {
     // If no custom ITypeDescriptorFilterService is loaded,
     // loads it now.
     if (!serviceloaded)
     {
         // Stores the current ITypeDescriptorFilterService
         // to restore later.
         ITypeDescriptorFilterService tdfs = (ITypeDescriptorFilterService)this.Component.Site.GetService(typeof(ITypeDescriptorFilterService));
         if (tdfs != null)
         {
             oldservice = tdfs;
         }
         // Retrieves an IDesignerHost interface to use to
         // remove and add services.
         IDesignerHost dh = (IDesignerHost)this.Component.Site.GetService(typeof(IDesignerHost));
         if (dh == null)
         {
             throw new Exception("Could not obtain IDesignerHost interface.");
         }
         // Removes standard ITypeDescriptorFilterService.
         dh.RemoveService(typeof(ITypeDescriptorFilterService));
         // Adds new custom ITypeDescriptorFilterService.
         dh.AddService(typeof(ITypeDescriptorFilterService), new ButtonDesignerFilterService());
         serviceloaded = true;
     }
 }
예제 #4
0
 public void Dispose()
 {
     if (this.serviceProvider != null)
     {
         IDesignerHost service = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));
         if (service != null)
         {
             service.RemoveService(typeof(DesignerActionUIService));
         }
     }
 }
 /// <summary>
 ///  Disposes all resources and unhooks all events.
 /// </summary>
 public void Dispose()
 {
     if (_serviceProvider != null)
     {
         IDesignerHost host = (IDesignerHost)_serviceProvider.GetService(typeof(IDesignerHost));
         if (host != null)
         {
             host.RemoveService(typeof(DesignerActionUIService));
         }
     }
 }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if ((service == null) || (context.Instance == null))
                {
                    return(value);
                }
                IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost));

                if (host == null)
                {
                    return(value);
                }

                //if (this.dataGridViewColumnCollectionDialog == null)
                //{
                //    this.dataGridViewColumnCollectionDialog = new DataGridViewColumnCollectionDialog(((DataGridView)context.Instance).Site);
                //}

                if (this.dataGridViewColumnCollectionDialog == null)
                {
                    Type type = Type.GetType("System.Windows.Forms.Design.DataGridViewColumnCollectionDialog");

                    this.dataGridViewColumnCollectionDialog = Activator.CreateInstance(
                        type,
                        BindingFlags.Instance | BindingFlags.NonPublic,
                        null,
                        new object[] { provider },
                        CultureInfo.CurrentCulture) as Form;
                }
                //this.dataGridViewColumnCollectionDialog.SetLiveDataGridView((DataGridView)context.Instance);
                MethodInfo methodInfo = this.dataGridViewColumnCollectionDialog.GetType().GetMethod("SetLiveDataGridView", BindingFlags.NonPublic | BindingFlags.Instance);
                methodInfo.Invoke(this.dataGridViewColumnCollectionDialog, new object[] { context.Instance });

                //using (DesignerTransaction transaction = host.CreateTransaction(System.Design.SR.GetString("DataGridViewColumnCollectionTransaction")))
                using (DesignerTransaction transaction = host.CreateTransaction())
                {
                    host.RemoveService(typeof(ITypeDiscoveryService));
                    host.AddService(typeof(ITypeDiscoveryService), new TypeDiscoveryService());
                    ITypeDiscoveryService service2 = (ITypeDiscoveryService)host.GetService(typeof(ITypeDiscoveryService));

                    if (service.ShowDialog(this.dataGridViewColumnCollectionDialog) == DialogResult.OK)
                    {
                        transaction.Commit();
                        return(value);
                    }
                    transaction.Cancel();
                }
            }
            return(value);
        }
        public void SetUpFixture()
        {
            resourceWriter   = new MockResourceWriter();
            componentCreator = new MockComponentCreator();
            componentCreator.SetResourceWriter(resourceWriter);

            resourceWriter2   = new MockResourceWriter();
            componentCreator2 = new MockComponentCreator();
            componentCreator2.SetResourceWriter(resourceWriter2);

            using (DesignSurface designSurface = new DesignSurface(typeof(Form))) {
                IDesignerHost        host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost));
                IEventBindingService eventBindingService = new MockEventBindingService(host);
                host.AddService(typeof(IResourceService), componentCreator);

                Form form = (Form)host.RootComponent;
                form.ClientSize = new Size(200, 300);

                PropertyDescriptorCollection descriptors            = TypeDescriptor.GetProperties(form);
                PropertyDescriptor           namePropertyDescriptor = descriptors.Find("Name", false);
                namePropertyDescriptor.SetValue(form, "MainForm");

                // Add picture box
                PictureBox pictureBox = (PictureBox)host.CreateComponent(typeof(PictureBox), "pictureBox1");
                pictureBox.Location = new Point(0, 0);
                bitmap              = new Bitmap(10, 10);
                pictureBox.Image    = bitmap;
                pictureBox.Size     = new Size(100, 120);
                pictureBox.TabIndex = 0;
                form.Controls.Add(pictureBox);

                // Add bitmap to form.
                form.BackgroundImage = new Bitmap(10, 10);

                DesignerSerializationManager serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    generatedPythonCode = serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }

                // Check that calling the GenerateInitializeComponentMethodBody also generates a resource file.
                host.RemoveService(typeof(IResourceService));
                host.AddService(typeof(IResourceService), componentCreator2);

                serializationManager = new DesignerSerializationManager(host);
                using (serializationManager.CreateSession()) {
                    PythonCodeDomSerializer serializer = new PythonCodeDomSerializer("    ");
                    serializer.GenerateInitializeComponentMethodBody(host, serializationManager, String.Empty, 1);
                }
            }
        }
예제 #8
0
        // Removes the custom service and reloads any stored,
        // preexisting service.
        private void RemoveService()
        {
            IDesignerHost dh = (IDesignerHost)this.GetService(typeof(IDesignerHost));

            if (dh == null)
            {
                throw new Exception("Could not obtain IDesignerHost interface.");
            }
            dh.RemoveService(typeof(ITypeDescriptorFilterService));
            if (oldservice != null)
            {
                dh.AddService(typeof(ITypeDescriptorFilterService), oldservice);
            }
            serviceloaded = false;
        }
예제 #9
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing && (this.serviceProvider != null))
     {
         IDesignerHost host = (IDesignerHost)this.serviceProvider.GetService(typeof(IDesignerHost));
         if (host != null)
         {
             host.RemoveService(typeof(DesignerActionService));
         }
         IComponentChangeService service = (IComponentChangeService)this.serviceProvider.GetService(typeof(IComponentChangeService));
         if (service != null)
         {
             service.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemoved);
         }
     }
 }
예제 #10
0
        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);

            IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

            if (host == null)
            {
                return;
            }

            IInheritanceService inheritanceService = (IInheritanceService)GetService(typeof(IInheritanceService));

            m_inheritanceService = new InlineInheritanceService(this, inheritanceService);
            host.RemoveService(typeof(IInheritanceService));
            host.AddService(typeof(IInheritanceService), m_inheritanceService);
        }
예제 #11
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && _serviceProvider != null)
            {
                IDesignerHost host = (IDesignerHost)_serviceProvider.GetService(typeof(IDesignerHost));
                if (host != null)
                {
                    host.RemoveService(typeof(DesignerActionService));
                }

                IComponentChangeService cs = (IComponentChangeService)_serviceProvider.GetService(typeof(IComponentChangeService));
                if (cs != null)
                {
                    cs.ComponentRemoved -= new ComponentEventHandler(OnComponentRemoved);
                }
            }
        }
        private void DesignMdiController_DesignPanelLoaded(object sender, DevExpress.XtraReports.UserDesigner.DesignerLoadedEventArgs e)
        {
            XRDesignPanel panel = (XRDesignPanel)sender;

            if (panel == null)
            {
                return;
            }
            IDesignerHost host = panel.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (host == null)
            {
                return;
            }
            ITypeDescriptorFilterService serv = host.GetService(typeof(ITypeDescriptorFilterService)) as ITypeDescriptorFilterService;

            host.RemoveService(typeof(ITypeDescriptorFilterService));
            host.AddService(typeof(ITypeDescriptorFilterService), new TypeDescriptorFilterService(serv));
        }
예제 #13
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
         if (host != null)
         {
             if (m_inheritanceService != null)
             {
                 host.RemoveService(typeof(IInheritanceService));
                 if (m_inheritanceService.m_parentService != null)
                 {
                     host.AddService(typeof(IInheritanceService), m_inheritanceService.m_parentService);
                 }
                 m_inheritanceService.Dispose();
                 m_inheritanceService = null;
             }
         }
     }
     base.Dispose(disposing);
 }
예제 #14
0
        /// <include file='doc\SelectionService.uex' path='docs/doc[@for="SelectionService.Dispose"]/*' />
        /// <devdoc>
        ///     Disposes the entire selection manager.
        /// </devdoc>
        public void Dispose()
        {
            // We've got to be careful here.  We're one of the last things to go away when
            // a form is being torn down, and we've got to be wary if things have pulled out
            // already.
            //
            host.RemoveService(typeof(ISelectionService));
            host.TransactionOpened -= new EventHandler(this.OnTransactionOpened);
            host.TransactionClosed -= new DesignerTransactionCloseEventHandler(this.OnTransactionClosed);
            if (host.InTransaction)
            {
                OnTransactionClosed(host, new DesignerTransactionCloseEventArgs(true));
            }
            host.LoadComplete -= new EventHandler(this.OnLoadComplete);

            // And configure the events we want to listen to.
            //
            IComponentChangeService cs = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));

            Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || cs != null, "IComponentChangeService not found");
            if (cs != null)
            {
                cs.ComponentAdded   -= new ComponentEventHandler(this.OnComponentAdd);
                cs.ComponentRemoved -= new ComponentEventHandler(this.OnComponentRemove);
                cs.ComponentChanged -= new ComponentChangedEventHandler(this.OnComponentChanged);
            }

            SelectionItem[] sels = new SelectionItem[selectionsByComponent.Values.Count];
            selectionsByComponent.Values.CopyTo(sels, 0);

            for (int i = 0; i < sels.Length; i++)
            {
                sels[i].Dispose();
            }

            selectionsByComponent.Clear();
            primarySelection = null;
        }
        // Remove the Service when the last toolStrip is removed.
        private void OnComponentRemoved(object sender, ComponentEventArgs e)
        {
            bool toolStripPresent     = false;
            ComponentCollection comps = _designerHost.Container.Components;

            foreach (IComponent comp in comps)
            {
                if (comp is ToolStrip)
                {
                    toolStripPresent = true;
                    break;
                }
            }
            if (!toolStripPresent)
            {
                ToolStripInSituService inSituService = (ToolStripInSituService)_sp.GetService(typeof(ISupportInSituService));
                if (inSituService != null)
                {
                    //since we are going away .. restore the old commands.
                    _designerHost.RemoveService(typeof(ISupportInSituService));
                }
            }
        }
예제 #16
0
        /// <include file='doc\CompositionDesigner.uex' path='docs/doc[@for="ComponentDocumentDesigner.Dispose"]/*' />
        /// <devdoc>
        ///    <para>Disposes of the resources (other than memory) used by
        ///       the <see cref='System.Windows.Forms.Design.ComponentDocumentDesigner'/>.</para>
        /// </devdoc>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
                Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || host != null, "IDesignerHost not found");

                if (host != null)
                {
                    host.RemoveService(typeof(IInheritanceService));
                    host.RemoveService(typeof(IEventHandlerService));
                    host.RemoveService(typeof(ISelectionUIService));
                    host.RemoveService(typeof(ComponentTray));

                    IComponentChangeService cs = (IComponentChangeService)GetService(typeof(IComponentChangeService));
                    Debug.Assert(!CompModSwitches.CommonDesignerServices.Enabled || cs != null, "IComponentChangeService not found");
                    if (cs != null)
                    {
                        cs.ComponentAdded   -= new ComponentEventHandler(OnComponentAdded);
                        cs.ComponentRemoved -= new ComponentEventHandler(OnComponentRemoved);
                    }
                }

                if (selectionUIService != null)
                {
                    selectionUIService.Dispose();
                    selectionUIService = null;
                }

                if (commandSet != null)
                {
                    commandSet.Dispose();
                    commandSet = null;
                }

                if (this.pbrsFwd != null)
                {
                    pbrsFwd.Dispose();
                    pbrsFwd = null;
                }

                if (compositionUI != null)
                {
                    compositionUI.Dispose();
                    compositionUI = null;
                }

                if (designerExtenders != null)
                {
                    designerExtenders.Dispose();
                    designerExtenders = null;
                }

                if (inheritanceService != null)
                {
                    inheritanceService.Dispose();
                    inheritanceService = null;
                }
            }
            base.Dispose(disposing);
        }
예제 #17
0
        void CreateDesigner(bool New, string XmlCode)
        {
            ModUi.ResetEventHandlers();
            //Create a new DesignSurface
            ModDesignSurface MDS = new ModDesignSurface();

            MDS.SetUpSelectionService();

            MDS.BeginLoad(typeof(Form));

            IDH = (IDesignerHost)MDS.GetService(typeof(IDesignerHost));
            try
            {
                IDH.RemoveService(typeof(ITypeDescriptorFilterService));
            }catch {}
            try
            {
                IDH.RemoveService(typeof(IToolboxService));
            }catch {}
            try
            {
                IDH.RemoveService(typeof(PropertyGrid));
            }catch { }

            //Read XML and update the Form control
            if (!New)
            {
                ModCodeAndControlHolder Code = ModUiTools.XmlToCode(XmlCode, (Form)IDH.RootComponent);
            }

            //Panel P = (Panel)IDH.CreateComponent(typeof(Panel));
            //P.Location = ModUiTools.GetLocationDefinition(20, 20);
            //P.Size = ModUiTools.GetSizeDefinition(100, 100);
            //Button B = (Button)IDH.CreateComponent(typeof(Button), "TestButton");
            //B.Text = "123";
            //P.Controls.Add(B);
            //P.Parent = (Form)IDH.RootComponent;

            try
            {
                this.BaseSplit.Panel2.Controls.RemoveAt(0);
            }
            catch { }
            Control C = MDS.View as Control;

            C.Parent = this.BaseSplit.Panel2;
            C.Dock   = DockStyle.Fill;



            IDH.AddService(typeof(ITypeDescriptorFilterService), new CustomFilterService());

            ModToolBox TB = new ModToolBox();

            TB.Parent = this.ToolboxTab;
            TB.Dock   = DockStyle.Fill;
            IDH.AddService(typeof(IToolboxService), TB);

            PropertyGrid PG = new PropertyGrid();

            PG.Parent = this.PropertiesPropertySubTab;
            PG.Dock   = DockStyle.Fill;

            IDH.AddService(typeof(PropertyGrid), PG);

            // Use ComponentChangeService to announce changing of the
            // Form's Controls collection */
            IComponentChangeService ICC = (IComponentChangeService)IDH.GetService(typeof(IComponentChangeService));

            ICC.OnComponentChanging(IDH.RootComponent, TypeDescriptor.GetProperties(IDH.RootComponent)["Controls"]);
        }
예제 #18
0
        void CreateDesigner(bool New, string XmlCode)
        {
            ModUi.ResetEventHandlers();
            //Create a new DesignSurface
            ModDesignSurface MDS = new ModDesignSurface();
            MDS.SetUpSelectionService();

            MDS.BeginLoad(typeof(Form));

            IDH = (IDesignerHost)MDS.GetService(typeof(IDesignerHost));
            try
            {
                IDH.RemoveService(typeof(ITypeDescriptorFilterService));
            }catch{}
            try
            {
                IDH.RemoveService(typeof(IToolboxService));
            }catch{}
            try
            {
                IDH.RemoveService(typeof(PropertyGrid));
            }catch { }

            //Read XML and update the Form control
            if (!New)
            {
                ModCodeAndControlHolder Code = ModUiTools.XmlToCode(XmlCode, (Form)IDH.RootComponent);
            }

            //Panel P = (Panel)IDH.CreateComponent(typeof(Panel));
            //P.Location = ModUiTools.GetLocationDefinition(20, 20);
            //P.Size = ModUiTools.GetSizeDefinition(100, 100);
            //Button B = (Button)IDH.CreateComponent(typeof(Button), "TestButton");
            //B.Text = "123";
            //P.Controls.Add(B);
            //P.Parent = (Form)IDH.RootComponent;

            try
            {
                this.BaseSplit.Panel2.Controls.RemoveAt(0);
            }
            catch { }
            Control C = MDS.View as Control;
            C.Parent = this.BaseSplit.Panel2;
            C.Dock = DockStyle.Fill;

            IDH.AddService(typeof(ITypeDescriptorFilterService), new CustomFilterService());

            ModToolBox TB = new ModToolBox();
            TB.Parent = this.ToolboxTab;
            TB.Dock = DockStyle.Fill;
            IDH.AddService(typeof(IToolboxService), TB);

            PropertyGrid PG = new PropertyGrid();
            PG.Parent = this.PropertiesPropertySubTab;
            PG.Dock = DockStyle.Fill;

            IDH.AddService(typeof(PropertyGrid), PG);

            // Use ComponentChangeService to announce changing of the
            // Form's Controls collection */
            IComponentChangeService ICC = (IComponentChangeService)IDH.GetService(typeof(IComponentChangeService));
            ICC.OnComponentChanging(IDH.RootComponent, TypeDescriptor.GetProperties(IDH.RootComponent)["Controls"]);
        }