1 //========================================================================
5 // Copyright 2002 Glyph & Cog, LLC
7 //========================================================================
14 #ifdef USE_GCC_PRAGMAS
18 #define Object XtObject
23 #include "gfile.h" // for time_t
30 class XPixmapOutputDev;
32 //------------------------------------------------------------------------
34 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
51 #define xpdfHistorySize 50
53 //------------------------------------------------------------------------
55 //------------------------------------------------------------------------
59 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 // Resize the window to fit page <pg> of the current document.
101 void resizeToPage(int pg);
103 // Clear out the current document, if any.
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);
113 // Display a link destination.
114 void displayDest(LinkDest *dest, int zoomA, int rotateA,
117 //----- page/position changes
119 void gotoNextPage(int inc, GBool top);
120 void gotoPrevPage(int dec, GBool top, GBool bottom);
123 void scrollLeft(int nCols = 1);
124 void scrollRight(int nCols = 1);
125 void scrollUp(int nLines = 1);
126 void scrollDown(int nLines = 1);
128 void scrollPageDown();
129 void scrollTo(int x, int y);
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);
142 void doAction(LinkAction *action);
149 //----- simple modal dialogs
151 GBool doQuestionDialog(char *title, GString *msg);
152 void doInfoDialog(char *title, GString *msg);
153 void doErrorDialog(char *title, GString *msg);
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);
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; }
189 void doLink(int mx, int my);
190 void runCommand(GString *cmdFmt, GString *arg);
193 static Boolean convertSelectionCbk(Widget widget, Atom *selection,
194 Atom *target, Atom *type,
195 XtPointer *value, unsigned long *length,
201 static void hScrollChangeCbk(Widget widget, XtPointer ptr,
203 static void hScrollDragCbk(Widget widget, XtPointer ptr,
205 static void vScrollChangeCbk(Widget widget, XtPointer ptr,
207 static void vScrollDragCbk(Widget widget, XtPointer ptr,
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,
221 static void dialogCancelCbk(Widget widget, XtPointer ptr,
231 Widget shell; // top-level shell containing the widget
232 Widget parentWidget; // parent widget (not created by XPDFCore)
236 Widget drawAreaFrame;
238 Cursor busyCursor, linkCursor, selectCursor;
239 Cursor currentCursor;
240 GC drawAreaGC; // GC for blitting into drawArea
244 int drawAreaWidth, drawAreaHeight;
245 int scrollX, scrollY; // current upper-left corner
247 int selectXMin, selectYMin, // coordinates of current selection:
248 selectXMax, selectYMax; // (xMin==xMax || yMin==yMax) means there
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;
259 XPDFHistory // page history queue
260 history[xpdfHistorySize];
261 int historyCur; // currently displayed page
262 int historyBLen; // number of valid entries backward from
264 int historyFLen; // number of valid entries forward from
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
274 LinkAction *linkAction; // mouse cursor is over this link
277 XPDFUpdateCbk updateCbk;
279 XPDFActionCbk actionCbk;
281 XPDFKeyPressCbk keyPressCbk;
282 void *keyPressCbkData;
283 XPDFMouseCbk mouseCbk;
285 XPDFReqPasswordCbk reqPasswordCbk;
286 void *reqPasswordCbkData;
288 GBool hyperlinksEnabled;
291 XPixmapOutputDev *out;