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