forked from rbrito/xpdf-poppler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XPDFCore.h
250 lines (197 loc) · 7.72 KB
/
XPDFCore.h
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//========================================================================
//
// XPDFCore.h
//
// Copyright 2002-2003 Glyph & Cog, LLC
//
//========================================================================
#ifndef XPDFCORE_H
#define XPDFCORE_H
#include <poppler-config.h>
#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif
#define Object XtObject
#include <Xm/XmAll.h>
#undef Object
#include "poppler/goo/gfile.h" // for time_t
#include "poppler/splash/SplashTypes.h"
#include "PDFCore.h"
class GooString;
class BaseStream;
class PDFDoc;
class LinkAction;
//------------------------------------------------------------------------
#define xMaxRGBCube 6 // max size of RGB color cube
//------------------------------------------------------------------------
// callbacks
//------------------------------------------------------------------------
typedef void (*XPDFUpdateCbk)(void *data, GooString *fileName,
int pageNum, int numPages, char *linkLabel);
typedef void (*XPDFActionCbk)(void *data, char *action);
typedef void (*XPDFKeyPressCbk)(void *data, KeySym key, unsigned modifiers,
XEvent *event);
typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
//------------------------------------------------------------------------
// XPDFCore
//------------------------------------------------------------------------
class XPDFCore: public PDFCore {
public:
// Create viewer core inside <parentWidgetA>.
XPDFCore(Widget shellA, Widget parentWidgetA,
SplashColorPtr paperColorA, unsigned long paperPixelA,
unsigned long mattePixelA, bool fullScreenA, bool reverseVideoA,
bool installCmap, int rgbCubeSizeA);
~XPDFCore();
//----- loadFile / displayPage / displayDest
// Load a new file. Returns pdfOk or error code.
virtual int loadFile(GooString *fileName, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
// Load a new file, via a Stream instead of a file name. Returns
// pdfOk or error code.
virtual int loadFile(BaseStream *stream, GooString *ownerPassword = NULL,
GooString *userPassword = NULL);
// Load an already-created PDFDoc object.
virtual void loadDoc(PDFDoc *docA);
// Resize the window to fit page <pg> of the current document.
void resizeToPage(int pg);
// Update the display, given the specified parameters.
virtual void update(int topPageA, int scrollXA, int scrollYA,
double zoomA, int rotateA,
bool force, bool addToHist);
//----- page/position changes
virtual bool gotoNextPage(int inc, bool top);
virtual bool gotoPrevPage(int dec, bool top, bool bottom);
virtual bool goForward();
virtual bool goBackward();
//----- selection
void startSelection(int wx, int wy);
void endSelection(int wx, int wy);
void copySelection();
void startPan(int wx, int wy);
void endPan(int wx, int wy);
//----- hyperlinks
void doAction(LinkAction *action);
LinkAction *getLinkAction() { return linkAction; }
GooString *mungeURL(GooString *url);
//----- find
virtual bool find(char *s, bool caseSensitive,
bool next, bool backward, bool onePageOnly);
virtual bool findU(Unicode *u, int len, bool caseSensitive,
bool next, bool backward, bool onePageOnly);
//----- simple modal dialogs
bool doQuestionDialog(char *title, GooString *msg);
void doInfoDialog(char *title, GooString *msg);
void doErrorDialog(char *title, GooString *msg);
//----- password dialog
GooString *getPassword();
//----- misc access
Widget getWidget() { return scrolledWin; }
Widget getDrawAreaWidget() { return drawArea; }
virtual void setBusyCursor(bool busy);
Cursor getBusyCursor() { return busyCursor; }
void takeFocus();
void enableHyperlinks(bool on) { hyperlinksEnabled = on; }
bool getHyperlinksEnabled() { return hyperlinksEnabled; }
void enableSelect(bool on) { selectEnabled = on; }
void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
{ updateCbk = cbk; updateCbkData = data; }
void setActionCbk(XPDFActionCbk cbk, void *data)
{ actionCbk = cbk; actionCbkData = data; }
void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
{ keyPressCbk = cbk; keyPressCbkData = data; }
void setMouseCbk(XPDFMouseCbk cbk, void *data)
{ mouseCbk = cbk; mouseCbkData = data; }
bool getFullScreen() { return fullScreen; }
private:
virtual bool checkForNewFile();
//----- hyperlinks
void runCommand(GooString *cmdFmt, GooString *arg);
//----- selection
static Boolean convertSelectionCbk(Widget widget, Atom *selection,
Atom *target, Atom *type,
XtPointer *value, unsigned long *length,
int *format);
//----- GUI code
void setupX(bool installCmap, int rgbCubeSizeA);
void initWindow();
static void hScrollChangeCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void hScrollDragCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void vScrollChangeCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void vScrollDragCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData);
static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData);
static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
virtual PDFCoreTile *newTile(int xDestA, int yDestA);
virtual void updateTileData(PDFCoreTile *tileA, int xSrc, int ySrc,
int width, int height, bool composited);
virtual void redrawRect(PDFCoreTile *tileA, int xSrc, int ySrc,
int xDest, int yDest, int width, int height,
bool composited);
virtual void updateScrollbars();
void setCursor(Cursor cursor);
bool doDialog(int type, bool hasCancel,
char *title, GooString *msg);
static void dialogOkCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void dialogCancelCbk(Widget widget, XtPointer ptr,
XtPointer callData);
void initPasswordDialog();
static void passwordTextVerifyCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void passwordOkCbk(Widget widget, XtPointer ptr,
XtPointer callData);
static void passwordCancelCbk(Widget widget, XtPointer ptr,
XtPointer callData);
unsigned long paperPixel;
unsigned long mattePixel;
//~unimp: move fullScreen into PDFCore?
bool fullScreen;
Display *display;
int screenNum;
Visual *visual;
Colormap colormap;
unsigned depth; // visual depth
bool trueColor; // set if using a TrueColor visual
int rDiv, gDiv, bDiv; // RGB right shifts (for TrueColor)
int rShift, gShift, bShift; // RGB left shifts (for TrueColor)
int rgbCubeSize; // size of color cube (for non-TrueColor)
unsigned long // color cube (for non-TrueColor)
colors[xMaxRGBCube * xMaxRGBCube * xMaxRGBCube];
Widget shell; // top-level shell containing the widget
Widget parentWidget; // parent widget (not created by XPDFCore)
Widget scrolledWin;
Widget hScrollBar;
Widget vScrollBar;
Widget drawAreaFrame;
Widget drawArea;
Cursor busyCursor, linkCursor, selectCursor;
Cursor currentCursor;
GC drawAreaGC; // GC for blitting into drawArea
static GooString *currentSelection; // selected text
static XPDFCore *currentSelectionOwner;
static Atom targetsAtom;
bool panning;
int panMX, panMY;
time_t modTime; // last modification time of PDF file
LinkAction *linkAction; // mouse cursor is over this link
XPDFUpdateCbk updateCbk;
void *updateCbkData;
XPDFActionCbk actionCbk;
void *actionCbkData;
XPDFKeyPressCbk keyPressCbk;
void *keyPressCbkData;
XPDFMouseCbk mouseCbk;
void *mouseCbkData;
bool hyperlinksEnabled;
bool selectEnabled;
int dialogDone;
Widget passwordDialog;
Widget passwordText;
GooString *password;
};
#endif