Ejemplo n.º 1
0
        public ListControl ProcessBeforeListItem(int currentNumId, int currentLevel, ListTypeEnum currentType,
                                                 int?previousNumId, int?previousLevel,
                                                 int?nextNumId, int?nextLevel)
        {
            // this is the first list element
            if (!previousNumId.HasValue || !previousLevel.HasValue)
            {
                ListInfo listInfo = new ListInfo(currentNumId, currentLevel, currentType);
                _listStyle.Add(listInfo);

                string suffix = string.Empty;
                if (currentType == ListTypeEnum.Numbered && currentLevel == 0)
                {
                    if (_visitedFirstLevelNumberings.ContainsKey(listInfo.HashCode))
                    {
                        return(new ListControl(ListTypeEnum.Numbered, NumberedCounterTypeEnum.LoadCounter, UniqueString(listInfo.NumId)));
                    }
                    else
                    {
                        _visitedFirstLevelNumberings.Add(listInfo.HashCode, string.Empty);
                        return(new ListControl(ListTypeEnum.Numbered, NumberedCounterTypeEnum.NewCounter, UniqueString(listInfo.NumId)));
                    }
                }

                return(new ListControl(currentType, NumberedCounterTypeEnum.None, null));
            }
            else //this is not the first list element
            {
                int listTopNumId = _listStyle[_listStyle.Count - 1].NumId;
                int listTopLevel = _listStyle[_listStyle.Count - 1].Level;

                // the same list continues
                if (listTopNumId == currentNumId)
                {
                    // the same list continues with the same level
                    if (listTopLevel == currentLevel)
                    {
                        //nothing to do
                    }
                    else // the same list continues but with different level
                    {
                        // a new level started
                        if (currentLevel > listTopLevel)
                        {
                            _listStyle.Add(new ListInfo(currentNumId, currentLevel, currentType));
                            return(new ListControl(currentType, NumberedCounterTypeEnum.None, null));
                        }
                        else // the previous level ended
                        {
                            //nothing to do
                        }
                    }
                }
                else // there was an other list before this
                {
                    int indexOfPrevious = FindListElement(previousNumId.Value, previousLevel.Value);

                    //a new list started because the previous cannot find in the list
                    if (indexOfPrevious != -1)
                    {
                        _listStyle.Add(new ListInfo(currentNumId, currentLevel, currentType));
                        return(new ListControl(currentType, NumberedCounterTypeEnum.None, null));
                    }
                    else // a previously broken list found
                    {
                        // nothing to do
                    }
                }
            }

            return(new ListControl(ListTypeEnum.None, NumberedCounterTypeEnum.None, null));
        }
Ejemplo n.º 2
0
        public List <ListControl> ProcessAfterListItem(int currentNumId, int currentLevel, ListTypeEnum currentType,
                                                       int?previousNumId, int?previousLevel,
                                                       int?nextNumId, int?nextLevel)
        {
            //if this is the last list element
            if (!nextNumId.HasValue || !nextLevel.HasValue)
            {
                ListControl suffix = new ListControl(ListTypeEnum.None, NumberedCounterTypeEnum.None, null);
                if (_listStyle.Count > 0)
                {
                    ListInfo listInfo = _listStyle[0];
                    if (listInfo.Style == ListTypeEnum.Numbered && listInfo.Level == 0)
                    {
                        if (_visitedFirstLevelNumberings.ContainsKey(listInfo.HashCode))
                        {
                            suffix.NumberedCounterType = NumberedCounterTypeEnum.SaveCounter;
                            suffix.Numbering           = UniqueString(listInfo.NumId);
                        }
                    }
                }

                List <ListControl> ends = GetReverseListTilIndex(0);

                if (ends.Count > 0)
                {
                    var first = ends[0];
                    first.NumberedCounterType = suffix.NumberedCounterType;
                    first.Numbering           = suffix.Numbering;
                    ends.RemoveAt(0);
                    ends.Insert(0, first);
                }

                _listStyle.Clear();

                return(ends);
            }
            else //a list
            {
                // the same list continues
                if (currentNumId == nextNumId.Value && currentLevel == nextLevel.Value)
                {
                    //nothing to do
                }
                else // other list encountered
                {
                    int indexOfNext = FindListElement(nextNumId.Value, nextLevel.Value);

                    //if the next list element cannot find, then a unknown new list will start
                    if (indexOfNext == -1)
                    {
                        //nothing to do
                    }
                    else // else end of list
                    {
                        //remove listStyles and sign ends
                        List <ListControl> ends = GetReverseListTilIndex(indexOfNext + 1);
                        _listStyle.RemoveRange(indexOfNext + 1, _listStyle.Count - indexOfNext - 1);
                        return(ends);
                    }
                }
            }

            return(new List <ListControl>());
        }