Outline.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using FastReport.Utils;
  5. namespace FastReport.Preview
  6. {
  7. internal class Outline
  8. {
  9. private XmlItem rootItem;
  10. private XmlItem curItem;
  11. private int firstPassPosition;
  12. public XmlItem Xml
  13. {
  14. get { return rootItem; }
  15. set
  16. {
  17. rootItem = value;
  18. curItem = rootItem;
  19. value.Parent = null;
  20. }
  21. }
  22. internal bool IsEmpty
  23. {
  24. get { return rootItem.Count == 0; }
  25. }
  26. internal XmlItem CurPosition
  27. {
  28. get { return curItem.Count == 0 ? null : curItem[curItem.Count - 1]; }
  29. }
  30. private void EnumItems(XmlItem item, float shift)
  31. {
  32. int pageNo = int.Parse(item.GetProp("Page"));
  33. float offset = Converter.StringToFloat(item.GetProp("Offset"));
  34. item.SetProp("Page", Converter.ToString(pageNo + 1));
  35. item.SetProp("Offset", Converter.ToString(offset + shift));
  36. for (int i = 0; i < item.Count; i++)
  37. {
  38. EnumItems(item[i], shift);
  39. }
  40. }
  41. internal void Shift(XmlItem from, float newY)
  42. {
  43. if (from == null || from.Parent == null)
  44. return;
  45. int i = from.Parent.IndexOf(from);
  46. if (i + 1 >= from.Parent.Count)
  47. return;
  48. from = from.Parent[i + 1];
  49. float topY = Converter.StringToFloat(from.GetProp("Offset"));
  50. EnumItems(from, newY - topY);
  51. }
  52. public void Add(string text, int pageNo, float offsetY)
  53. {
  54. curItem = curItem.Add();
  55. curItem.Name = "item";
  56. curItem.SetProp("Text", text);
  57. curItem.SetProp("Page", pageNo.ToString());
  58. curItem.SetProp("Offset", Converter.ToString(offsetY));
  59. }
  60. public void LevelRoot()
  61. {
  62. curItem = rootItem;
  63. }
  64. public void LevelUp()
  65. {
  66. if (curItem != rootItem)
  67. curItem = curItem.Parent;
  68. }
  69. public void Clear()
  70. {
  71. Clear(-1);
  72. }
  73. private void Clear(int position)
  74. {
  75. if (position == -1)
  76. rootItem.Clear();
  77. else if (position < rootItem.Count)
  78. rootItem.Items[position].Dispose();
  79. LevelRoot();
  80. }
  81. public void PrepareToFirstPass()
  82. {
  83. firstPassPosition = rootItem.Count == 0 ? -1 : rootItem.Count;
  84. LevelRoot();
  85. }
  86. public void ClearFirstPass()
  87. {
  88. Clear(firstPassPosition);
  89. }
  90. public Outline()
  91. {
  92. rootItem = new XmlItem();
  93. rootItem.Name = "outline";
  94. LevelRoot();
  95. }
  96. }
  97. }