Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pdf/xpdf/XPDFCore.h
blob: 64357362375111392720c9d21611b2642d626b14 (plain)
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//========================================================================
//
// XPDFCore.h
//
// Copyright 2002-2003 Glyph & Cog, LLC
//
//========================================================================

#ifndef XPDFCORE_H
#define XPDFCORE_H

#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

#define Object XtObject
#include <Xm/XmAll.h>
#undef Object
#include <aconf.h>
#include "gtypes.h"
#include "gfile.h" // for time_t

class GString;
class GList;
class BaseStream;
class PDFDoc;
class LinkAction;
class LinkDest;
class XPixmapOutputDev;

//------------------------------------------------------------------------
// zoom factor
//------------------------------------------------------------------------

#define minZoom    -5
#define maxZoom     5
#define zoomPage  100
#define zoomWidth 101
#define defZoom     1

//------------------------------------------------------------------------
// XPDFHistory
//------------------------------------------------------------------------

struct XPDFHistory {
  GString *fileName;
  int page;
};

#define xpdfHistorySize 50

//------------------------------------------------------------------------
// XPDFRegion
//------------------------------------------------------------------------

struct XPDFRegion {
  int page;
  double xMin, yMin, xMax, yMax;
  Gulong color;
  Gulong selectColor;
  GBool selectable;
};

//------------------------------------------------------------------------
// callbacks
//------------------------------------------------------------------------

typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
				int pageNum, int numPages, char *linkLabel);

typedef void (*XPDFActionCbk)(void *data, char *action);

typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
				Guint modifiers);

typedef void (*XPDFMouseCbk)(void *data, XEvent *event);

typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);

//------------------------------------------------------------------------
// XPDFCore
//------------------------------------------------------------------------

class XPDFCore {
public:

  // Create viewer core inside <parentWidgetA>.
  XPDFCore(Widget shellA, Widget parentWidgetA,
	   Gulong paperColorA, GBool fullScreenA, GBool reverseVideo,
	   GBool installCmap, int rgbCubeSize);

  ~XPDFCore();

  //----- loadFile / displayPage / displayDest

  // Load a new file.  Returns pdfOk or error code.
  int loadFile(GString *fileName, GString *ownerPassword = NULL,
	       GString *userPassword = NULL);

  // Load a new file, via a Stream instead of a file name.  Returns
  // pdfOk or error code.
  int loadFile(BaseStream *stream, GString *ownerPassword = NULL,
	       GString *userPassword = NULL);

  // Resize the window to fit page <pg> of the current document.
  void resizeToPage(int pg);

  // Clear out the current document, if any.
  void clear();

  // Display (or redisplay) the specified page.  If <scrollToTop> is
  // set, the window is vertically scrolled to the top; otherwise, no
  // scrolling is done.  If <addToHist> is set, this page change is
  // added to the history list.
  void displayPage(int pageA, int zoomA, int rotateA,
		   GBool scrollToTop, GBool addToHist);

  // Display a link destination.
  void displayDest(LinkDest *dest, int zoomA, int rotateA,
		   GBool addToHist);

  //----- page/position changes

  void gotoNextPage(int inc, GBool top);
  void gotoPrevPage(int dec, GBool top, GBool bottom);
  void goForward();
  void goBackward();
  void scrollLeft(int nCols = 1);
  void scrollRight(int nCols = 1);
  void scrollUp(int nLines = 1);
  void scrollDown(int nLines = 1);
  void scrollPageUp();
  void scrollPageDown();
  void scrollTo(int x, int y);

  //----- selection

  void setSelection(int newXMin, int newYMin, int newXMax, int newYMax);
  void moveSelection(int mx, int my);
  void copySelection();
  GBool getSelection(int *xMin, int *yMin, int *xMax, int *yMax);
  GString *extractText(int xMin, int yMin, int xMax, int yMax);
  GString *extractText(int pageNum, int xMin, int yMin, int xMax, int yMax);

  //----- hyperlinks

  void doAction(LinkAction *action);


  //----- find

  void find(char *s);

  //----- simple modal dialogs

  GBool doQuestionDialog(char *title, GString *msg);
  void doInfoDialog(char *title, GString *msg);
  void doErrorDialog(char *title, GString *msg);

  //----- misc access

  Widget getWidget() { return scrolledWin; }
  Widget getDrawAreaWidget() { return drawArea; }
  PDFDoc *getDoc() { return doc; }
  XPixmapOutputDev *getOutputDev() { return out; }
  int getPageNum() { return page; }
  int getZoom() { return zoom; }
  double getZoomDPI() { return dpi; }
  int getRotate() { return rotate; }
  GBool canGoBack() { return historyBLen > 1; }
  GBool canGoForward() { return historyFLen > 0; }
  int getScrollX() { return scrollX; }
  int getScrollY() { return scrollY; }
  int getDrawAreaWidth() { return drawAreaWidth; }
  int getDrawAreaHeight() { return drawAreaHeight; }
  void setBusyCursor(GBool busy);
  Cursor getBusyCursor() { return busyCursor; }
  void takeFocus();
  void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
  void enableSelect(GBool 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; }
  void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
    { reqPasswordCbk = cbk; reqPasswordCbkData = data; }

private:

  //----- hyperlinks
  void doLink(int mx, int my);
  void runCommand(GString *cmdFmt, GString *arg);

  //----- selection
  static Boolean convertSelectionCbk(Widget widget, Atom *selection,
				     Atom *target, Atom *type,
				     XtPointer *value, unsigned long *length,
				     int *format);


  //----- GUI code
  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 outputDevRedrawCbk(void *data);
  static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
  void keyPress(char *s, KeySym key, Guint modifiers);
  void redrawRectangle(int x, int y, int w, int h);
  void updateScrollBars();
  void setCursor(Cursor cursor);
  GBool doDialog(int type, GBool hasCancel,
		 char *title, GString *msg);
  static void dialogOkCbk(Widget widget, XtPointer ptr,
			  XtPointer callData);
  static void dialogCancelCbk(Widget widget, XtPointer ptr,
			      XtPointer callData);

  Gulong paperColor;
  GBool fullScreen;

  Display *display;
  int screenNum;
  Visual *visual;
  Colormap colormap;
  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
  GC selectGC;
  GC highlightGC;

  int drawAreaWidth, drawAreaHeight;
  int scrollX, scrollY;		// current upper-left corner

  int selectXMin, selectYMin,	// coordinates of current selection:
      selectXMax, selectYMax;	//   (xMin==xMax || yMin==yMax) means there
				//   is no selection
  GBool dragging;		// set while selection is being dragged
  GBool lastDragLeft;		// last dragged selection edge was left/right
  GBool lastDragTop;		// last dragged selection edge was top/bottom
  static GString *currentSelection;  // selected text
  static XPDFCore *currentSelectionOwner;
  static Atom targetsAtom;

  GBool panning;
  int panMX, panMY;

  XPDFHistory			// page history queue
    history[xpdfHistorySize];
  int historyCur;               // currently displayed page
  int historyBLen;              // number of valid entries backward from
                                //   current entry
  int historyFLen;              // number of valid entries forward from
                                //   current entry

  PDFDoc *doc;			// current PDF file
  int page;			// current page number
  int zoom;			// current zoom level
  double dpi;			// current zoom level, in DPI
  int rotate;			// current page rotation
  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;
  XPDFReqPasswordCbk reqPasswordCbk;
  void *reqPasswordCbkData;

  GBool hyperlinksEnabled;
  GBool selectEnabled;

  XPixmapOutputDev *out;

  int dialogDone;
};

#endif