]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/XPDFCore.h
348486f0ff9c786bfe8f994a98c40b6d638f8bb5
[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   void takeFocus();
173   void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
174   void enableSelect(GBool on) { selectEnabled = on; }
175   void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
176     { updateCbk = cbk; updateCbkData = data; }
177   void setActionCbk(XPDFActionCbk cbk, void *data)
178     { actionCbk = cbk; actionCbkData = data; }
179   void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
180     { keyPressCbk = cbk; keyPressCbkData = data; }
181   void setMouseCbk(XPDFMouseCbk cbk, void *data)
182     { mouseCbk = cbk; mouseCbkData = data; }
183   void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
184     { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
185
186 private:
187
188   //----- hyperlinks
189   void doLink(int mx, int my);
190   void runCommand(GString *cmdFmt, GString *arg);
191
192   //----- selection
193   static Boolean convertSelectionCbk(Widget widget, Atom *selection,
194                                      Atom *target, Atom *type,
195                                      XtPointer *value, unsigned long *length,
196                                      int *format);
197
198
199   //----- GUI code
200   void initWindow();
201   static void hScrollChangeCbk(Widget widget, XtPointer ptr,
202                                XtPointer callData);
203   static void hScrollDragCbk(Widget widget, XtPointer ptr,
204                              XtPointer callData);
205   static void vScrollChangeCbk(Widget widget, XtPointer ptr,
206                                XtPointer callData);
207   static void vScrollDragCbk(Widget widget, XtPointer ptr,
208                              XtPointer callData);
209   static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData);
210   static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData);
211   static void outputDevRedrawCbk(void *data);
212   static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
213   void keyPress(char *s, KeySym key, Guint modifiers);
214   void redrawRectangle(int x, int y, int w, int h);
215   void updateScrollBars();
216   void setCursor(Cursor cursor);
217   GBool doDialog(int type, GBool hasCancel,
218                  char *title, GString *msg);
219   static void dialogOkCbk(Widget widget, XtPointer ptr,
220                           XtPointer callData);
221   static void dialogCancelCbk(Widget widget, XtPointer ptr,
222                               XtPointer callData);
223
224   Gulong paperColor;
225   GBool fullScreen;
226
227   Display *display;
228   int screenNum;
229   Visual *visual;
230   Colormap colormap;
231   Widget shell;                 // top-level shell containing the widget
232   Widget parentWidget;          // parent widget (not created by XPDFCore)
233   Widget scrolledWin;
234   Widget hScrollBar;
235   Widget vScrollBar;
236   Widget drawAreaFrame;
237   Widget drawArea;
238   Cursor busyCursor, linkCursor, selectCursor;
239   Cursor currentCursor;
240   GC drawAreaGC;                // GC for blitting into drawArea
241   GC selectGC;
242   GC highlightGC;
243
244   int drawAreaWidth, drawAreaHeight;
245   int scrollX, scrollY;         // current upper-left corner
246
247   int selectXMin, selectYMin,   // coordinates of current selection:
248       selectXMax, selectYMax;   //   (xMin==xMax || yMin==yMax) means there
249                                 //   is no selection
250   GBool dragging;               // set while selection is being dragged
251   GBool lastDragLeft;           // last dragged selection edge was left/right
252   GBool lastDragTop;            // last dragged selection edge was top/bottom
253   static GString *currentSelection;  // selected text
254   static XPDFCore *currentSelectionOwner;
255
256   GBool panning;
257   int panMX, panMY;
258
259   XPDFHistory                   // page history queue
260     history[xpdfHistorySize];
261   int historyCur;               // currently displayed page
262   int historyBLen;              // number of valid entries backward from
263                                 //   current entry
264   int historyFLen;              // number of valid entries forward from
265                                 //   current entry
266
267   PDFDoc *doc;                  // current PDF file
268   int page;                     // current page number
269   int zoom;                     // current zoom level
270   double dpi;                   // current zoom level, in DPI
271   int rotate;                   // current page rotation
272   time_t modTime;               // last modification time of PDF file
273
274   LinkAction *linkAction;       // mouse cursor is over this link
275
276
277   XPDFUpdateCbk updateCbk;
278   void *updateCbkData;
279   XPDFActionCbk actionCbk;
280   void *actionCbkData;
281   XPDFKeyPressCbk keyPressCbk;
282   void *keyPressCbkData;
283   XPDFMouseCbk mouseCbk;
284   void *mouseCbkData;
285   XPDFReqPasswordCbk reqPasswordCbk;
286   void *reqPasswordCbkData;
287
288   GBool hyperlinksEnabled;
289   GBool selectEnabled;
290
291   XPixmapOutputDev *out;
292
293   int dialogDone;
294 };
295
296 #endif