]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/XPDFCore.h
Import of Xpdf 3.00
[evince.git] / pdf / xpdf / XPDFCore.h
1 //========================================================================
2 //
3 // XPDFCore.h
4 //
5 // Copyright 2002-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifndef XPDFCORE_H
10 #define XPDFCORE_H
11
12 #include <aconf.h>
13
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17
18 #define Object XtObject
19 #include <Xm/XmAll.h>
20 #undef Object
21 #include <aconf.h>
22 #include "gtypes.h"
23 #include "gfile.h" // for time_t
24 #include "SplashTypes.h"
25
26 class GString;
27 class GList;
28 class BaseStream;
29 class PDFDoc;
30 class LinkAction;
31 class LinkDest;
32 class XSplashOutputDev;
33
34 //------------------------------------------------------------------------
35 // zoom factor
36 //------------------------------------------------------------------------
37
38 #define zoomPage  -1
39 #define zoomWidth -2
40 #define defZoom   125
41
42 //------------------------------------------------------------------------
43 // XPDFHistory
44 //------------------------------------------------------------------------
45
46 struct XPDFHistory {
47   GString *fileName;
48   int page;
49 };
50
51 #define xpdfHistorySize 50
52
53 //------------------------------------------------------------------------
54 // XPDFRegion
55 //------------------------------------------------------------------------
56
57 struct XPDFRegion {
58   int page;
59   double xMin, yMin, xMax, yMax;
60   SplashRGB8 color;
61   SplashRGB8 selectColor;
62   GBool selectable;
63 };
64
65 //------------------------------------------------------------------------
66 // callbacks
67 //------------------------------------------------------------------------
68
69 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
70                                 int pageNum, int numPages, char *linkLabel);
71
72 typedef void (*XPDFActionCbk)(void *data, char *action);
73
74 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
75                                 Guint modifiers);
76
77 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
78
79 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
80
81 //------------------------------------------------------------------------
82 // XPDFCore
83 //------------------------------------------------------------------------
84
85 class XPDFCore {
86 public:
87
88   // Create viewer core inside <parentWidgetA>.
89   XPDFCore(Widget shellA, Widget parentWidgetA,
90            SplashRGB8 paperColorA, GBool fullScreenA,
91            GBool reverseVideo, GBool installCmap, int rgbCubeSize);
92
93   ~XPDFCore();
94
95   //----- loadFile / displayPage / displayDest
96
97   // Load a new file.  Returns pdfOk or error code.
98   int loadFile(GString *fileName, GString *ownerPassword = NULL,
99                GString *userPassword = NULL);
100
101   // Load a new file, via a Stream instead of a file name.  Returns
102   // pdfOk or error code.
103   int loadFile(BaseStream *stream, GString *ownerPassword = NULL,
104                GString *userPassword = NULL);
105
106   // Resize the window to fit page <pg> of the current document.
107   void resizeToPage(int pg);
108
109   // Clear out the current document, if any.
110   void clear();
111
112   // Display (or redisplay) the specified page.  If <scrollToTop> is
113   // set, the window is vertically scrolled to the top; otherwise, no
114   // scrolling is done.  If <addToHist> is set, this page change is
115   // added to the history list.
116   void displayPage(int pageA, double zoomA, int rotateA,
117                    GBool scrollToTop, GBool addToHist);
118
119   // Display a link destination.
120   void displayDest(LinkDest *dest, double zoomA, int rotateA,
121                    GBool addToHist);
122
123   //----- page/position changes
124
125   void gotoNextPage(int inc, GBool top);
126   void gotoPrevPage(int dec, GBool top, GBool bottom);
127   void goForward();
128   void goBackward();
129   void scrollLeft(int nCols = 1);
130   void scrollRight(int nCols = 1);
131   void scrollUp(int nLines = 1);
132   void scrollDown(int nLines = 1);
133   void scrollPageUp();
134   void scrollPageDown();
135   void scrollTo(int x, int y);
136
137   //----- selection
138
139   void setSelection(int newXMin, int newYMin, int newXMax, int newYMax);
140   void moveSelection(int mx, int my);
141   void copySelection();
142   GBool getSelection(int *xMin, int *yMin, int *xMax, int *yMax);
143   GString *extractText(int xMin, int yMin, int xMax, int yMax);
144   GString *extractText(int pageNum, int xMin, int yMin, int xMax, int yMax);
145
146   //----- hyperlinks
147
148   void doAction(LinkAction *action);
149
150
151   //----- find
152
153   void find(char *s, GBool next = gFalse);
154
155   //----- simple modal dialogs
156
157   GBool doQuestionDialog(char *title, GString *msg);
158   void doInfoDialog(char *title, GString *msg);
159   void doErrorDialog(char *title, GString *msg);
160
161   //----- misc access
162
163   Widget getWidget() { return scrolledWin; }
164   Widget getDrawAreaWidget() { return drawArea; }
165   PDFDoc *getDoc() { return doc; }
166   XSplashOutputDev *getOutputDev() { return out; }
167   int getPageNum() { return page; }
168   double getZoom() { return zoom; }
169   double getZoomDPI() { return dpi; }
170   int getRotate() { return rotate; }
171   GBool canGoBack() { return historyBLen > 1; }
172   GBool canGoForward() { return historyFLen > 0; }
173   int getScrollX() { return scrollX; }
174   int getScrollY() { return scrollY; }
175   int getDrawAreaWidth() { return drawAreaWidth; }
176   int getDrawAreaHeight() { return drawAreaHeight; }
177   void setBusyCursor(GBool busy);
178   Cursor getBusyCursor() { return busyCursor; }
179   void takeFocus();
180   void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
181   void enableSelect(GBool on) { selectEnabled = on; }
182   void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
183     { updateCbk = cbk; updateCbkData = data; }
184   void setActionCbk(XPDFActionCbk cbk, void *data)
185     { actionCbk = cbk; actionCbkData = data; }
186   void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
187     { keyPressCbk = cbk; keyPressCbkData = data; }
188   void setMouseCbk(XPDFMouseCbk cbk, void *data)
189     { mouseCbk = cbk; mouseCbkData = data; }
190   void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
191     { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
192
193 private:
194
195   //----- hyperlinks
196   GBool doLink(int mx, int my);
197   void runCommand(GString *cmdFmt, GString *arg);
198   GString *mungeURL(GString *url);
199
200   //----- selection
201   static Boolean convertSelectionCbk(Widget widget, Atom *selection,
202                                      Atom *target, Atom *type,
203                                      XtPointer *value, unsigned long *length,
204                                      int *format);
205
206
207   //----- GUI code
208   void initWindow();
209   static void hScrollChangeCbk(Widget widget, XtPointer ptr,
210                                XtPointer callData);
211   static void hScrollDragCbk(Widget widget, XtPointer ptr,
212                              XtPointer callData);
213   static void vScrollChangeCbk(Widget widget, XtPointer ptr,
214                                XtPointer callData);
215   static void vScrollDragCbk(Widget widget, XtPointer ptr,
216                              XtPointer callData);
217   static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData);
218   static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData);
219   static void outputDevRedrawCbk(void *data);
220   static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
221   void keyPress(char *s, KeySym key, Guint modifiers);
222   void redrawRectangle(int x, int y, int w, int h);
223   void updateScrollBars();
224   void setCursor(Cursor cursor);
225   GBool doDialog(int type, GBool hasCancel,
226                  char *title, GString *msg);
227   static void dialogOkCbk(Widget widget, XtPointer ptr,
228                           XtPointer callData);
229   static void dialogCancelCbk(Widget widget, XtPointer ptr,
230                               XtPointer callData);
231
232   SplashRGB8 paperColor;
233   GBool fullScreen;
234
235   Display *display;
236   int screenNum;
237   Visual *visual;
238   Colormap colormap;
239   Widget shell;                 // top-level shell containing the widget
240   Widget parentWidget;          // parent widget (not created by XPDFCore)
241   Widget scrolledWin;
242   Widget hScrollBar;
243   Widget vScrollBar;
244   Widget drawAreaFrame;
245   Widget drawArea;
246   Cursor busyCursor, linkCursor, selectCursor;
247   Cursor currentCursor;
248   GC drawAreaGC;                // GC for blitting into drawArea
249
250   int drawAreaWidth, drawAreaHeight;
251   int scrollX, scrollY;         // current upper-left corner
252
253   int selectXMin, selectYMin,   // coordinates of current selection:
254       selectXMax, selectYMax;   //   (xMin==xMax || yMin==yMax) means there
255                                 //   is no selection
256   GBool dragging;               // set while selection is being dragged
257   GBool lastDragLeft;           // last dragged selection edge was left/right
258   GBool lastDragTop;            // last dragged selection edge was top/bottom
259   static GString *currentSelection;  // selected text
260   static XPDFCore *currentSelectionOwner;
261   static Atom targetsAtom;
262
263   GBool panning;
264   int panMX, panMY;
265
266   XPDFHistory                   // page history queue
267     history[xpdfHistorySize];
268   int historyCur;               // currently displayed page
269   int historyBLen;              // number of valid entries backward from
270                                 //   current entry
271   int historyFLen;              // number of valid entries forward from
272                                 //   current entry
273
274   PDFDoc *doc;                  // current PDF file
275   int page;                     // current page number
276   double zoom;                  // current zoom level, in percent of 72 dpi
277   double dpi;                   // current zoom level, in DPI
278   int rotate;                   // current page rotation
279   time_t modTime;               // last modification time of PDF file
280
281   LinkAction *linkAction;       // mouse cursor is over this link
282
283
284   XPDFUpdateCbk updateCbk;
285   void *updateCbkData;
286   XPDFActionCbk actionCbk;
287   void *actionCbkData;
288   XPDFKeyPressCbk keyPressCbk;
289   void *keyPressCbkData;
290   XPDFMouseCbk mouseCbk;
291   void *mouseCbkData;
292   XPDFReqPasswordCbk reqPasswordCbk;
293   void *reqPasswordCbkData;
294
295   GBool hyperlinksEnabled;
296   GBool selectEnabled;
297
298   XSplashOutputDev *out;
299
300   int dialogDone;
301 };
302
303 #endif