-
Notifications
You must be signed in to change notification settings - Fork 22
/
NamedDestinationsViewer.cs
181 lines (164 loc) · 4.82 KB
/
NamedDestinationsViewer.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace Patagames.Pdf.Net.Controls.WinForms
{
/// <summary>
/// Represents the NamedDestinationsViewer control for displaying named destinations contained in PDF document
/// </summary>
public partial class NamedDestinationsViewer : ListView
{
#region Private fields
private PdfViewer _pdfViewer = null;
#endregion
#region Public Properties
/// <summary>
/// Gets or sets PdfViewer control associated with this NamedDestinationsViewer control
/// </summary>
public PdfViewer PdfViewer
{
get
{
return _pdfViewer;
}
set
{
if (_pdfViewer != value)
OnPdfViewerChanging(_pdfViewer, value);
}
}
#endregion
#region Constructors and initialization
/// <summary>
/// Initializes a new instance of the <see cref="NamedDestinationsViewer"/> class.
/// </summary>
public NamedDestinationsViewer()
{
InitializeComponent();
}
/// <summary>
/// Initializes a new instance of the <see cref="NamedDestinationsViewer"/> class.
/// </summary>
/// <param name="container">Container</param>
public NamedDestinationsViewer(IContainer container)
{
container.Add(this);
InitializeComponent();
}
#endregion
#region Overrides
/// <summary>
/// Raises the System.Windows.Forms.Control.MouseDoubleClick event.
/// </summary>
/// <param name="e">An System.Windows.Forms.MouseEventArgs that contains the event data.</param>
protected override void OnMouseDoubleClick(MouseEventArgs e)
{
ProcessNamedDestinationsClick();
base.OnMouseDoubleClick(e);
}
/// <summary>
/// Raises the System.Windows.Forms.Control.KeyDown event.
/// </summary>
/// <param name="e">A System.Windows.Forms.KeyEventArgs that contains the event data.</param>
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
ProcessNamedDestinationsClick();
base.OnKeyDown(e);
}
#endregion
#region Protected methods
/// <summary>
/// Called when the current PdfViewer control associated with the ToolStrip is changing.
/// </summary>
/// <param name="oldValue">PdfViewer control of which was associated with the ToolStrip.</param>
/// <param name="newValue">PdfViewer control of which will be associated with the ToolStrip.</param>
protected virtual void OnPdfViewerChanging(PdfViewer oldValue, PdfViewer newValue)
{
if (oldValue != null)
{
oldValue.AfterDocumentChanged -= pdfViewer_DocumentChanged;
oldValue.DocumentClosed -= pdfViewer_DocumentClosed;
oldValue.DocumentLoaded -= pdfViewer_DocumentLoaded;
}
if (newValue != null)
{
newValue.AfterDocumentChanged += pdfViewer_DocumentChanged;
newValue.DocumentClosed += pdfViewer_DocumentClosed;
newValue.DocumentLoaded += pdfViewer_DocumentLoaded;
}
_pdfViewer = newValue;
RebuildList();
}
/// <summary>
/// Process the <see cref="PdfDestination"/>.
/// </summary>
/// <param name="pdfDestination">PdfDestination to be performed.</param>
protected virtual void ProcessDestination(PdfDestination pdfDestination)
{
if (_pdfViewer == null)
return;
_pdfViewer.ProcessDestination(pdfDestination);
}
#endregion
#region Private event handlers
private void pdfViewer_DocumentChanged(object sender, EventArgs e)
{
RebuildList();
}
private void pdfViewer_DocumentLoaded(object sender, EventArgs e)
{
RebuildList();
}
private void pdfViewer_DocumentClosed(object sender, EventArgs e)
{
RebuildList();
}
private void NamedDestinationsViewer_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = new NamedDestinationsViewerItem(_pdfViewer.Document.NamedDestinations[e.ItemIndex]);
}
#endregion
#region Private methods
private void ProcessNamedDestinationsClick()
{
foreach (int index in SelectedIndices)
{
var item = Items[index] as NamedDestinationsViewerItem;
if (item == null)
continue;
if (item.Destination != null)
ProcessDestination(item.Destination);
}
}
#endregion
#region Public methods
/// <summary>
/// Constructs the list of named destinations
/// </summary>
public void RebuildList()
{
if (_pdfViewer == null || _pdfViewer.Document == null || _pdfViewer.Document.NamedDestinations == null)
{
VirtualListSize = 0;
Items.Clear();
}
else
{
VirtualListSize = _pdfViewer.Document.NamedDestinations.Count;
if (!VirtualMode)
{
BeginUpdate();
Items.Clear();
foreach (var b in _pdfViewer.Document.NamedDestinations)
{
var item = new NamedDestinationsViewerItem(b);
Items.Add(item);
}
EndUpdate();
}
}
}
#endregion
}
}