home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / Link.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  8.8 KB  |  345 lines

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