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);
172 Cursor getBusyCursor() { return busyCursor; }
174 void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
175 void enableSelect(GBool on) { selectEnabled = on; }
176 void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
177 { updateCbk = cbk; updateCbkData = data; }
178 void setActionCbk(XPDFActionCbk cbk, void *data)
179 { actionCbk = cbk; actionCbkData = data; }
180 void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
181 { keyPressCbk = cbk; keyPressCbkData = data; }
182 void setMouseCbk(XPDFMouseCbk cbk, void *data)
183 { mouseCbk = cbk; mouseCbkData = data; }
184 void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
185 { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
190 void doLink(int mx, int my);
191 void runCommand(GString *cmdFmt, GString *arg);
194 static Boolean convertSelectionCbk(Widget widget, Atom *selection,
195 Atom *target, Atom *type,
196 XtPointer *value, unsigned long *length,
202 static void hScrollChangeCbk(Widget widget, XtPointer ptr,
204 static void hScrollDragCbk(Widget widget, XtPointer ptr,
206 static void vScrollChangeCbk(Widget widget, XtPointer ptr,
208 static void vScrollDragCbk(Widget widget, XtPointer ptr,
210 static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData);
211 static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData);
212 static void outputDevRedrawCbk(void *data);
213 static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
214 void keyPress(char *s, KeySym key, Guint modifiers);
215 void redrawRectangle(int x, int y, int w, int h);
216 void updateScrollBars();
217 void setCursor(Cursor cursor);
218 GBool doDialog(int type, GBool hasCancel,
219 char *title, GString *msg);
220 static void dialogOkCbk(Widget widget, XtPointer ptr,
222 static void dialogCancelCbk(Widget widget, XtPointer ptr,
232 Widget shell; // top-level shell containing the widget
233 Widget parentWidget; // parent widget (not created by XPDFCore)
237 Widget drawAreaFrame;
239 Cursor busyCursor, linkCursor, selectCursor;
240 Cursor currentCursor;
241 GC drawAreaGC; // GC for blitting into drawArea
245 int drawAreaWidth, drawAreaHeight;
246 int scrollX, scrollY; // current upper-left corner
248 int selectXMin, selectYMin, // coordinates of current selection:
249 selectXMax, selectYMax; // (xMin==xMax || yMin==yMax) means there
251 GBool dragging; // set while selection is being dragged
252 GBool lastDragLeft; // last dragged selection edge was left/right
253 GBool lastDragTop; // last dragged selection edge was top/bottom
254 static GString *currentSelection; // selected text
255 static XPDFCore *currentSelectionOwner;
260 XPDFHistory // page history queue
261 history[xpdfHistorySize];
262 int historyCur; // currently displayed page
263 int historyBLen; // number of valid entries backward from
265 int historyFLen; // number of valid entries forward from
268 PDFDoc *doc; // current PDF file
269 int page; // current page number
270 int zoom; // current zoom level
271 double dpi; // current zoom level, in DPI
272 int rotate; // current page rotation
273 time_t modTime; // last modification time of PDF file
275 LinkAction *linkAction; // mouse cursor is over this link
278 XPDFUpdateCbk updateCbk;
280 XPDFActionCbk actionCbk;
282 XPDFKeyPressCbk keyPressCbk;
283 void *keyPressCbkData;
284 XPDFMouseCbk mouseCbk;
286 XPDFReqPasswordCbk reqPasswordCbk;
287 void *reqPasswordCbkData;
289 GBool hyperlinksEnabled;
292 XPixmapOutputDev *out;