Ejemplo n.º 1
0
        // Render element elmt onto the page currentPage.
        // parent refers to the parent element within the current rendered page.  When
        //      a page break occurs a new parent hierarchy is build for the new page
        //      and parent will point to the bottom of the new parent hierarchy.
        // currentPage will refer to the current page being built.  It will be updated
        //      inside this routine if elmt spans pages.
        private void RecurseRender(
            Rdl.Render.GenericRender rpt,
            Element elmt,         // The current element from the source document
            ref Container parent, // The parent element in the page.
            ref Page currentPage, // The current page.
            decimal parentTop,    // The absolute position of the parent element in the master rendered document.
            decimal top,          // The absolute position in the master rendered document.
            decimal xPos,         // The X position within the parent object
            decimal yPos          // The Y position within the parent object
            )
        {
            //decimal elementHeight = CalcHeight(elmt);
            decimal elementHeight  = elmt.Height;
            decimal requiredHeight = elementHeight;
            decimal elementTop;

            // If this element has repeated elements associated with it then make sure
            // that there is room on the page for those repeated elements.
            if (elmt is Container)
            {
                // If this is a toggle item, then determine if we want to include it in the
                // rendered page.
                if (!((Container)elmt).IsVisible)
                {
                    return;
                }

                foreach (Container re in ((Container)elmt).RepeatList)
                {
                    if (re.AbsoluteTop > elmt.AbsoluteTop)
                    {
                        requiredHeight += re.Height;
                    }
                    //requiredHeight += CalcHeight(re);
                }
            }

            // If this element is spanning pages, then calculate the top
            // based on the starting position of this page.
            if (parentTop < currentPage.RelativeTop)
            {
                elementTop = yPos - (currentPage.RelativeTop - parentTop);
            }
            else
            {
                elementTop = yPos;
            }

            bool newPage = false;

            if (elmt is Container && ((Container)elmt).PageBreakBefore)
            {
                newPage = true;
            }
            else if (top - currentPage.RelativeTop + requiredHeight > currentPage.AvailableHeight)
            {
                // If the element doesn't fit entirely on this page and we should keep it on
                // one page, then create a new page.
                if (!(elmt is Container) || (elmt is Container && ((Container)elmt).KeepTogether))
                {
                    newPage = true;
                }
            }

            if (newPage)
            {
                //currentPage.AddFooters(rpt, parent, false);
                currentPage.ResolveReportItemReferences();

                currentPage = new Page(
                    rpt,
                    currentPage.PageNumber + 1,
                    rpt.BodyContainer.Width, //PageWidth - RightMargin - LeftMargin,
                    PageHeight - TopMargin - BottomMargin,
                    top, elmt.Parent, ref parent);

                _pageList.Add(currentPage);

                if (parentTop < currentPage.RelativeTop)
                {
                    elementTop = yPos - (currentPage.RelativeTop - parentTop);
                }
                else
                {
                    elementTop = yPos;
                }
            }

            Element newElement = null;

            if (elmt is Container)
            {
                newElement = Copy(((Container)elmt), false);
                newElement.CanGrowVertically = true;

                // Loop through the repeated elements
                foreach (Container r in ((Container)elmt).RepeatList)
                {
                    // If the repeated element is below the current element then reserve space for it at the bottom.
                    if (r.AbsoluteTop > elmt.AbsoluteTop)
                    {
                        currentPage.FooterSpace += (r.Top - yPos + elementHeight + r.Height);
                    }
                }
                //currentPage.FooterSpace += (r.Top - yPos + elementHeight + CalcHeight(r));
            }
            if (elmt is TextElement)
            {
                TextElement te = (TextElement)elmt;

                // Save the report item value for filling in to ReportItem references later
                if (te.ReportElement is Rdl.Engine.ReportItem)
                {
                    currentPage.elementValues[((Rdl.Engine.ReportItem)te.ReportElement).Name] =
                        te.Text;
                }

                newElement = new TextElement(te);
            }
            if (elmt is ImageElement)
            {
                newElement = new ImageElement((ImageElement)elmt);
            }
            if (elmt is ChartElement)
            {
                newElement = new ChartElement((ChartElement)elmt);
            }

            newElement.Parent = parent;
            newElement.Top    = 0;
            newElement.Height = 0;
            //newElement.Left += xPos;
            if (parent != null)
            {
                parent.Children.Add(newElement);
            }

            // Set the height of this element to either the height of the source element
            // or the height of the remaining space on the page.  Whichever is less.
            newElement.Top    = elementTop;
            newElement.Height = Math.Min(elementHeight, currentPage.AvailableHeight - (top - currentPage.RelativeTop));

            if (elmt is Container)
            {
                Container be = newElement as Container;

                // Sort the children by the top values so if the children span a page then
                // they will render in the correct order.
                if (elmt is FixedContainer)
                {
                    ((Container)elmt).Children.Sort(delegate(Element a, Element b) { return(a.Top.CompareTo(b.Top)); });
                }

                foreach (Element child in ((Container)elmt).Children)
                {
                    RecurseRender(rpt, child, ref be, ref currentPage, top, top + child.Top, child.Left, child.Top);
                    parent = be.Parent;
                }

                // Loop through the repeated elements
                foreach (Container r in be.RepeatList)
                {
                    // If the repeated element is below the current element then release the reserved space
                    if (r.AbsoluteTop > be.AbsoluteTop)
                    {
                        currentPage.FooterSpace -= (r.Top - elmt.Top + elementHeight + r.Height);
                    }
                }
                //currentPage.FooterSpace -= (r.Top - elmt.Top + elementHeight + CalcHeight(r));

                if (be.PageBreakAfter)
                {
                    //currentPage.AddFooters(rpt, parent, false);
                    currentPage.ResolveReportItemReferences();

                    currentPage = new Page(
                        rpt,
                        currentPage.PageNumber + 1,
                        rpt.BodyContainer.Width, //PageWidth - RightMargin - LeftMargin,
                        PageHeight - TopMargin - BottomMargin,
                        elmt.Top + elementHeight, elmt.Parent, ref parent);

                    _pageList.Add(currentPage);
                }
            }
        }
