Ejemplo n.º 1
0
        /// <summary>
        /// Parse a string "1,2,3,4" to a ColumnDisplay array.
        /// </summary>
        /// <param name="size">The string to parse.</param>
        /// <returns>The integer array.</returns>
        public static ColumnDisplay[] GetSizes(string size)
        {
            ColumnDisplay[] sizes = null;
            if (String.IsNullOrEmpty(size) == false)
            {
                string[] elts = size.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                sizes = new ColumnDisplay[elts.Length];
                for (int i = 0; i < elts.Length; i++)
                {
                    sizes[i] = new ColumnDisplay(elts[i]);
                }
            }

            return(sizes);
        }
Ejemplo n.º 2
0
        protected ColumnDisplay[] GetSizes(GenericScore genScore, string[][] labels)
        {
            ColumnDisplay[] cols = null;
            if (!this.AutoSize)
            {
                cols = ColumnDisplay.GetSizes(genScore.Sizes);
            }
            else
            {
                // evaluate max size foreach column
                // warning: all columns do not have the same number of columns
                Dictionary <int, int> coldic = new Dictionary <int, int>();
                foreach (string[] row in labels)
                {
                    if (row == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < row.Length; i++)
                    {
                        string cell   = row[i];
                        int    length = String.IsNullOrEmpty(cell) ? 0 : cell.Length;
                        if (coldic.ContainsKey(i))
                        {
                            coldic[i] = Math.Max(coldic[i], length);
                        }
                        else
                        {
                            coldic[i] = length;
                        }
                    }
                }

                cols = new ColumnDisplay[coldic.Count];
                foreach (int key in coldic.Keys)
                {
                    cols[key] = new ColumnDisplay(coldic[key], ColumnDisplay.Alignment.Left);
                }
            }

            return(cols);
        }
Ejemplo n.º 3
0
        public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn,
                                        int startX, int startY, int pnlWidth, int pnlHeight,
                                        CreateControlDelegate <T> createControl,
                                        out bool overRight, out bool overDown, out int lineNumber, out int colNumber)
        {
            lineNumber = -1;
            colNumber  = -1;
            overRight  = false;
            overDown   = false;

            //Tools.LogMessage("X = {0}, Y = {1}, W = {2}, H = {3}", startX, startY, pnlWidth, pnlHeight);

            GenericScore genScore = score as GenericScore;

            if (genScore == null)
            {
                return(null);
            }

            int maxX          = startX + pnlWidth;
            int maxY          = startY + pnlHeight;
            int posX          = startX;
            int posY          = startY;
            int maxColumnSize = pnlWidth / m_charWidth;

            // Get Columns Sizes
            ColumnDisplay[] cols = GetSizes(genScore, labels);

            RuleEvaluator engine = new RuleEvaluator(genScore.Rules);

            ParsingOptions opt          = genScore.GetParseOption();
            bool           reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse);
            bool           wordWrap     = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap);

            // for all the rows
            IList <T> controls   = new List <T>();
            int       totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER);

            foreach (string[] row_ in labels)
            {
                // ignore empty lines
                if (row_ == null || row_.Length == 0)
                {
                    continue;
                }

                lineNumber++;

                // ignore lines on previous page
                if (lineNumber < startLine)
                {
                    continue;
                }

                // calculate X position
                posX = startX;// -startColumn;

                // ignore if outside and break to next row
                if (LimitToPage && posY > maxY)
                {
                    overDown = true;
                    break;
                }

                bool     isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER);
                string[] row      = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_;

                #region Evaluate rule for full line
                //bool isHeader = !String.IsNullOrEmpty(this.Score.Headers) && lineNumber == 0;
                Style lineStyle = (lineNumber % 2 == 0) ? m_defaultStyle : m_altStyle;
                bool  merge     = false;
                if (!isHeader)
                {
                    Rule rule = engine.CheckLine(row, lineNumber, totalLines);
                    if (rule != null)
                    {
                        // skip lines and continue
                        if (rule.Action == RuleAction.SkipLine)
                        {
                            continue;
                        }

                        merge     = rule.Action == RuleAction.MergeCells;
                        lineStyle = FindStyle(rule.Format) ?? lineStyle;
                    }
                }
                #endregion

                #region For all columns
                int nbLines    = 1;
                int nbControls = 0;
                for (int index = startColumn; index < row.Length; index++)
                {
                    int colIndex = reverseOrder ? row.Length - index - 1 : index;

                    // get cell
                    string        cell    = row[colIndex];
                    ColumnDisplay colSize = GetColumnSize(colIndex, cols, cell, merge);
                    if (colSize.Size == 0)
                    {
                        continue;
                    }

                    // ignore controls outside area
                    if (LimitToPage && posX > maxX)
                    {
                        overRight = true;
                        continue;
                    }

                    // evaluate size of the control in pixel
                    int maxChar = Math.Min(colSize.Size + 1, maxColumnSize);

                    // wrap needed?
                    if (wordWrap || AutoWrap)
                    {
                        int i = maxChar + 1;
                        while (i < cell.Length)
                        {
                            cell = cell.Insert(i, Environment.NewLine);
                            i   += maxChar + 1;
                        }
                    }

                    // count new lines
                    int nb = Tools.CountLines(cell);
                    nbLines = Math.Max(nbLines, nb);

                    int length = m_charWidth * maxChar;
                    int height = m_charHeight * nbLines;
                    if (posX < startX)
                    {
                        // cell was on previous page
                        // increase posX so that we can get to current page
                        posX += length;
                        continue;
                    }

                    #region Evaluate rule for the cell
                    Style cellStyle = lineStyle;
                    if (!isHeader)
                    {
                        IList <Rule> cellRules = engine.CheckCell(cell, colIndex);
                        foreach (var cellRule in cellRules)
                        {
                            cell = RuleProcessor.Process(cell, cellRule);
                            if (cellRule != null && cellRule.Action == RuleAction.FormatCell)
                            {
                                cellStyle = FindStyle(cellRule.Format) ?? lineStyle;
                            }
                        }
                    }
                    #endregion

                    // create the control
                    string[] aa = cell.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < aa.Length; i++)
                    {
                        T control = createControl(posX, posY + (i * m_charHeight), length, m_charHeight,
                                                  colSize.Alignement,
                                                  aa[i],
                                                  m_fontName, m_fontSize, cellStyle, maxChar, colIndex);

                        if (control != null)
                        {
                            controls.Add(control);
                            nbControls++;
                        }
                    }

                    // set X pos to the end of the control
                    posX += Math.Min(length, pnlWidth - 1);
                }
                #endregion

                // set Y pos to the bottom of the control
                if (nbControls > 0 || isHeader)
                {
                    posY += m_charHeight * nbLines;
                }
            }

            Tools.LogMessage("{0}: {1} controls created", score.Id, controls.Count);
            return(controls);
        }