Exemple #1
0
        /// <summary>
        ///  This method is called to create a designer for a component.
        /// </summary>
        protected internal virtual IDesigner CreateDesigner(IComponent component, bool rootDesigner)
        {
            if (component is null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (_host is null)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            IDesigner designer;

            if (rootDesigner)
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner)) as IRootDesigner;
            }
            else
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }

            return(designer);
        }
Exemple #2
0
        private void UpdateSchemePreview()
        {
            Calendar  previewCalendar = this.GetPreviewCalendar();
            IDesigner designer        = TypeDescriptor.CreateDesigner(previewCalendar, typeof(IDesigner));

            designer.Initialize(previewCalendar);
            string designTimeHtml = ((CalendarDesigner)designer).GetDesignTimeHtml();

            this.schemePreview.GetDocument().GetBody().SetInnerHTML(designTimeHtml);
        }
        internal IDesigner CreateDesigner(IComponent component, bool rootDesigner)
        {
            if (component == null)
            {
                throw new System.ArgumentNullException("component");
            }

            if (rootDesigner)
            {
                return(TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner)));
            }
            else
            {
                return(TypeDescriptor.CreateDesigner(component, typeof(IDesigner)));
            }
        }
 protected internal virtual IDesigner CreateDesigner(IComponent component, bool rootDesigner)
 {
     if (component == null)
     {
         throw new ArgumentNullException("component");
     }
     if (this._host == null)
     {
         throw new ObjectDisposedException(base.GetType().FullName);
     }
     if (rootDesigner)
     {
         return(TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner)) as IRootDesigner);
     }
     return(TypeDescriptor.CreateDesigner(component, typeof(IDesigner)));
 }
Exemple #5
0
        /// <include file='doc\CalendarAutoFormatDialog.uex' path='docs/doc[@for="CalendarAutoFormatDialog.UpdateSchemePreview"]/*' />
        /// <devdoc>
        ///    Update scheme preview
        /// </devdoc>
        /// <internalonly/>
        private void UpdateSchemePreview()
        {
            // create a new calendar and apply the scheme to it
            Calendar wc = GetPreviewCalendar();

            // CONSIDER: Its not safe to create a designer and associate it to
            //   a control that is not site'd...
            //   This should use the runtime control directly and call RenderControl instead.

            // get the design time HTML
            IDesigner designer = TypeDescriptor.CreateDesigner(wc, typeof(IDesigner));

            designer.Initialize(wc);
            CalendarDesigner wcd        = (CalendarDesigner)designer;
            string           designHTML = wcd.GetDesignTimeHtml();

            // and show it!
            NativeMethods.IHTMLDocument2 tridentDocument = schemePreview.GetDocument();
            NativeMethods.IHTMLElement   documentElement = tridentDocument.GetBody();
            documentElement.SetInnerHTML(designHTML);
        }
        private void CreateComponentDesigner(IComponent component)
        {
            IDesigner designer = null;

            if (this.rootComponent != null)
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }
            else
            {
                Exception ex;
                this.rootComponent = component;
                this.rootDesigner  = (IRootDesigner)TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));
                if (this.rootDesigner == null)
                {
                    this.rootComponent = null;
                    ex = new Exception("No Top Level Designer for " + component.GetType().FullName);
                    throw ex;
                }
                ViewTechnology[] technologies = this.rootDesigner.SupportedTechnologies;
                bool             supported    = false;
                foreach (ViewTechnology tech in technologies)
                {
                    if (tech == ViewTechnology.Default)
                    {
                        supported = true;
                        break;
                    }
                }
                if (!supported)
                {
                    ex = new Exception("This designer host does not support the designer for " + component.GetType().FullName);
                    throw ex;
                }
                designer = this.rootDesigner;
                if (this.rootComponentClassName == null)
                {
                    this.rootComponentClassName = component.Site.Name;
                }
            }
            if (designer != null)
            {
                this.designerTable[component] = designer;
                try
                {
                    designer.Initialize(component);
                }
                catch
                {
                    this.designerTable.Remove(component);
                    if (designer == this.rootDesigner)
                    {
                        this.rootDesigner = null;
                    }
                    throw;
                }
                if (!(!(designer is IExtenderProvider) || TypeDescriptor.GetAttributes(designer).Contains(InheritanceAttribute.InheritedReadOnly)))
                {
                    ((IExtenderProviderService)this).AddExtenderProvider((IExtenderProvider)designer);
                }
                if (designer == this.rootDesigner)
                {
                    this.documentWindow.SetDesigner(this.rootDesigner);
                }
            }
        }