Ejemplo n.º 2
0
        private void RecurseRender(Element elmt, decimal top, decimal left, bool renderAll)
        {
            top  += elmt.Top;
            left += elmt.Left;

            if (!renderAll)
            {
                if (elmt is Container && !((Container)elmt).IsVisible)
                {
                    return;
                }
            }

            if (elmt is TextElement)
            {
                TextElement te = elmt as TextElement;
                TextStyle   ts = null;
                if (te.Style is TextStyle)
                {
                    ts = (TextStyle)te.Style;
                }

                Int32 row = _rows.FindIndex(delegate(decimal d) { return(d == top); });
                Int32 col;
                if (ts != null && ts.TextAlign == Rdl.Engine.Style.TextAlignEnum.Right)
                {
                    col = _cols.FindIndex(delegate(decimal d) { return(d == left + elmt.Width); }) - 1;
                }
                else
                {
                    col = _cols.FindIndex(delegate(decimal d) { return(d == left); });
                }

                WritableCell cell;
                double       dValue;
                if (double.TryParse(te.Text, out dValue))
                {
                    cell = new Number(col, row, dValue);
                }
                else
                {
                    cell = new Label(col, row, te.Text);
                }
                cell.setCellFormat(formats[te.StyleIndex]);
                _ws.addCell(cell);
            }

            if (elmt is ImageElement)
            {
                ImageElement ie = elmt as ImageElement;

                Int32 row = _rows.FindIndex(delegate(decimal d) { return(d == top); });
                Int32 col;
                if (ie != null)
                {
                    col = _cols.FindIndex(delegate(decimal d) { return(d == left); });
                }

                Rdl.Render.ImageData id  = _report.ImageList[ie._imageIndex];
                WritableImage        img = new WritableImage(0, 0, (double)ie.Width, (double)ie.Height,
                                                             id.GetImageData());
                _ws.addImage(img);
            }

            if (elmt is Container)
            {
                foreach (Element child in ((Container)elmt).Children)
                {
                    RecurseRender(child, top, left, renderAll);
                }
            }
        }
