filters

Link.h

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