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