Ejemplo n.º 3
0
        protected int RecurseRender(Rdl.Render.GenericRender rpt, StringBuilder body, Element elmt, int level, bool forPrint)
        {
            StringBuilder bodyPart  = new StringBuilder();
            bool          hasAction = false;

            string style = string.Empty;

            //BoxStyle bs = rpt.StyleList[elmt.StyleIndex];

            //if (elmt.ReportElement is Rdl.Engine.Report)
            //{
            //    rpt = (Rdl.Engine.Report)elmt.ReportElement;
            //}
            if (elmt is Container)
            {
                Container c = elmt as Container;
                if (!c.IsVisible)
                {
                    return(0);
                }
            }
            if ((elmt is TextElement || elmt is FixedContainer || elmt is ImageElement || elmt is ChartElement))
            {
                style += "width: " + ElementWidth(rpt, elmt) + "pt;"
                         + "height: " + ElementHeight(rpt, elmt) + "pt;";
            }
            if (elmt is TextElement)
            {
                style += "overflow: hidden;";
            }
            if (elmt._imageIndex >= 0 && !(elmt is ImageElement))
            {
                style += "background-image: url(" + GetImageUrl(elmt.Name, "StaticImage", elmt._imageIndex.ToString()) + ");";
                style += "background-repeat: " + rpt.ImageList[elmt._imageIndex].ImageRepeat.ToString() + ";";
            }
            if (elmt.Parent != null && elmt.Parent is Rdl.Render.FixedContainer)
            {
                decimal top  = elmt.Top;
                decimal left = elmt.Left;
                style +=
                    "top: " + top + "pt;" +
                    "left: " + left + "pt;";
                // 12/26/2007 This line caused problems with tables.
                //if (!elmt.MatchParentHeight)
                style += "position: absolute;";
            }
            if (elmt is TextElement && ((TextStyle)elmt.Style).TextAlign == Rdl.Engine.Style.TextAlignEnum.General)
            {
                TextElement te = elmt as TextElement;
                decimal     val;

                if (te.Text.Length > 0 &&
                    decimal.TryParse(te.Text,
                                     System.Globalization.NumberStyles.AllowCurrencySymbol |
                                     System.Globalization.NumberStyles.Number,
                                     System.Globalization.CultureInfo.CurrentCulture,
                                     out val))
                {
                    style += "text-align: right;";
                }
                else
                {
                    style += "text-align: left;";
                }
            }

            if (elmt is FlowContainer && ((FlowContainer)elmt).FlowDirection == FlowContainer.FlowDirectionEnum.LeftToRight)
            {
                int elements = 0;
                bodyPart.AppendLine(Spaces(level) + "<table cellpadding=\"0\" cellspacing=\"0\" " +
                                    "id=\"" + elmt.Name + "\" " +
                                    ((elmt.StyleIndex >= 0) ? "class=\"Report_style" + elmt.StyleIndex + "\" " : string.Empty) +
                                    "style=\"" + style + "\"" +
                                    ">" +
                                    "<tr>");

                foreach (Element child in ((Container)elmt).Children)
                {
                    bodyPart.AppendLine(Spaces(level + 1) + "<td>");
                    elements += RecurseRender(rpt, bodyPart, child, level + 2, forPrint);
                    bodyPart.AppendLine(Spaces(level + 1) + "</td>");
                }

                bodyPart.AppendLine(Spaces(level) + "</tr></table>");
                if (elements > 0)
                {
                    body.Append(bodyPart.ToString());
                }
                return(elements);
            }

            if (elmt is Container || elmt is TextElement || elmt is ImageElement || elmt is ChartElement)
            {
                string divTag =
                    "<div " +
                    "id=\"" + elmt.Name + "\" " +
                    ((elmt.StyleIndex >= 0) ? "class=\"Report_style" + elmt.StyleIndex.ToString() + "\" " : string.Empty) +
                    "style=\"" + style + "\"";
                if (elmt is TextElement && ((TextElement)elmt).IsToggle)
                {
                    divTag += " stateToggle=\"" + ((TextElement)elmt).ToggleState.ToString() + "\"";
                }
                divTag += ">";
                bodyPart.AppendLine(Spaces(level) + divTag);
            }

            if (elmt is TextElement)
            {
                TextElement te = elmt as TextElement;

                if (te.IsToggle && !forPrint)
                {
                    bodyPart.AppendLine(Spaces(level + 1) +
                                        "<a href=\"javascript:{}\" onclick=\"javascript:ToggleState('" + te.Name + "');\">");
                    bodyPart.AppendLine(Spaces(level + 1) +
                                        "<img id=\"" + te.Name + "_img\" src=" + ((te.ToggleState == TextElement.ToggleStateEnum.open) ? _minusGif : _plusGif) + " border=\"0\" style=\"float: left;\" />");
                    bodyPart.AppendLine(Spaces(level + 1) + "</a>");
                }
            }

            if (elmt is ActionElement)
            {
                ActionElement ae = (ActionElement)elmt;
                if (ae.DrillThroughReportName != null)
                {
                    bodyPart.AppendLine(Spaces(level + 1) +
                                        "<a href=\"javascript:{}\" onclick=\"javascript:Action('" + ae.Name + "');\">");
                    hasAction = true;
                }
                else if (ae.Hyperlink != null)
                {
                    bodyPart.AppendLine(Spaces(level + 1) +
                                        "<a href=\"" + ae.Hyperlink + "\" >");
                    hasAction = true;
                }
                else if (ae.BookmarkLink != null)
                {
                    bodyPart.AppendLine(Spaces(level + 1) +
                                        "<a href=\"#" + ae.BookmarkLink + "\" >");
                    hasAction = true;
                }
            }

            if (elmt is TextElement)
            {
                TextElement te = elmt as TextElement;

                // Save the report item value for filling in to ReportItem references later
                if (te.ReportElement is Rdl.Engine.ReportItem)
                {
                    elementValues[((Rdl.Engine.ReportItem)te.ReportElement).Name] =
                        te.Text;
                }

                string text = te.Text.Replace("\n", "<br />");
                bodyPart.AppendLine(Spaces(level) + text);
            }

            if (elmt is ImageElement)
            {
                ImageElement ie = elmt as ImageElement;

                bodyPart.AppendLine(Spaces(level) +
                                    "<img id=\"img_" + elmt.Name + "\" alt=\"\" border=\"0\" src=\"\">");
                _script.AppendLine(Spaces(level) +
                                   "document.getElementById('img_" + elmt.Name + "').src = " +
                                   GetImageUrl(elmt.Name, "SizedImage", elmt._imageIndex.ToString()) + ";"
                                   );
            }

            if (elmt is ChartElement)
            {
                _charts.Add(elmt.Name, (ChartElement)elmt);
                bodyPart.AppendLine(Spaces(level) +
                                    "<img id=\"img_" + elmt.Name + "\" alt=\"\" border=\"0\" src=\"\">");
                _script.AppendLine(Spaces(level) +
                                   "document.getElementById('img_" + elmt.Name + "').src = " +
                                   GetImageUrl(elmt.Name, "Chart", elmt.Name) + ";"
                                   );
            }

            if (elmt is Container)
            {
                if (elmt.Height == 0)
                {
                    return(0);
                }
                int elements = 0;
                foreach (Element child in ((Container)elmt).Children)
                {
                    elements += RecurseRender(rpt, bodyPart, child, level + 1, forPrint);
                }
            }

            if (hasAction)
            {
                bodyPart.Append("</a>");
            }

            if (elmt is Container || elmt is TextElement || elmt is ImageElement || elmt is ChartElement)
            {
                bodyPart.AppendLine(Spaces(level) +
                                    "</div>");
            }

            body.Append(bodyPart.ToString());
            return(1);
        }
Ejemplo n.º 4
0
 public ImageElement(ImageElement ie)
     : base(ie)
 {
 }