]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/XPDFCore.h
Import of Xpdf 2.02 for merge
[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
25 class GString;
26 class GList;
27 class BaseStream;
28 class PDFDoc;
29 class LinkAction;
30 class LinkDest;
31 class XPixmapOutputDev;
32
33 //------------------------------------------------------------------------
34 // zoom factor
35 //------------------------------------------------------------------------
36
37 #define minZoom    -5
38 #define maxZoom     5
39 #define zoomPage  100
40 #define zoomWidth 101
41 #define defZoom     1
42
43 //------------------------------------------------------------------------
44 // XPDFHistory
45 //------------------------------------------------------------------------
46
47 struct XPDFHistory {
48   GString *fileName;
49   int page;
50 };
51
52 #define xpdfHistorySize 50
53
54 //------------------------------------------------------------------------
55 // XPDFRegion
56 //------------------------------------------------------------------------
57
58 struct XPDFRegion {
59   int page;
60   double xMin, yMin, xMax, yMax;
61   Gulong color;
62   Gulong selectColor;
63   GBool selectable;
64 };
65
66 //------------------------------------------------------------------------
67 // callbacks
68 //------------------------------------------------------------------------
69
70 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
71                                 int pageNum, int numPages, char *linkLabel);
72
73 typedef void (*XPDFActionCbk)(void *data, char *action);
74
75 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
76                                 Guint modifiers);
77
78 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
79
80 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
81
82 //------------------------------------------------------------------------
83 // XPDFCore
84 //------------------------------------------------------------------------
85
86 class XPDFCore {
87 public:
88
89   // Create viewer core inside <parentWidgetA>.
90   XPDFCore(Widget shellA, Widget parentWidgetA,
91            Gulong paperColorA, GBool fullScreenA, GBool reverseVideo,
92            GBool installCmap, int rgbCubeSize);
93
94   ~XPDFCore();
95
96   //----- loadFile / displayPage / displayDest
97
98   // Load a new file.  Returns pdfOk or error code.
99   int loadFile(GString *fileName, GString *ownerPassword = NULL,
100                GString *userPassword = NULL);
101
102   // Load a new file, via a Stream instead of a file name.  Returns
103   // pdfOk or error code.
104   int loadFile(BaseStream *stream, GString *ownerPassword = NULL,
105                GString *userPassword = NULL);
106
107   // Resize the window to fit page <pg> of the current document.
108   void resizeToPage(int pg);
109
110   // Clear out the current document, if any.
111   void clear();
112
113   // Display (or redisplay) the specified page.  If <scrollToTop> is
114   // set, the window is vertically scrolled to the top; otherwise, no
115   // scrolling is done.  If <addToHist> is set, this page change is
116   // added to the history list.
117   void displayPage(int pageA, int zoomA, int rotateA,
118                    GBool scrollToTop, GBool addToHist);
119
120   // Display a link destination.
121   void displayDest(LinkDest *dest, int zoomA, int rotateA,
122                    GBool addToHist);
123
124   //----- page/position changes
125
126   void gotoNextPage(int inc, GBool top);
127   void gotoPrevPage(int dec, GBool top, GBool bottom);
128   void goForward();
129   void goBackward();
130   void scrollLeft(int nCols = 1);
131   void scrollRight(int nCols = 1);
132   void scrollUp(int nLines = 1);
133   void scrollDown(int nLines = 1);
134   void scrollPageUp();
135   void scrollPageDown();
136   void scrollTo(int x, int y);
137
138   //----- selection
139
140   void setSelection(int newXMin, int newYMin, int newXMax, int newYMax);
141   void moveSelection(int mx, int my);
142   void copySelection();
143   GBool getSelection(int *xMin, int *yMin, int *xMax, int *yMax);
144   GString *extractText(int xMin, int yMin, int xMax, int yMax);
145   GString *extractText(int pageNum, int xMin, int yMin, int xMax, int yMax);
146
147   //----- hyperlinks
148
149   void doAction(LinkAction *action);
150
151
152   //----- find
153
154   void find(char *s);
155
156   //----- simple modal dialogs
157
158   GBool doQuestionDialog(char *title, GString *msg);
159   void doInfoDialog(char *title, GString *msg);
160   void doErrorDialog(char *title, GString *msg);
161
162   //----- misc access
163
164   Widget getWidget() { return scrolledWin; }
165   Widget getDrawAreaWidget() { return drawArea; }
166   PDFDoc *getDoc() { return doc; }
167   XPixmapOutputDev *getOutputDev() { return out; }
168   int getPageNum() { return page; }
169   int getZoom() { return zoom; }
170   double getZoomDPI() { return dpi; }
171   int getRotate() { return rotate; }
172   GBool canGoBack() { return historyBLen > 1; }
173   GBool canGoForward() { return historyFLen > 0; }
174   int getScrollX() { return scrollX; }
175   int getScrollY() { return scrollY; }
176   int getDrawAreaWidth() { return drawAreaWidth; }
177   int getDrawAreaHeight() { return drawAreaHeight; }
178   void setBusyCursor(GBool busy);
179   Cursor getBusyCursor() { return busyCursor; }
180   void takeFocus();
181   void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
182   void enableSelect(GBool on) { selectEnabled = on; }
183   void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
184     { updateCbk = cbk; updateCbkData = data; }
185   void setActionCbk(XPDFActionCbk cbk, void *data)
186     { actionCbk = cbk; actionCbkData = data; }
187   void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
188     { keyPressCbk = cbk; keyPressCbkData = data; }
189   void setMouseCbk(XPDFMouseCbk cbk, void *data)
190     { mouseCbk = cbk; mouseCbkData = data; }
191   void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
192     { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
193
194 private:
195
196   //----- hyperlinks
197   void doLink(int mx, int my);
198   void runCommand(GString *cmdFmt, GString *arg);
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   Gulong 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   GC selectGC;
250   GC highlightGC;
251
252   int drawAreaWidth, drawAreaHeight;
253   int scrollX, scrollY;         // current upper-left corner
254
255   int selectXMin, selectYMin,   // coordinates of current selection:
256       selectXMax, selectYMax;   //   (xMin==xMax || yMin==yMax) means there
257                                 //   is no selection
258   GBool dragging;               // set while selection is being dragged
259   GBool lastDragLeft;           // last dragged selection edge was left/right
260   GBool lastDragTop;            // last dragged selection edge was top/bottom
261   static GString *currentSelection;  // selected text
262   static XPDFCore *currentSelectionOwner;
263   static Atom targetsAtom;
264
265   GBool panning;
266   int panMX, panMY;
267
268   XPDFHistory                   // page history queue
269     history[xpdfHistorySize];
270   int historyCur;               // currently displayed page
271   int historyBLen;              // number of valid entries backward from
272                                 //   current entry
273   int historyFLen;              // number of valid entries forward from
274                                 //   current entry
275
276   PDFDoc *doc;                  // current PDF file
277   int page;                     // current page number
278   int zoom;                     // current zoom level
279   double dpi;                   // current zoom level, in DPI
280   int rotate;                   // current page rotation
281   time_t modTime;               // last modification time of PDF file
282
283   LinkAction *linkAction;       // mouse cursor is over this link
284
285
286   XPDFUpdateCbk updateCbk;
287   void *updateCbkData;
288   XPDFActionCbk actionCbk;
289   void *actionCbkData;
290   XPDFKeyPressCbk keyPressCbk;
291   void *keyPressCbkData;
292   XPDFMouseCbk mouseCbk;
293   void *mouseCbkData;
294   XPDFReqPasswordCbk reqPasswordCbk;
295   void *reqPasswordCbkData;
296
297   GBool hyperlinksEnabled;
298   GBool selectEnabled;
299
300   XPixmapOutputDev *out;
301
302   int dialogDone;
303 };
304
305 #endif