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
24 #include "SplashTypes.h"
32 class XSplashOutputDev;
34 //------------------------------------------------------------------------
36 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
51 #define xpdfHistorySize 50
53 //------------------------------------------------------------------------
55 //------------------------------------------------------------------------
59 double xMin, yMin, xMax, yMax;
61 SplashRGB8 selectColor;
65 //------------------------------------------------------------------------
67 //------------------------------------------------------------------------
69 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
70 int pageNum, int numPages, char *linkLabel);
72 typedef void (*XPDFActionCbk)(void *data, char *action);
74 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
77 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
79 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
88 // Create viewer core inside <parentWidgetA>.
89 XPDFCore(Widget shellA, Widget parentWidgetA,
90 SplashRGB8 paperColorA, GBool fullScreenA,
91 GBool reverseVideo, GBool installCmap, int rgbCubeSize);
95 //----- loadFile / displayPage / displayDest
97 // Load a new file. Returns pdfOk or error code.
98 int loadFile(GString *fileName, GString *ownerPassword = NULL,
99 GString *userPassword = NULL);
101 // Load a new file, via a Stream instead of a file name. Returns
102 // pdfOk or error code.
103 int loadFile(BaseStream *stream, GString *ownerPassword = NULL,
104 GString *userPassword = NULL);
106 // Resize the window to fit page <pg> of the current document.
107 void resizeToPage(int pg);
109 // Clear out the current document, if any.
112 // Display (or redisplay) the specified page. If <scrollToTop> is
113 // set, the window is vertically scrolled to the top; otherwise, no
114 // scrolling is done. If <addToHist> is set, this page change is
115 // added to the history list.
116 void displayPage(int pageA, double zoomA, int rotateA,
117 GBool scrollToTop, GBool addToHist);
119 // Display a link destination.
120 void displayDest(LinkDest *dest, double zoomA, int rotateA,
123 //----- page/position changes
125 void gotoNextPage(int inc, GBool top);
126 void gotoPrevPage(int dec, GBool top, GBool bottom);
129 void scrollLeft(int nCols = 1);
130 void scrollRight(int nCols = 1);
131 void scrollUp(int nLines = 1);
132 void scrollDown(int nLines = 1);
134 void scrollPageDown();
135 void scrollTo(int x, int y);
139 void setSelection(int newXMin, int newYMin, int newXMax, int newYMax);
140 void moveSelection(int mx, int my);
141 void copySelection();
142 GBool getSelection(int *xMin, int *yMin, int *xMax, int *yMax);
143 GString *extractText(int xMin, int yMin, int xMax, int yMax);
144 GString *extractText(int pageNum, int xMin, int yMin, int xMax, int yMax);
148 void doAction(LinkAction *action);
153 void find(char *s, GBool next = gFalse);
155 //----- simple modal dialogs
157 GBool doQuestionDialog(char *title, GString *msg);
158 void doInfoDialog(char *title, GString *msg);
159 void doErrorDialog(char *title, GString *msg);
163 Widget getWidget() { return scrolledWin; }
164 Widget getDrawAreaWidget() { return drawArea; }
165 PDFDoc *getDoc() { return doc; }
166 XSplashOutputDev *getOutputDev() { return out; }
167 int getPageNum() { return page; }
168 double getZoom() { return zoom; }
169 double getZoomDPI() { return dpi; }
170 int getRotate() { return rotate; }
171 GBool canGoBack() { return historyBLen > 1; }
172 GBool canGoForward() { return historyFLen > 0; }
173 int getScrollX() { return scrollX; }
174 int getScrollY() { return scrollY; }
175 int getDrawAreaWidth() { return drawAreaWidth; }
176 int getDrawAreaHeight() { return drawAreaHeight; }
177 void setBusyCursor(GBool busy);
178 Cursor getBusyCursor() { return busyCursor; }
180 void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
181 void enableSelect(GBool on) { selectEnabled = on; }
182 void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
183 { updateCbk = cbk; updateCbkData = data; }
184 void setActionCbk(XPDFActionCbk cbk, void *data)
185 { actionCbk = cbk; actionCbkData = data; }
186 void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
187 { keyPressCbk = cbk; keyPressCbkData = data; }
188 void setMouseCbk(XPDFMouseCbk cbk, void *data)
189 { mouseCbk = cbk; mouseCbkData = data; }
190 void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
191 { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
196 GBool doLink(int mx, int my);
197 void runCommand(GString *cmdFmt, GString *arg);
198 GString *mungeURL(GString *url);
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,
232 SplashRGB8 paperColor;
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
250 int drawAreaWidth, drawAreaHeight;
251 int scrollX, scrollY; // current upper-left corner
253 int selectXMin, selectYMin, // coordinates of current selection:
254 selectXMax, selectYMax; // (xMin==xMax || yMin==yMax) means there
256 GBool dragging; // set while selection is being dragged
257 GBool lastDragLeft; // last dragged selection edge was left/right
258 GBool lastDragTop; // last dragged selection edge was top/bottom
259 static GString *currentSelection; // selected text
260 static XPDFCore *currentSelectionOwner;
261 static Atom targetsAtom;
266 XPDFHistory // page history queue
267 history[xpdfHistorySize];
268 int historyCur; // currently displayed page
269 int historyBLen; // number of valid entries backward from
271 int historyFLen; // number of valid entries forward from
274 PDFDoc *doc; // current PDF file
275 int page; // current page number
276 double zoom; // current zoom level, in percent of 72 dpi
277 double dpi; // current zoom level, in DPI
278 int rotate; // current page rotation
279 time_t modTime; // last modification time of PDF file
281 LinkAction *linkAction; // mouse cursor is over this link
284 XPDFUpdateCbk updateCbk;
286 XPDFActionCbk actionCbk;
288 XPDFKeyPressCbk keyPressCbk;
289 void *keyPressCbkData;
290 XPDFMouseCbk mouseCbk;
292 XPDFReqPasswordCbk reqPasswordCbk;
293 void *reqPasswordCbkData;
295 GBool hyperlinksEnabled;
298 XSplashOutputDev *out;