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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
//========================================================================
//
// QtPDFCore.h
//
// Copyright 2009-2014 Glyph & Cog, LLC
//
//========================================================================
#ifndef QTPDFCORE_H
#define QTPDFCORE_H
#include <aconf.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#include <QDateTime>
#include "gtypes.h"
#include "SplashTypes.h"
#include "PDFCore.h"
class GString;
class BaseStream;
class PDFDoc;
class LinkAction;
class QWidget;
class QScrollBar;
//------------------------------------------------------------------------
// callbacks
//------------------------------------------------------------------------
typedef void (*QtPDFUpdateCbk)(void *data, GString *fileName,
int pageNum, int numPages,
const char *linkLabel);
typedef void (*QtPDFMidPageChangedCbk)(void *data, int pageNum);
typedef void (*QtPDFLoadCbk)(void *data);
typedef void (*QtPDFActionCbk)(void *data, char *action);
typedef void (*QtPDFLinkCbk)(void *data, const char *type,
const char *dest, int page);
typedef void (*QtPDFSelectDoneCbk)(void *data);
typedef void (*QtPDFPaintDoneCbk)(void *data, bool finished);
//------------------------------------------------------------------------
// QtPDFCore
//------------------------------------------------------------------------
class QtPDFCore: public PDFCore {
public:
// Create viewer core in <viewportA>.
QtPDFCore(QWidget *viewportA,
QScrollBar *hScrollBarA, QScrollBar *vScrollBarA,
SplashColorPtr paperColor, SplashColorPtr matteColor,
GBool reverseVideo);
~QtPDFCore();
//----- loadFile / displayPage / displayDest
// Load a new file. Returns pdfOk or error code.
virtual int loadFile(GString *fileName, GString *ownerPassword = NULL,
GString *userPassword = NULL);
#ifdef _WIN32
// Load a new file. Returns pdfOk or error code.
virtual int loadFile(wchar_t *fileName, int fileNameLen,
GString *ownerPassword = NULL,
GString *userPassword = NULL);
#endif
// Load a new file, via a Stream instead of a file name. Returns
// pdfOk or error code.
virtual int loadFile(BaseStream *stream, GString *ownerPassword = NULL,
GString *userPassword = NULL);
// Load an already-created PDFDoc object.
virtual void loadDoc(PDFDoc *docA);
// Reload the current file. This only works if the PDF was loaded
// via a file. Returns pdfOk or error code.
virtual int reload();
// Called after any update is complete.
virtual void finishUpdate(GBool addToHist, GBool checkForChangedFile);
//----- panning and selection
void startPan(int wx, int wy);
void endPan(int wx, int wy);
void startSelection(int wx, int wy, GBool extend);
void endSelection(int wx, int wy);
void mouseMove(int wx, int wy);
void selectWord(int wx, int wy);
void selectLine(int wx, int wy);
QString getSelectedTextQString();
void copySelection(GBool toClipboard);
//----- hyperlinks
GBool doAction(LinkAction *action);
LinkAction *getLinkAction() { return linkAction; }
QString getLinkInfo(LinkAction *action);
GString *mungeURL(GString *url);
//----- find
virtual GBool find(char *s, GBool caseSensitive, GBool next,
GBool backward, GBool wholeWord, GBool onePageOnly);
virtual GBool findU(Unicode *u, int len, GBool caseSensitive,
GBool next, GBool backward,
GBool wholeWord, GBool onePageOnly);
//----- password dialog
virtual GString *getPassword();
//----- misc access
virtual void setBusyCursor(GBool busy);
void doSetCursor(const QCursor &cursor);
void doUnsetCursor();
void takeFocus();
QSize getBestSize();
int getDisplayDpi() { return displayDpi; }
double getScaleFactor() { return scaleFactor; }
void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
GBool getHyperlinksEnabled() { return hyperlinksEnabled; }
void enableExternalHyperlinks(GBool on) { externalHyperlinksEnabled = on; }
GBool getExternalHyperlinksEnabled() { return externalHyperlinksEnabled; }
void enableSelect(GBool on) { selectEnabled = on; }
void enablePan(GBool on) { panEnabled = on; }
void setShowPasswordDialog(GBool show) { showPasswordDialog = show; }
void setUpdateCbk(QtPDFUpdateCbk cbk, void *data)
{ updateCbk = cbk; updateCbkData = data; }
void setMidPageChangedCbk(QtPDFMidPageChangedCbk cbk, void *data)
{ midPageChangedCbk = cbk; midPageChangedCbkData = data; }
void setPreLoadCbk(QtPDFLoadCbk cbk, void *data)
{ preLoadCbk = cbk; preLoadCbkData = data; }
void setPostLoadCbk(QtPDFLoadCbk cbk, void *data)
{ postLoadCbk = cbk; postLoadCbkData = data; }
void setActionCbk(QtPDFActionCbk cbk, void *data)
{ actionCbk = cbk; actionCbkData = data; }
void setLinkCbk(QtPDFLinkCbk cbk, void *data)
{ linkCbk = cbk; linkCbkData = data; }
void setSelectDoneCbk(QtPDFSelectDoneCbk cbk, void *data)
{ selectDoneCbk = cbk; selectDoneCbkData = data; }
void setPaintDoneCbk(QtPDFPaintDoneCbk cbk, void *data)
{ paintDoneCbk = cbk; paintDoneCbkData = data; }
//----- GUI events
void resizeEvent();
void paintEvent(int x, int y, int w, int h);
void scrollEvent();
virtual void tick();
private:
//----- hyperlinks
void doLinkCbk(LinkAction *action);
void runCommand(GString *cmdFmt, GString *arg);
//----- PDFCore callbacks
virtual void invalidate(int x, int y, int w, int h);
virtual void updateScrollbars();
virtual GBool checkForNewFile();
virtual void preLoad();
virtual void postLoad();
QWidget *viewport;
QScrollBar *hScrollBar;
QScrollBar *vScrollBar;
int displayDpi;
double scaleFactor;
GBool dragging;
GBool panning;
int panMX, panMY;
GBool inUpdateScrollbars;
int oldFirstPage;
int oldMidPage;
LinkAction *linkAction; // mouse cursor is over this link
LinkAction *lastLinkAction; // getLinkInfo() caches an action
QString lastLinkActionInfo;
QDateTime modTime; // last modification time of PDF file
QtPDFUpdateCbk updateCbk;
void *updateCbkData;
QtPDFMidPageChangedCbk midPageChangedCbk;
void *midPageChangedCbkData;
QtPDFLoadCbk preLoadCbk;
void *preLoadCbkData;
QtPDFLoadCbk postLoadCbk;
void *postLoadCbkData;
QtPDFActionCbk actionCbk;
void *actionCbkData;
QtPDFLinkCbk linkCbk;
void *linkCbkData;
QtPDFSelectDoneCbk selectDoneCbk;
void *selectDoneCbkData;
QtPDFPaintDoneCbk paintDoneCbk;
void *paintDoneCbkData;
GBool hyperlinksEnabled;
GBool externalHyperlinksEnabled;
GBool selectEnabled;
GBool panEnabled;
GBool showPasswordDialog;
};
#endif
|