Exemple #7
0
        private void Initialize(ArrayList dragComponents, IDesignerHost host)
        {
            Control c = null;

            if ((dragComponents != null) && (dragComponents.Count > 0))
            {
                c = dragComponents[0] as Control;
            }
            Control   rootComponent = host.RootComponent as Control;
            Rectangle clipBounds    = new Rectangle(0, 0, rootComponent.ClientRectangle.Width, rootComponent.ClientRectangle.Height);

            clipBounds.Inflate(-1, -1);
            if (c != null)
            {
                this.dragOffset = this.behaviorService.ControlToAdornerWindow(c);
            }
            else
            {
                this.dragOffset = this.behaviorService.MapAdornerWindowPoint(rootComponent.Handle, Point.Empty);
                if ((rootComponent.Parent != null) && rootComponent.Parent.IsMirrored)
                {
                    this.dragOffset.Offset(-rootComponent.Width, 0);
                }
            }
            if (c != null)
            {
                ControlDesigner controlDesigner = host.GetDesigner(c) as ControlDesigner;
                bool            flag            = false;
                if (controlDesigner == null)
                {
                    controlDesigner = TypeDescriptor.CreateDesigner(c, typeof(IDesigner)) as ControlDesigner;
                    if (controlDesigner != null)
                    {
                        controlDesigner.ForceVisible = false;
                        controlDesigner.Initialize(c);
                        flag = true;
                    }
                }
                this.AddSnapLines(controlDesigner, this.targetHorizontalSnapLines, this.targetVerticalSnapLines, true, c != null);
                if (flag)
                {
                    controlDesigner.Dispose();
                }
            }
            foreach (IComponent component in host.Container.Components)
            {
                if (this.AddChildCompSnaplines(component, dragComponents, clipBounds, c))
                {
                    ControlDesigner designer = host.GetDesigner(component) as ControlDesigner;
                    if (designer != null)
                    {
                        if (this.AddControlSnaplinesWhenResizing(designer, component as Control, c))
                        {
                            this.AddSnapLines(designer, this.horizontalSnapLines, this.verticalSnapLines, false, c != null);
                        }
                        int num = designer.NumberOfInternalControlDesigners();
                        for (int i = 0; i < num; i++)
                        {
                            ControlDesigner designer3 = designer.InternalControlDesigner(i);
                            if (((designer3 != null) && this.AddChildCompSnaplines(designer3.Component, dragComponents, clipBounds, c)) && this.AddControlSnaplinesWhenResizing(designer3, designer3.Component as Control, c))
                            {
                                this.AddSnapLines(designer3, this.horizontalSnapLines, this.verticalSnapLines, false, c != null);
                            }
                        }
                    }
                }
            }
            this.verticalDistances   = new int[this.verticalSnapLines.Count];
            this.horizontalDistances = new int[this.horizontalSnapLines.Count];
        }
Exemple #8
0
        public void Add(System.ComponentModel.IComponent component, string name)
        {
            IDesigner  designer = null;
            DesignSite site     = null;

            // Check we're not trying to add a null component
            if (component == null)
            {
                throw new ArgumentNullException("Cannot add a null component to the container.");
            }

            // Remove this component from its existing container, if applicable
            if (component.Site != null && component.Site.Container != this)
            {
                component.Site.Container.Remove(component);
            }

            // Make sure we have a name for the component
            if (name == null)
            {
                INameCreationService nameService = (INameCreationService)GetService(typeof(INameCreationService));
                name = nameService.CreateName(this, component.GetType());
            }

            // Make sure there isn't already a component with this name in the container
            if (ContainsName(name))
            {
                throw new ArgumentException("A component with this name already exists in the container.");
            }

            // Give the new component a site
            site = new DesignSite(this, name);
            site.SetComponent(component);
            component.Site = site;

            // Let everyone know there's a component being added
            if (ComponentAdding != null)
            {
                ComponentAdding(this, new ComponentEventArgs(component));
            }

            // Get the designer for this component
            if (components.Count == 0)
            {
                // This is the first component being added and therefore must offer a root designer
                designer      = TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));
                rootComponent = component;
            }
            else
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }

            // If we got a designer, initialize it
            if (designer != null)
            {
                designer.Initialize(component);
                designers[component] = designer;
            }
            else
            {
                // This should never happen
                component.Site = null;
                throw new InvalidOperationException("Failed to get designer for this component.");
            }

            // Add to our list of extenderproviders if necessary
            if (component is IExtenderProvider)
            {
                IExtenderProviderService e = (IExtenderProviderService)GetService(typeof(IExtenderProviderService));
                e.AddExtenderProvider((IExtenderProvider)component);
            }

            // Finally we're able to add the component
            components.Add(component.Site.Name, component);
            if (ComponentAdded != null)
            {
                ComponentAdded(this, new ComponentEventArgs(component));
            }
        }
Exemple #9
0
        public void Add(IComponent component, string name)
        {
            // we have to have a component
            if (component == null)
            {
                throw new ArgumentException("component");
            }

            // if we dont have a name, create one
            if (name == null || name.Trim().Length == 0)
            {
                // we need the naming service
                INameCreationService nameCreationService = GetService(typeof(INameCreationService)) as INameCreationService;
                if (nameCreationService == null)
                {
                    throw new Exception("Failed to get INameCreationService.");
                }
                name = nameCreationService.CreateName(this, component.GetType());
            }

            // if we own the component and the name has changed
            // we just rename the component
            if (component.Site != null && component.Site.Container == this &&
                name != null && string.Compare(name, component.Site.Name, true) != 0)
            {
                // name validation and component changing/changed events
                // are fired in the Site.Name property so we don't have
                // to do it here...
                component.Site.Name = name;
                // bail out
                return;
            }
            // create a site for the component
            ISite site = new SiteImpl(component, name, this);

            // create component-site association
            component.Site = site;
            // the container-component association was established when
            // we created the site through site.host.
            // we need to fire adding/added events. create a component event args
            // for the component we are adding.

            ComponentEventArgs evtArgs = new ComponentEventArgs(component);

            // fire off adding event
            if (ComponentAdding != null)
            {
                try
                {
                    ComponentAdding(this, evtArgs);
                }
                catch {}
            }

            // if this is the root component
            IDesigner designer = null;

            if (rootComponent == null)
            {
                // set the root component
                rootComponent = component;
                // create the root designer
                designer = (IRootDesigner)TypeDescriptor.CreateDesigner(component, typeof(IRootDesigner));
            }
            else
            {
                designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
            }
            if (designer != null)
            {
                // add the designer to the list
                designers.Add(component, designer);
                // initialize the designer
                designer.Initialize(component);
            }
            // add to container component list
            sites.Add(site.Name, site);
            // now fire off added event
            if (ComponentAdded != null)
            {
                try
                {
                    ComponentAdded(this, evtArgs);
                }
                catch {}
            }
        }