home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / xpdf / link.h < prev    next >
C/C++ Source or Header  |  1998-11-27  |  8KB  |  314 lines

  1. //========================================================================
  2. //
  3. // Link.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef LINK_H
  10. #define LINK_H
  11.  
  12. #ifdef __GNUC__
  13. #pragma interface
  14. #endif
  15.  
  16. #include "Object.h"
  17.  
  18. class GString;
  19. class Array;
  20. class Dict;
  21.  
  22. //------------------------------------------------------------------------
  23. // LinkAction
  24. //------------------------------------------------------------------------
  25.  
  26. enum LinkActionKind {
  27.   actionGoTo,            // go to destination
  28.   actionGoToR,            // go to destination in new file
  29.   actionLaunch,            // launch app (or open document)
  30.   actionURI,            // URI
  31.   actionUnknown            // anything else
  32. };
  33.  
  34. class LinkAction {
  35. public:
  36.  
  37.   // Destructor.
  38.   virtual ~LinkAction() {}
  39.  
  40.   // Was the LinkAction created successfully?
  41.   virtual GBool isOk() = 0;
  42.  
  43.   // Check link action type.
  44.   virtual LinkActionKind getKind() = 0;
  45. };
  46.  
  47. //------------------------------------------------------------------------
  48. // LinkDest
  49. //------------------------------------------------------------------------
  50.  
  51. enum LinkDestKind {
  52.   destXYZ,
  53.   destFit,
  54.   destFitH,
  55.   destFitV,
  56.   destFitR,
  57.   destFitB,
  58.   destFitBH,
  59.   destFitBV
  60. };
  61.  
  62. class LinkDest {
  63. public:
  64.  
  65.   // Build a LinkDest from the array.  If <pageIsRef> is true, the
  66.   // page is specified by an object reference; otherwise the page is
  67.   // specified by a (zero-relative) page number.
  68.   LinkDest(Array *a, GBool pageIsRef1);
  69.  
  70.   // Copy a LinkDest.
  71.   LinkDest *copy() { return new LinkDest(this); }
  72.  
  73.   // Was the LinkDest created successfully?
  74.   GBool isOk() { return ok; }
  75.  
  76.   // Accessors.
  77.   LinkDestKind getKind() { return kind; }
  78.   GBool isPageRef() { return pageIsRef; }
  79.   int getPageNum() { return pageNum; }
  80.   Ref getPageRef() { return pageRef; }
  81.   double getLeft() { return left; }
  82.   double getBottom() { return bottom; }
  83.   double getRight() { return right; }
  84.   double getTop() { return top; }
  85.   double getZoom() { return zoom; }
  86.   GBool getChangeLeft() { return changeLeft; }
  87.   GBool getChangeTop() { return changeTop; }
  88.   GBool getChangeZoom() { return changeZoom; }
  89.  
  90. private:
  91.  
  92.   LinkDestKind kind;        // destination type
  93.   GBool pageIsRef;        // is the page a reference or number?
  94.   union {
  95.     Ref pageRef;        // reference to page
  96.     int pageNum;        // one-relative page number
  97.   };
  98.   double left, bottom;        // position
  99.   double right, top;
  100.   double zoom;            // zoom factor
  101.   GBool changeLeft, changeTop;    // for destXYZ links, which position
  102.   GBool changeZoom;        //   components to change
  103.   GBool ok;            // set if created successfully
  104.  
  105.   LinkDest(LinkDest *dest);
  106. };
  107.  
  108. //------------------------------------------------------------------------
  109. // LinkGoTo
  110. //------------------------------------------------------------------------
  111.  
  112. class LinkGoTo: public LinkAction {
  113. public:
  114.  
  115.   // Build a LinkGoTo from a destination (dictionary, name, or string).
  116.   LinkGoTo(Object *destObj);
  117.  
  118.   // Destructor.
  119.   virtual ~LinkGoTo();
  120.  
  121.   // Was the LinkGoTo created successfully?
  122.   virtual GBool isOk() { return dest || namedDest; }
  123.  
  124.   // Accessors.
  125.   virtual LinkActionKind getKind() { return actionGoTo; }
  126.   LinkDest *getDest() { return dest; }
  127.   GString *getNamedDest() { return namedDest; }
  128.  
  129. private:
  130.  
  131.   LinkDest *dest;        // regular destination (NULL for remote
  132.                 //   link with bad destination)
  133.   GString *namedDest;        // named destination (only one of dest and
  134.                 //   and namedDest may be non-NULL)
  135. };
  136.  
  137. //------------------------------------------------------------------------
  138. // LinkGoToR
  139. //------------------------------------------------------------------------
  140.  
  141. class LinkGoToR: public LinkAction {
  142. public:
  143.  
  144.   // Build a LinkGoToR from a file spec (dictionary) and destination
  145.   // (dictionary, name, or string).
  146.   LinkGoToR(Object *fileSpecObj, Object *destObj);
  147.  
  148.   // Destructor.
  149.   virtual ~LinkGoToR();
  150.  
  151.   // Was the LinkGoToR created successfully?
  152.   virtual GBool isOk() { return fileName && (dest || namedDest); }
  153.  
  154.   // Accessors.
  155.   virtual LinkActionKind getKind() { return actionGoToR; }
  156.   GString *getFileName() { return fileName; }
  157.   LinkDest *getDest() { return dest; }
  158.   GString *getNamedDest() { return namedDest; }
  159.  
  160. private:
  161.  
  162.   GString *fileName;        // file name
  163.   LinkDest *dest;        // regular destination (NULL for remote
  164.                 //   link with bad destination)
  165.   GString *namedDest;        // named destination (only one of dest and
  166.                 //   and namedDest may be non-NULL)
  167. };
  168.  
  169. //------------------------------------------------------------------------
  170. // LinkLaunch
  171. //------------------------------------------------------------------------
  172.  
  173. class LinkLaunch: public LinkAction {
  174. public:
  175.  
  176.   // Build a LinkLaunch from an action dictionary.
  177.   LinkLaunch(Object *actionObj);
  178.  
  179.   // Destructor.
  180.   virtual ~LinkLaunch();
  181.  
  182.   // Was the LinkLaunch created successfully?
  183.   virtual GBool isOk() { return fileName != NULL; }
  184.  
  185.   // Accessors.
  186.   virtual LinkActionKind getKind() { return actionLaunch; }
  187.   GString *getFileName() { return fileName; }
  188.   GString *getParams() { return params; }
  189.  
  190. private:
  191.  
  192.   GString *fileName;        // file name
  193.   GString *params;        // parameters
  194. };
  195.  
  196. //------------------------------------------------------------------------
  197. // LinkURI
  198. //------------------------------------------------------------------------
  199.  
  200. class LinkURI: public LinkAction {
  201. public:
  202.  
  203.   // Build a LinkURI given the URI (string).
  204.   LinkURI(Object *uriObj);
  205.  
  206.   // Destructor.
  207.   virtual ~LinkURI();
  208.  
  209.   // Was the LinkURI created successfully?
  210.   virtual GBool isOk() { return uri != NULL; }
  211.  
  212.   // Accessors.
  213.   virtual LinkActionKind getKind() { return actionURI; }
  214.   GString *getURI() { return uri; }
  215.  
  216. private:
  217.  
  218.   GString *uri;            // the URI
  219. };
  220.  
  221. //------------------------------------------------------------------------
  222. // LinkUnknown
  223. //------------------------------------------------------------------------
  224.  
  225. class LinkUnknown: public LinkAction {
  226. public:
  227.  
  228.   // Build a LinkUnknown with the specified action type.
  229.   LinkUnknown(char *action1);
  230.  
  231.   // Destructor.
  232.   virtual ~LinkUnknown();
  233.  
  234.   // Was the LinkUnknown create successfully?
  235.   virtual GBool isOk() { return action != NULL; }
  236.  
  237.   // Accessors.
  238.   virtual LinkActionKind getKind() { return actionUnknown; }
  239.   GString *getAction() { return action; }
  240.  
  241. private:
  242.  
  243.   GString *action;        // action subtype
  244. };
  245.  
  246. //------------------------------------------------------------------------
  247. // Link
  248. //------------------------------------------------------------------------
  249.  
  250. class Link {
  251. public:
  252.  
  253.   // Construct a link, given its dictionary.
  254.   Link(Dict *dict);
  255.  
  256.   // Destructor.
  257.   ~Link();
  258.  
  259.   // Was the link created successfully?
  260.   GBool isOk() { return ok; }
  261.  
  262.   // Check if point is inside the link rectangle.
  263.   GBool inRect(double x, double y)
  264.     { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
  265.  
  266.   // Get action.
  267.   LinkAction *getAction() { return action; }
  268.  
  269.   // Get border corners and width.
  270.   void getBorder(double *xa1, double *ya1, double *xa2, double *ya2,
  271.          double *wa)
  272.     { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
  273.  
  274. private:
  275.  
  276.   double x1, y1;        // lower left corner
  277.   double x2, y2;        // upper right corner
  278.   double borderW;        // border width
  279.   LinkAction *action;        // action
  280.   GBool ok;            // is link valid?
  281. };
  282.  
  283. //------------------------------------------------------------------------
  284. // Links
  285. //------------------------------------------------------------------------
  286.  
  287. class Links {
  288. public:
  289.  
  290.   // Extract links from array of annotations.
  291.   Links(Object *annots);
  292.  
  293.   // Destructor.
  294.   ~Links();
  295.  
  296.   // Iterate through list of links.
  297.   int getNumLinks() { return numLinks; }
  298.   Link *getLink(int i) { return links[i]; }
  299.  
  300.   // If point <x>,<y> is in a link, return the associated action;
  301.   // else return NULL.
  302.   LinkAction *find(double x, double y);
  303.  
  304.   // Return true if <x>,<y> is in a link.
  305.   GBool onLink(double x, double y);
  306.  
  307. private:
  308.  
  309.   Link **links;
  310.   int numLinks;
  311. };
  312.  
  313. #endif
  314.