Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Link.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Link.h
00004 //
00005 // Copyright 1996-2002 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef LINK_H
00010 #define LINK_H
00011 
00012 #ifdef __GNUC__
00013 #pragma interface
00014 #endif
00015 
00016 #include "Object.h"
00017 
00018 class GString;
00019 class Array;
00020 class Dict;
00021 
00022 //------------------------------------------------------------------------
00023 // LinkAction
00024 //------------------------------------------------------------------------
00025 
00026 enum LinkActionKind {
00027   actionGoTo,                   // go to destination
00028   actionGoToR,                  // go to destination in new file
00029   actionLaunch,                 // launch app (or open document)
00030   actionURI,                    // URI
00031   actionNamed,                  // named action
00032   actionUnknown                 // anything else
00033 };
00034 
00035 class LinkAction {
00036 public:
00037 
00038   // Destructor.
00039   virtual ~LinkAction() {}
00040 
00041   // Was the LinkAction created successfully?
00042   virtual GBool isOk() = 0;
00043 
00044   // Check link action type.
00045   virtual LinkActionKind getKind() = 0;
00046 };
00047 
00048 //------------------------------------------------------------------------
00049 // LinkDest
00050 //------------------------------------------------------------------------
00051 
00052 enum LinkDestKind {
00053   destXYZ,
00054   destFit,
00055   destFitH,
00056   destFitV,
00057   destFitR,
00058   destFitB,
00059   destFitBH,
00060   destFitBV
00061 };
00062 
00063 class LinkDest {
00064 public:
00065 
00066   // Build a LinkDest from the array.
00067   LinkDest(Array *a);
00068 
00069   // Copy a LinkDest.
00070   LinkDest *copy() { return new LinkDest(this); }
00071 
00072   // Was the LinkDest created successfully?
00073   GBool isOk() { return ok; }
00074 
00075   // Accessors.
00076   LinkDestKind getKind() { return kind; }
00077   GBool isPageRef() { return pageIsRef; }
00078   int getPageNum() { return pageNum; }
00079   Ref getPageRef() { return pageRef; }
00080   fouble getLeft() { return left; }
00081   fouble getBottom() { return bottom; }
00082   fouble getRight() { return right; }
00083   fouble getTop() { return top; }
00084   fouble getZoom() { return zoom; }
00085   GBool getChangeLeft() { return changeLeft; }
00086   GBool getChangeTop() { return changeTop; }
00087   GBool getChangeZoom() { return changeZoom; }
00088 
00089 private:
00090 
00091   LinkDestKind kind;            // destination type
00092   GBool pageIsRef;              // is the page a reference or number?
00093   union {
00094     Ref pageRef;                // reference to page
00095     int pageNum;                // one-relative page number
00096   };
00097   fouble left, bottom;          // position
00098   fouble right, top;
00099   fouble zoom;                  // zoom factor
00100   GBool changeLeft, changeTop;  // for destXYZ links, which position
00101   GBool changeZoom;             //   components to change
00102   GBool ok;                     // set if created successfully
00103 
00104   LinkDest(LinkDest *dest);
00105 };
00106 
00107 //------------------------------------------------------------------------
00108 // LinkGoTo
00109 //------------------------------------------------------------------------
00110 
00111 class LinkGoTo: public LinkAction {
00112 public:
00113 
00114   // Build a LinkGoTo from a destination (dictionary, name, or string).
00115   LinkGoTo(Object *destObj);
00116 
00117   // Destructor.
00118   virtual ~LinkGoTo();
00119 
00120   // Was the LinkGoTo created successfully?
00121   virtual GBool isOk() { return dest || namedDest; }
00122 
00123   // Accessors.
00124   virtual LinkActionKind getKind() { return actionGoTo; }
00125   LinkDest *getDest() { return dest; }
00126   GString *getNamedDest() { return namedDest; }
00127 
00128 private:
00129 
00130   LinkDest *dest;               // regular destination (NULL for remote
00131                                 //   link with bad destination)
00132   GString *namedDest;           // named destination (only one of dest and
00133                                 //   and namedDest may be non-NULL)
00134 };
00135 
00136 //------------------------------------------------------------------------
00137 // LinkGoToR
00138 //------------------------------------------------------------------------
00139 
00140 class LinkGoToR: public LinkAction {
00141 public:
00142 
00143   // Build a LinkGoToR from a file spec (dictionary) and destination
00144   // (dictionary, name, or string).
00145   LinkGoToR(Object *fileSpecObj, Object *destObj);
00146 
00147   // Destructor.
00148   virtual ~LinkGoToR();
00149 
00150   // Was the LinkGoToR created successfully?
00151   virtual GBool isOk() { return fileName && (dest || namedDest); }
00152 
00153   // Accessors.
00154   virtual LinkActionKind getKind() { return actionGoToR; }
00155   GString *getFileName() { return fileName; }
00156   LinkDest *getDest() { return dest; }
00157   GString *getNamedDest() { return namedDest; }
00158 
00159 private:
00160 
00161   GString *fileName;            // file name
00162   LinkDest *dest;               // regular destination (NULL for remote
00163                                 //   link with bad destination)
00164   GString *namedDest;           // named destination (only one of dest and
00165                                 //   and namedDest may be non-NULL)
00166 };
00167 
00168 //------------------------------------------------------------------------
00169 // LinkLaunch
00170 //------------------------------------------------------------------------
00171 
00172 class LinkLaunch: public LinkAction {
00173 public:
00174 
00175   // Build a LinkLaunch from an action dictionary.
00176   LinkLaunch(Object *actionObj);
00177 
00178   // Destructor.
00179   virtual ~LinkLaunch();
00180 
00181   // Was the LinkLaunch created successfully?
00182   virtual GBool isOk() { return fileName != NULL; }
00183 
00184   // Accessors.
00185   virtual LinkActionKind getKind() { return actionLaunch; }
00186   GString *getFileName() { return fileName; }
00187   GString *getParams() { return params; }
00188 
00189 private:
00190 
00191   GString *fileName;            // file name
00192   GString *params;              // parameters
00193 };
00194 
00195 //------------------------------------------------------------------------
00196 // LinkURI
00197 //------------------------------------------------------------------------
00198 
00199 class LinkURI: public LinkAction {
00200 public:
00201 
00202   // Build a LinkURI given the URI (string) and base URI.
00203   LinkURI(Object *uriObj, GString *baseURI);
00204 
00205   // Destructor.
00206   virtual ~LinkURI();
00207 
00208   // Was the LinkURI created successfully?
00209   virtual GBool isOk() { return uri != NULL; }
00210 
00211   // Accessors.
00212   virtual LinkActionKind getKind() { return actionURI; }
00213   GString *getURI() { return uri; }
00214 
00215 private:
00216 
00217   GString *uri;                 // the URI
00218 };
00219 
00220 //------------------------------------------------------------------------
00221 // LinkNamed
00222 //------------------------------------------------------------------------
00223 
00224 class LinkNamed: public LinkAction {
00225 public:
00226 
00227   // Build a LinkNamed given the action name.
00228   LinkNamed(Object *nameObj);
00229 
00230   virtual ~LinkNamed();
00231 
00232   virtual GBool isOk() { return name != NULL; }
00233 
00234   virtual LinkActionKind getKind() { return actionNamed; }
00235   GString *getName() { return name; }
00236 
00237 private:
00238 
00239   GString *name;
00240 };
00241 
00242 //------------------------------------------------------------------------
00243 // LinkUnknown
00244 //------------------------------------------------------------------------
00245 
00246 class LinkUnknown: public LinkAction {
00247 public:
00248 
00249   // Build a LinkUnknown with the specified action type.
00250   LinkUnknown(char *actionA);
00251 
00252   // Destructor.
00253   virtual ~LinkUnknown();
00254 
00255   // Was the LinkUnknown create successfully?
00256   virtual GBool isOk() { return action != NULL; }
00257 
00258   // Accessors.
00259   virtual LinkActionKind getKind() { return actionUnknown; }
00260   GString *getAction() { return action; }
00261 
00262 private:
00263 
00264   GString *action;              // action subtype
00265 };
00266 
00267 //------------------------------------------------------------------------
00268 // Link
00269 //------------------------------------------------------------------------
00270 
00271 class Link {
00272 public:
00273 
00274   // Construct a link, given its dictionary.
00275   Link(Dict *dict, GString *baseURI);
00276 
00277   // Destructor.
00278   ~Link();
00279 
00280   // Was the link created successfully?
00281   GBool isOk() { return ok; }
00282 
00283   // Check if point is inside the link rectangle.
00284   GBool inRect(fouble x, fouble y)
00285     { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
00286 
00287   // Get action.
00288   LinkAction *getAction() { return action; }
00289 
00290   // Get border corners and width.
00291   void getBorder(fouble *xa1, fouble *ya1, fouble *xa2, fouble *ya2,
00292                  fouble *wa)
00293     { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; }
00294 
00295 private:
00296 
00297   fouble x1, y1;                // lower left corner
00298   fouble x2, y2;                // upper right corner
00299   fouble borderW;               // border width
00300   LinkAction *action;           // action
00301   GBool ok;                     // is link valid?
00302 };
00303 
00304 //------------------------------------------------------------------------
00305 // Links
00306 //------------------------------------------------------------------------
00307 
00308 class Links {
00309 public:
00310 
00311   // Extract links from array of annotations.
00312   Links(Object *annots, GString *baseURI);
00313 
00314   // Destructor.
00315   ~Links();
00316 
00317   // Iterate through list of links.
00318   int getNumLinks() { return numLinks; }
00319   Link *getLink(int i) { return links[i]; }
00320 
00321   // If point <x>,<y> is in a link, return the associated action;
00322   // else return NULL.
00323   LinkAction *find(fouble x, fouble y);
00324 
00325   // Return true if <x>,<y> is in a link.
00326   GBool onLink(fouble x, fouble y);
00327 
00328 private:
00329 
00330   Link **links;
00331   int numLinks;
00332 };
00333 
00334 #endif

Generated on Sat Nov 5 16:18:15 2005 for OPIE by  doxygen 1.4.2