1 //======================================================================== 2 // 3 // XPDFCore.h 4 // 5 // Copyright 2002-2003 Glyph & Cog, LLC 6 // 7 //======================================================================== 8 9 #ifndef XPDFCORE_H 10 #define XPDFCORE_H 11 12 #include <aconf.h> 13 14 #ifdef USE_GCC_PRAGMAS 15 #pragma interface 16 #endif 17 18 #define Object XtObject 19 #include <Xm/XmAll.h> 20 #undef Object 21 #include "gtypes.h" 22 #include "gfile.h" // for time_t 23 #include "SplashTypes.h" 24 #include "PDFCore.h" 25 26 class GString; 27 class BaseStream; 28 class PDFDoc; 29 class LinkAction; 30 31 //------------------------------------------------------------------------ 32 33 #define xMaxRGBCube 6 // max size of RGB color cube 34 35 //------------------------------------------------------------------------ 36 // callbacks 37 //------------------------------------------------------------------------ 38 39 typedef void (*XPDFUpdateCbk)(void *data, GString *fileName, 40 int pageNum, int numPages, 41 const char *linkLabel); 42 43 typedef void (*XPDFActionCbk)(void *data, char *action); 44 45 typedef void (*XPDFKeyPressCbk)(void *data, KeySym key, Guint modifiers, 46 XEvent *event); 47 48 typedef void (*XPDFMouseCbk)(void *data, XEvent *event); 49 50 //------------------------------------------------------------------------ 51 // XPDFCore 52 //------------------------------------------------------------------------ 53 54 class XPDFCore: public PDFCore { 55 public: 56 57 // Create viewer core inside <parentWidgetA>. 58 XPDFCore(Widget shellA, Widget parentWidgetA, 59 SplashColorPtr paperColorA, Gulong paperPixelA, 60 Gulong mattePixelA, GBool fullScreenA, GBool reverseVideoA, 61 GBool installCmap, int rgbCubeSizeA); 62 63 ~XPDFCore(); 64 65 //----- loadFile / displayPage / displayDest 66 67 // Load a new file. Returns pdfOk or error code. 68 virtual int loadFile(GString *fileName, GString *ownerPassword = NULL, 69 GString *userPassword = NULL); 70 71 // Load a new file, via a Stream instead of a file name. Returns 72 // pdfOk or error code. 73 virtual int loadFile(BaseStream *stream, GString *ownerPassword = NULL, 74 GString *userPassword = NULL); 75 76 // Load an already-created PDFDoc object. 77 virtual void loadDoc(PDFDoc *docA); 78 79 // Resize the window to fit page <pg> of the current document. 80 void resizeToPage(int pg); 81 82 // Update the display, given the specified parameters. 83 virtual void update(int topPageA, int scrollXA, int scrollYA, 84 double zoomA, int rotateA, GBool force, 85 GBool addToHist, GBool adjustScrollX); 86 87 //----- page/position changes 88 89 virtual GBool gotoNextPage(int inc, GBool top); 90 virtual GBool gotoPrevPage(int dec, GBool top, GBool bottom); 91 virtual GBool goForward(); 92 virtual GBool goBackward(); 93 void startPan(int wx, int wy); 94 void endPan(int wx, int wy); 95 96 //----- selection 97 98 void startSelection(int wx, int wy); 99 void endSelection(int wx, int wy); 100 void copySelection(); 101 102 //----- hyperlinks 103 104 void doAction(LinkAction *action); getLinkAction()105 LinkAction *getLinkAction() { return linkAction; } 106 GString *mungeURL(GString *url); 107 108 //----- find 109 110 virtual GBool find(char *s, GBool caseSensitive, GBool next, 111 GBool backward, GBool wholeWord, GBool onePageOnly); 112 virtual GBool findU(Unicode *u, int len, GBool caseSensitive, 113 GBool next, GBool backward, 114 GBool wholeWord, GBool onePageOnly); 115 116 //----- simple modal dialogs 117 118 GBool doQuestionDialog(const char *title, GString *msg); 119 void doInfoDialog(const char *title, GString *msg); 120 void doErrorDialog(const char *title, GString *msg); 121 122 //----- password dialog 123 124 virtual GString *getPassword(); 125 126 //----- misc access 127 getWidget()128 Widget getWidget() { return scrolledWin; } getDrawAreaWidget()129 Widget getDrawAreaWidget() { return drawArea; } 130 virtual void setBusyCursor(GBool busy); getBusyCursor()131 Cursor getBusyCursor() { return busyCursor; } 132 void takeFocus(); enableHyperlinks(GBool on)133 void enableHyperlinks(GBool on) { hyperlinksEnabled = on; } getHyperlinksEnabled()134 GBool getHyperlinksEnabled() { return hyperlinksEnabled; } enableSelect(GBool on)135 void enableSelect(GBool on) { selectEnabled = on; } setUpdateCbk(XPDFUpdateCbk cbk,void * data)136 void setUpdateCbk(XPDFUpdateCbk cbk, void *data) 137 { updateCbk = cbk; updateCbkData = data; } setActionCbk(XPDFActionCbk cbk,void * data)138 void setActionCbk(XPDFActionCbk cbk, void *data) 139 { actionCbk = cbk; actionCbkData = data; } setKeyPressCbk(XPDFKeyPressCbk cbk,void * data)140 void setKeyPressCbk(XPDFKeyPressCbk cbk, void *data) 141 { keyPressCbk = cbk; keyPressCbkData = data; } setMouseCbk(XPDFMouseCbk cbk,void * data)142 void setMouseCbk(XPDFMouseCbk cbk, void *data) 143 { mouseCbk = cbk; mouseCbkData = data; } getFullScreen()144 GBool getFullScreen() { return fullScreen; } 145 146 private: 147 148 virtual GBool checkForNewFile(); 149 150 //----- hyperlinks 151 void runCommand(GString *cmdFmt, GString *arg); 152 153 //----- selection 154 static Boolean convertSelectionCbk(Widget widget, Atom *selection, 155 Atom *target, Atom *type, 156 XtPointer *value, unsigned long *length, 157 int *format); 158 159 //----- GUI code 160 void setupX(GBool installCmap, int rgbCubeSizeA); 161 void initWindow(); 162 static void hScrollChangeCbk(Widget widget, XtPointer ptr, 163 XtPointer callData); 164 static void hScrollDragCbk(Widget widget, XtPointer ptr, 165 XtPointer callData); 166 static void vScrollChangeCbk(Widget widget, XtPointer ptr, 167 XtPointer callData); 168 static void vScrollDragCbk(Widget widget, XtPointer ptr, 169 XtPointer callData); 170 static void resizeCbk(Widget widget, XtPointer ptr, XtPointer callData); 171 static void redrawCbk(Widget widget, XtPointer ptr, XtPointer callData); 172 static void inputCbk(Widget widget, XtPointer ptr, XtPointer callData); 173 virtual PDFCoreTile *newTile(int xDestA, int yDestA); 174 virtual void updateTileData(PDFCoreTile *tileA, int xSrc, int ySrc, 175 int width, int height, GBool composited); 176 virtual void redrawRect(PDFCoreTile *tileA, int xSrc, int ySrc, 177 int xDest, int yDest, int width, int height, 178 GBool composited); 179 virtual void updateScrollbars(); 180 void setCursor(Cursor cursor); 181 GBool doDialog(int type, GBool hasCancel, 182 const char *title, GString *msg); 183 static void dialogOkCbk(Widget widget, XtPointer ptr, 184 XtPointer callData); 185 static void dialogCancelCbk(Widget widget, XtPointer ptr, 186 XtPointer callData); 187 void initPasswordDialog(); 188 static void passwordTextVerifyCbk(Widget widget, XtPointer ptr, 189 XtPointer callData); 190 static void passwordOkCbk(Widget widget, XtPointer ptr, 191 XtPointer callData); 192 static void passwordCancelCbk(Widget widget, XtPointer ptr, 193 XtPointer callData); 194 195 Gulong paperPixel; 196 Gulong mattePixel; 197 //~unimp: move fullScreen into PDFCore? 198 GBool fullScreen; 199 200 Display *display; 201 int screenNum; 202 Visual *visual; 203 Colormap colormap; 204 Guint depth; // visual depth 205 GBool trueColor; // set if using a TrueColor visual 206 int rDiv, gDiv, bDiv; // RGB right shifts (for TrueColor) 207 int rShift, gShift, bShift; // RGB left shifts (for TrueColor) 208 int rgbCubeSize; // size of color cube (for non-TrueColor) 209 Gulong // color cube (for non-TrueColor) 210 colors[xMaxRGBCube * xMaxRGBCube * xMaxRGBCube]; 211 212 Widget shell; // top-level shell containing the widget 213 Widget parentWidget; // parent widget (not created by XPDFCore) 214 Widget scrolledWin; 215 Widget hScrollBar; 216 Widget vScrollBar; 217 Widget drawAreaFrame; 218 Widget drawArea; 219 Cursor busyCursor, linkCursor, selectCursor; 220 Cursor currentCursor; 221 GC drawAreaGC; // GC for blitting into drawArea 222 223 static GString *currentSelection; // selected text 224 static XPDFCore *currentSelectionOwner; 225 static Atom targetsAtom; 226 227 GBool panning; 228 int panMX, panMY; 229 230 time_t modTime; // last modification time of PDF file 231 232 LinkAction *linkAction; // mouse cursor is over this link 233 234 XPDFUpdateCbk updateCbk; 235 void *updateCbkData; 236 XPDFActionCbk actionCbk; 237 void *actionCbkData; 238 XPDFKeyPressCbk keyPressCbk; 239 void *keyPressCbkData; 240 XPDFMouseCbk mouseCbk; 241 void *mouseCbkData; 242 243 GBool hyperlinksEnabled; 244 GBool selectEnabled; 245 246 int dialogDone; 247 248 Widget passwordDialog; 249 Widget passwordText; 250 GString *password; 251 }; 252 253 #endif 254