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 //------------------------------------------------------------------------
41 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
50 #define xpdfHistorySize 50
52 //------------------------------------------------------------------------
54 //------------------------------------------------------------------------
58 double xMin, yMin, xMax, yMax;
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
68 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
69 int pageNum, int numPages, char *linkLabel);
71 typedef void (*XPDFActionCbk)(void *data, char *action);
73 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
76 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
78 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
80 //------------------------------------------------------------------------
82 //------------------------------------------------------------------------
87 // Create viewer core inside <parentWidgetA>.
88 XPDFCore(Widget shellA, Widget parentWidgetA,
89 Gulong paperColorA, GBool fullScreenA, GBool reverseVideo,
90 GBool installCmap, int rgbCubeSize);
94 //----- loadFile / displayPage / displayDest
96 // Load a new file. Returns pdfOk or error code.
97 int loadFile(GString *fileName, GString *ownerPassword = NULL,
98 GString *userPassword = NULL);
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);
105 // Resize the window to fit page <pg> of the current document.
106 void resizeToPage(int pg);
108 // Clear out the current document, if any.
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);
118 // Display a link destination.
119 void displayDest(LinkDest *dest, double zoomA, int rotateA,
122 //----- page/position changes
124 void gotoNextPage(int inc, GBool top);
125 void gotoPrevPage(int dec, GBool top, GBool bottom);
128 void scrollLeft(int nCols = 1);
129 void scrollRight(int nCols = 1);
130 void scrollUp(int nLines = 1);
131 void scrollDown(int nLines = 1);
133 void scrollPageDown();
134 void scrollTo(int x, int y);
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);
147 void doAction(LinkAction *action);
152 void find(char *s, GBool next = gFalse);
154 //----- simple modal dialogs
156 GBool doQuestionDialog(char *title, GString *msg);
157 void doInfoDialog(char *title, GString *msg);
158 void doErrorDialog(char *title, GString *msg);
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; }
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; }
195 GBool doLink(int mx, int my);
196 void runCommand(GString *cmdFmt, GString *arg);
197 GString *mungeURL(GString *url);
200 static Boolean convertSelectionCbk(Widget widget, Atom *selection,
201 Atom *target, Atom *type,
202 XtPointer *value, unsigned long *length,
208 static void hScrollChangeCbk(Widget widget, XtPointer ptr,
210 static void hScrollDragCbk(Widget widget, XtPointer ptr,
212 static void vScrollChangeCbk(Widget widget, XtPointer ptr,
214 static void vScrollDragCbk(Widget widget, XtPointer ptr,
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,
228 static void dialogCancelCbk(Widget widget, XtPointer ptr,
238 Widget shell; // top-level shell containing the widget
239 Widget parentWidget; // parent widget (not created by XPDFCore)
243 Widget drawAreaFrame;
245 Cursor busyCursor, linkCursor, selectCursor;
246 Cursor currentCursor;
247 GC drawAreaGC; // GC for blitting into drawArea
251 int drawAreaWidth, drawAreaHeight;
252 int scrollX, scrollY; // current upper-left corner
254 int selectXMin, selectYMin, // coordinates of current selection:
255 selectXMax, selectYMax; // (xMin==xMax || yMin==yMax) means there
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;
267 XPDFHistory // page history queue
268 history[xpdfHistorySize];
269 int historyCur; // currently displayed page
270 int historyBLen; // number of valid entries backward from
272 int historyFLen; // number of valid entries forward from
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
282 LinkAction *linkAction; // mouse cursor is over this link
285 XPDFUpdateCbk updateCbk;
287 XPDFActionCbk actionCbk;
289 XPDFKeyPressCbk keyPressCbk;
290 void *keyPressCbkData;
291 XPDFMouseCbk mouseCbk;
293 XPDFReqPasswordCbk reqPasswordCbk;
294 void *reqPasswordCbkData;
296 GBool hyperlinksEnabled;
299 XPixmapOutputDev *out;