1 //========================================================================
5 // Copyright 2002-2003 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
18 #define Object XtObject
23 #include "gfile.h" // for time_t
31 class XPixmapOutputDev;
33 //------------------------------------------------------------------------
35 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
52 #define xpdfHistorySize 50
54 //------------------------------------------------------------------------
56 //------------------------------------------------------------------------
60 double xMin, yMin, xMax, yMax;
66 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
70 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
71 int pageNum, int numPages, char *linkLabel);
73 typedef void (*XPDFActionCbk)(void *data, char *action);
75 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
78 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
80 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
89 // Create viewer core inside <parentWidgetA>.
90 XPDFCore(Widget shellA, Widget parentWidgetA,
91 Gulong paperColorA, GBool fullScreenA, GBool reverseVideo,
92 GBool installCmap, int rgbCubeSize);
96 //----- loadFile / displayPage / displayDest
98 // Load a new file. Returns pdfOk or error code.
99 int loadFile(GString *fileName, GString *ownerPassword = NULL,
100 GString *userPassword = NULL);
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);
107 // Resize the window to fit page <pg> of the current document.
108 void resizeToPage(int pg);
110 // Clear out the current document, if any.
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);
120 // Display a link destination.
121 void displayDest(LinkDest *dest, int zoomA, int rotateA,
124 //----- page/position changes
126 void gotoNextPage(int inc, GBool top);
127 void gotoPrevPage(int dec, GBool top, GBool bottom);
130 void scrollLeft(int nCols = 1);
131 void scrollRight(int nCols = 1);
132 void scrollUp(int nLines = 1);
133 void scrollDown(int nLines = 1);
135 void scrollPageDown();
136 void scrollTo(int x, int y);
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);
149 void doAction(LinkAction *action);
156 //----- simple modal dialogs
158 GBool doQuestionDialog(char *title, GString *msg);
159 void doInfoDialog(char *title, GString *msg);
160 void doErrorDialog(char *title, GString *msg);
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; }
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; }
197 void doLink(int mx, int my);
198 void runCommand(GString *cmdFmt, GString *arg);
201 static Boolean convertSelectionCbk(Widget widget, Atom *selection,
202 Atom *target, Atom *type,
203 XtPointer *value, unsigned long *length,
209 static void hScrollChangeCbk(Widget widget, XtPointer ptr,
211 static void hScrollDragCbk(Widget widget, XtPointer ptr,
213 static void vScrollChangeCbk(Widget widget, XtPointer ptr,
215 static void vScrollDragCbk(Widget widget, XtPointer ptr,
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,
229 static void dialogCancelCbk(Widget widget, XtPointer ptr,
239 Widget shell; // top-level shell containing the widget
240 Widget parentWidget; // parent widget (not created by XPDFCore)
244 Widget drawAreaFrame;
246 Cursor busyCursor, linkCursor, selectCursor;
247 Cursor currentCursor;
248 GC drawAreaGC; // GC for blitting into drawArea
252 int drawAreaWidth, drawAreaHeight;
253 int scrollX, scrollY; // current upper-left corner
255 int selectXMin, selectYMin, // coordinates of current selection:
256 selectXMax, selectYMax; // (xMin==xMax || yMin==yMax) means there
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;
268 XPDFHistory // page history queue
269 history[xpdfHistorySize];
270 int historyCur; // currently displayed page
271 int historyBLen; // number of valid entries backward from
273 int historyFLen; // number of valid entries forward from
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
283 LinkAction *linkAction; // mouse cursor is over this link
286 XPDFUpdateCbk updateCbk;
288 XPDFActionCbk actionCbk;
290 XPDFKeyPressCbk keyPressCbk;
291 void *keyPressCbkData;
292 XPDFMouseCbk mouseCbk;
294 XPDFReqPasswordCbk reqPasswordCbk;
295 void *reqPasswordCbkData;
297 GBool hyperlinksEnabled;
300 XPixmapOutputDev *out;