-
Notifications
You must be signed in to change notification settings - Fork 620
/
Copy pathBookmarks.cs
119 lines (100 loc) · 2.92 KB
/
Bookmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.Collections.Generic;
using System.Text;
using FastReport.Utils;
using System.Collections;
namespace FastReport.Preview
{
internal class Bookmarks
{
private List<BookmarkItem> items;
private List<BookmarkItem> firstPassItems;
internal int CurPosition
{
get { return items.Count; }
}
internal void Shift(int index, float newY)
{
if (index < 0 || index >= items.Count)
return;
float topY = items[index].offsetY;
float shift = newY - topY;
for (int i = index; i < items.Count; i++)
{
items[i].pageNo++;
items[i].offsetY += shift;
}
}
public void Add(string name, int pageNo, float offsetY)
{
BookmarkItem item = new BookmarkItem();
item.name = name;
item.pageNo = pageNo;
item.offsetY = offsetY;
items.Add(item);
}
public int GetPageNo(string name)
{
BookmarkItem item = Find(name);
if (item == null)
item = Find(name, firstPassItems);
return item == null ? 0 : item.pageNo + 1;
}
public BookmarkItem Find(string name)
{
return Find(name, items);
}
private BookmarkItem Find(string name, List<BookmarkItem> items)
{
if (items == null)
return null;
foreach (BookmarkItem item in items)
{
if (item.name == name)
return item;
}
return null;
}
public void Clear()
{
items.Clear();
}
public void ClearFirstPass()
{
firstPassItems = items;
items = new List<BookmarkItem>();
}
public void Save(XmlItem rootItem)
{
rootItem.Clear();
foreach (BookmarkItem item in items)
{
XmlItem xi = rootItem.Add();
xi.Name = "item";
xi.SetProp("Name", item.name);
xi.SetProp("Page", item.pageNo.ToString());
xi.SetProp("Offset", Converter.ToString(item.offsetY));
}
}
public void Load(XmlItem rootItem)
{
Clear();
for (int i = 0; i < rootItem.Count; i++)
{
XmlItem item = rootItem[i];
Add(item.GetProp("Name"), int.Parse(item.GetProp("Page")),
(float)Converter.FromString(typeof(float), item.GetProp("Offset")));
}
}
public Bookmarks()
{
items = new List<BookmarkItem>();
}
internal class BookmarkItem
{
public string name;
public int pageNo;
public float offsetY;
}
}
}