private const int APPEND = -1; //mark the index so it appends to the container

        protected int AddTemplateToContainer(IPDFContainerComponent container, int index, IPDFTemplate template)
        {
            int count = 0;
            IEnumerable <IPDFComponent> generated = template.Instantiate(index, container);

            foreach (IPDFComponent comp in generated)
            {
                Component actual = comp as Component;
                if (null != actual)
                {
                    if (index >= 0 && index < container.Content.Count)
                    {
                        container.Content.Insert(index, actual);
                    }
                    else
                    {
                        container.Content.Add(actual);
                    }
                    count++;
                }
                if (comp is IPDFBindableComponent)
                {
                    ((IPDFBindableComponent)comp).DataBinding += PDFDataGridTemplateColumn_DataBinding;
                }
            }
            return(count);
        }
        /// <summary>
        /// Creates a new instance of the template and adds it to this components content
        /// </summary>
        /// <param name="context"></param>
        /// <param name="count"></param>
        /// <param name="index"></param>
        /// <param name="container"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        protected virtual int InstantiateAndAddWithTemplate(IPDFTemplate template, int count, int index, IPDFContainerComponent container, PDFDataContext context)
        {
            if (null == template)
            {
                return(0);
            }

            PDFInitContext init = GetInitContext(context);
            PDFLoadContext load = GetLoadContext(context);

            IEnumerable <IPDFComponent> created = template.Instantiate(count, this);
            int added = 0;

            if (created != null)
            {
                foreach (IPDFComponent ele in ((IEnumerable)created))
                {
                    InsertComponentInContainer(container, index, ele, init, load);
                    if (ele is IPDFBindableComponent)
                    {
                        ((IPDFBindableComponent)ele).DataBind(context);
                    }
                    index++;
                    added++;

                    //raise the event
                    this.OnItemDataBound(context, ele);
                }
            }
            return(added);
        }
Ejemplo n.º 3
0
        public void InstantiateTemplate(IPDFTemplate template, PDFLayoutContext context, PDFRect available, int pageindex)
        {
            if (null == template)
            {
                throw new ArgumentNullException("template");
            }
            if (null == context)
            {
                throw new ArgumentNullException("context");
            }

            List <IPDFComponent> generated = new List <IPDFComponent>(template.Instantiate(GeneratedCount, this));

            if (generated.Count == 0)
            {
                return;
            }

            PDFInitContext init = new PDFInitContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document)
            {
                Compression  = context.Compression,
                OutputFormat = context.OutputFormat,
                Conformance  = context.Conformance
            };

            PDFLoadContext load = new PDFLoadContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document)
            {
                Compression  = context.Compression,
                OutputFormat = context.OutputFormat,
                Conformance  = context.Conformance
            };

            PDFDataContext data = new PDFDataContext(context.Items, context.TraceLog, context.PerformanceMonitor, this.Document)
            {
                Compression  = context.Compression,
                OutputFormat = context.OutputFormat,
                Conformance  = context.Conformance
            };


            IPDFContainerComponent container  = this;
            IPDFComponentList      components = container.Content as IPDFComponentList;

            for (int index = 0; index < generated.Count; index++)
            {
                IPDFComponent comp = generated[index];
                components.Insert(index, comp);
                comp.Init(init);
            }

            foreach (IPDFComponent comp in generated)
            {
                comp.Load(load);
            }
            foreach (IPDFComponent comp in generated)
            {
                if (comp is IPDFBindableComponent)
                {
                    (comp as IPDFBindableComponent).DataBind(data);
                }
            }
            this.GeneratedCount++;
        }