filters

XPDFCore.h

00001 //========================================================================
00002 //
00003 // XPDFCore.h
00004 //
00005 // Copyright 2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef XPDFCORE_H
00010 #define XPDFCORE_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #define Object XtObject
00019 #include <Xm/XmAll.h>
00020 #undef Object
00021 #include <aconf.h>
00022 #include "gtypes.h"
00023 #include "gfile.h" // for time_t
00024 
00025 class GString;
00026 class GList;
00027 class PDFDoc;
00028 class LinkAction;
00029 class LinkDest;
00030 class XPixmapOutputDev;
00031 
00032 //------------------------------------------------------------------------
00033 // zoom factor
00034 //------------------------------------------------------------------------
00035 
00036 #define minZoom    -5
00037 #define maxZoom     5
00038 #define zoomPage  100
00039 #define zoomWidth 101
00040 #define defZoom     1
00041 
00042 //------------------------------------------------------------------------
00043 // XPDFHistory
00044 //------------------------------------------------------------------------
00045 
00046 struct XPDFHistory {
00047   GString *fileName;
00048   int page;
00049 };
00050 
00051 #define xpdfHistorySize 50
00052 
00053 //------------------------------------------------------------------------
00054 // XPDFRegion
00055 //------------------------------------------------------------------------
00056 
00057 struct XPDFRegion {
00058   int page;
00059   double xMin, yMin, xMax, yMax;
00060   Gulong color;
00061   Gulong selectColor;
00062 };
00063 
00064 //------------------------------------------------------------------------
00065 // callbacks
00066 //------------------------------------------------------------------------
00067 
00068 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName,
00069                 int pageNum, int numPages, char *linkLabel);
00070 
00071 typedef void (*XPDFActionCbk)(void *data, char *action);
00072 
00073 typedef void (*XPDFKeyPressCbk)(void *data, char *s, KeySym key,
00074                 Guint modifiers);
00075 
00076 typedef void (*XPDFMouseCbk)(void *data, XEvent *event);
00077 
00078 typedef GString *(*XPDFReqPasswordCbk)(void *data, GBool again);
00079 
00080 //------------------------------------------------------------------------
00081 // XPDFCore
00082 //------------------------------------------------------------------------
00083 
00084 class XPDFCore {
00085 public:
00086 
00087   // Create viewer core inside <parentWidgetA>.
00088   XPDFCore(Widget shellA, Widget parentWidgetA,
00089        Gulong paperColorA, GBool fullScreenA, GBool reverseVideo,
00090        GBool installCmap, int rgbCubeSize);
00091 
00092   ~XPDFCore();
00093 
00094   //----- loadFile / displayPage / displayDest
00095 
00096   // Load a new file.  Returns pdfOk or error code.
00097   int loadFile(GString *fileName, GString *ownerPassword = NULL,
00098            GString *userPassword = NULL);
00099 
00100   // Resize the window to fit page <pg> of the current document.
00101   void resizeToPage(int pg);
00102 
00103   // Clear out the current document, if any.
00104   void clear();
00105 
00106   // Display (or redisplay) the specified page.  If <scrollToTop> is
00107   // set, the window is vertically scrolled to the top; otherwise, no
00108   // scrolling is done.  If <addToHist> is set, this page change is
00109   // added to the history list.
00110   void displayPage(int pageA, int zoomA, int rotateA,
00111            GBool scrollToTop, GBool addToHist);
00112 
00113   // Display a link destination.
00114   void displayDest(LinkDest *dest, int zoomA, int rotateA,
00115            GBool addToHist);
00116 
00117   //----- page/position changes
00118 
00119   void gotoNextPage(int inc, GBool top);
00120   void gotoPrevPage(int dec, GBool top, GBool bottom);
00121   void goForward();
00122   void goBackward();
00123   void scrollLeft(int nCols = 1);
00124   void scrollRight(int nCols = 1);
00125   void scrollUp(int nLines = 1);
00126   void scrollDown(int nLines = 1);
00127   void scrollPageUp();
00128   void scrollPageDown();
00129   void scrollTo(int x, int y);
00130 
00131   //----- selection
00132 
00133   void setSelection(int newXMin, int newYMin, int newXMax, int newYMax);
00134   void moveSelection(int mx, int my);
00135   void copySelection();
00136   GBool getSelection(int *xMin, int *yMin, int *xMax, int *yMax);
00137   GString *extractText(int xMin, int yMin, int xMax, int yMax);
00138   GString *extractText(int pageNum, int xMin, int yMin, int xMax, int yMax);
00139 
00140   //----- hyperlinks
00141 
00142   void doAction(LinkAction *action);
00143 
00144 
00145   //----- find
00146 
00147   void find(char *s);
00148 
00149   //----- simple modal dialogs
00150 
00151   GBool doQuestionDialog(char *title, GString *msg);
00152   void doInfoDialog(char *title, GString *msg);
00153   void doErrorDialog(char *title, GString *msg);
00154 
00155   //----- misc access
00156 
00157   Widget getWidget() { return scrolledWin; }
00158   Widget getDrawAreaWidget() { return drawArea; }
00159   PDFDoc *getDoc() { return doc; }
00160   XPixmapOutputDev *getOutputDev() { return out; }
00161   int getPageNum() { return page; }
00162   int getZoom() { return zoom; }
00163   double getZoomDPI() { return dpi; }
00164   int getRotate() { return rotate; }
00165   GBool canGoBack() { return historyBLen > 1; }
00166   GBool canGoForward() { return historyFLen > 0; }
00167   int getScrollX() { return scrollX; }
00168   int getScrollY() { return scrollY; }
00169   int getDrawAreaWidth() { return drawAreaWidth; }
00170   int getDrawAreaHeight() { return drawAreaHeight; }
00171   void setBusyCursor(GBool busy);
00172   void takeFocus();
00173   void enableHyperlinks(GBool on) { hyperlinksEnabled = on; }
00174   void enableSelect(GBool on) { selectEnabled = on; }
00175   void setUpdateCbk(XPDFUpdateCbk cbk, void *data)
00176     { updateCbk = cbk; updateCbkData = data; }
00177   void setActionCbk(XPDFActionCbk cbk, void *data)
00178     { actionCbk = cbk; actionCbkData = data; }
00179   void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data)
00180     { keyPressCbk = cbk; keyPressCbkData = data; }
00181   void setMouseCbk(XPDFMouseCbk cbk, void *data)
00182     { mouseCbk = cbk; mouseCbkData = data; }
00183   void setReqPasswordCbk(XPDFReqPasswordCbk cbk, void *data)
00184     { reqPasswordCbk = cbk; reqPasswordCbkData = data; }
00185 
00186 private:
00187 
00188   //----- hyperlinks
00189   void doLink(int mx, int my);
00190   void runCommand(GString *cmdFmt, GString *arg);
00191 
00192   //----- selection
00193   static Boolean convertSelectionCbk(Widget widget, Atom *selection,
00194                      Atom *target, Atom *type,
00195                      XtPointer *value, unsigned long *length,
00196                      int *format);
00197 
00198 
00199   //----- GUI code
00200   void initWindow();
00201   static void hScrollChangeCbk(Widget widget, XtPointer ptr,
00202                    XtPointer callData);
00203   static void hScrollDragCbk(Widget widget, XtPointer ptr,
00204                  XtPointer callData);
00205   static void vScrollChangeCbk(Widget widget, XtPointer ptr,
00206                    XtPointer callData);
00207   static void vScrollDragCbk(Widget widget, XtPointer ptr,
00208                  XtPointer callData);
00209   static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData);
00210   static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData);
00211   static void outputDevRedrawCbk(void *data);
00212   static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData);
00213   void keyPress(char *s, KeySym key, Guint modifiers);
00214   void redrawRectangle(int x, int y, int w, int h);
00215   void updateScrollBars();
00216   void setCursor(Cursor cursor);
00217   GBool doDialog(int type, GBool hasCancel,
00218          char *title, GString *msg);
00219   static void dialogOkCbk(Widget widget, XtPointer ptr,
00220               XtPointer callData);
00221   static void dialogCancelCbk(Widget widget, XtPointer ptr,
00222                   XtPointer callData);
00223 
00224   Gulong paperColor;
00225   GBool fullScreen;
00226 
00227   Display *display;
00228   int screenNum;
00229   Visual *visual;
00230   Colormap colormap;
00231   Widget shell;         // top-level shell containing the widget
00232   Widget parentWidget;      // parent widget (not created by XPDFCore)
00233   Widget scrolledWin;
00234   Widget hScrollBar;
00235   Widget vScrollBar;
00236   Widget drawAreaFrame;
00237   Widget drawArea;
00238   Cursor busyCursor, linkCursor, selectCursor;
00239   Cursor currentCursor;
00240   GC drawAreaGC;        // GC for blitting into drawArea
00241   GC selectGC;
00242   GC highlightGC;
00243 
00244   int drawAreaWidth, drawAreaHeight;
00245   int scrollX, scrollY;     // current upper-left corner
00246 
00247   int selectXMin, selectYMin,   // coordinates of current selection:
00248       selectXMax, selectYMax;   //   (xMin==xMax || yMin==yMax) means there
00249                 //   is no selection
00250   GBool dragging;       // set while selection is being dragged
00251   GBool lastDragLeft;       // last dragged selection edge was left/right
00252   GBool lastDragTop;        // last dragged selection edge was top/bottom
00253   static GString *currentSelection;  // selected text
00254   static XPDFCore *currentSelectionOwner;
00255 
00256   GBool panning;
00257   int panMX, panMY;
00258 
00259   XPDFHistory           // page history queue
00260     history[xpdfHistorySize];
00261   int historyCur;               // currently displayed page
00262   int historyBLen;              // number of valid entries backward from
00263                                 //   current entry
00264   int historyFLen;              // number of valid entries forward from
00265                                 //   current entry
00266 
00267   PDFDoc *doc;          // current PDF file
00268   int page;         // current page number
00269   int zoom;         // current zoom level
00270   double dpi;           // current zoom level, in DPI
00271   int rotate;           // current page rotation
00272   time_t modTime;       // last modification time of PDF file
00273 
00274   LinkAction *linkAction;   // mouse cursor is over this link
00275 
00276 
00277   XPDFUpdateCbk updateCbk;
00278   void *updateCbkData;
00279   XPDFActionCbk actionCbk;
00280   void *actionCbkData;
00281   XPDFKeyPressCbk keyPressCbk;
00282   void *keyPressCbkData;
00283   XPDFMouseCbk mouseCbk;
00284   void *mouseCbkData;
00285   XPDFReqPasswordCbk reqPasswordCbk;
00286   void *reqPasswordCbkData;
00287 
00288   GBool hyperlinksEnabled;
00289   GBool selectEnabled;
00290 
00291   XPixmapOutputDev *out;
00292 
00293   int dialogDone;
00294 };
00295 
00296 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys