Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / xpdf / Link.h
blob9f044204966cb58bbe8058630cad460443d435e8
1 //========================================================================
2 //
3 // Link.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef LINK_H
10 #define LINK_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "Object.h"
20 class GString;
21 class Array;
22 class Dict;
24 //------------------------------------------------------------------------
25 // LinkAction
26 //------------------------------------------------------------------------
28 enum LinkActionKind {
29 actionGoTo, // go to destination
30 actionGoToR, // go to destination in new file
31 actionLaunch, // launch app (or open document)
32 actionURI, // URI
33 actionNamed, // named action
34 actionMovie, // movie action
35 actionUnknown // anything else
38 class LinkAction {
39 public:
41 // Destructor.
42 virtual ~LinkAction() {}
44 // Was the LinkAction created successfully?
45 virtual GBool isOk() = 0;
47 // Check link action type.
48 virtual LinkActionKind getKind() = 0;
50 // Parse a destination (old-style action) name, string, or array.
51 static LinkAction *parseDest(Object *obj);
53 // Parse an action dictionary.
54 static LinkAction *parseAction(Object *obj, GString *baseURI = NULL);
56 // Extract a file name from a file specification (string or
57 // dictionary).
58 static GString *getFileSpecName(Object *fileSpecObj);
61 //------------------------------------------------------------------------
62 // LinkDest
63 //------------------------------------------------------------------------
65 enum LinkDestKind {
66 destXYZ,
67 destFit,
68 destFitH,
69 destFitV,
70 destFitR,
71 destFitB,
72 destFitBH,
73 destFitBV
76 class LinkDest {
77 public:
79 // Build a LinkDest from the array.
80 LinkDest(Array *a);
82 // Copy a LinkDest.
83 LinkDest *copy() { return new LinkDest(this); }
85 // Was the LinkDest created successfully?
86 GBool isOk() { return ok; }
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; }
102 private:
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
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
117 LinkDest(LinkDest *dest);
120 //------------------------------------------------------------------------
121 // LinkGoTo
122 //------------------------------------------------------------------------
124 class LinkGoTo: public LinkAction {
125 public:
127 // Build a LinkGoTo from a destination (dictionary, name, or string).
128 LinkGoTo(Object *destObj);
130 // Destructor.
131 virtual ~LinkGoTo();
133 // Was the LinkGoTo created successfully?
134 virtual GBool isOk() { return dest || namedDest; }
136 // Accessors.
137 virtual LinkActionKind getKind() { return actionGoTo; }
138 LinkDest *getDest() { return dest; }
139 GString *getNamedDest() { return namedDest; }
141 private:
143 LinkDest *dest; // regular destination (NULL for remote
144 // link with bad destination)
145 GString *namedDest; // named destination (only one of dest and
146 // and namedDest may be non-NULL)
149 //------------------------------------------------------------------------
150 // LinkGoToR
151 //------------------------------------------------------------------------
153 class LinkGoToR: public LinkAction {
154 public:
156 // Build a LinkGoToR from a file spec (dictionary) and destination
157 // (dictionary, name, or string).
158 LinkGoToR(Object *fileSpecObj, Object *destObj);
160 // Destructor.
161 virtual ~LinkGoToR();
163 // Was the LinkGoToR created successfully?
164 virtual GBool isOk() { return fileName && (dest || namedDest); }
166 // Accessors.
167 virtual LinkActionKind getKind() { return actionGoToR; }
168 GString *getFileName() { return fileName; }
169 LinkDest *getDest() { return dest; }
170 GString *getNamedDest() { return namedDest; }
172 private:
174 GString *fileName; // file name
175 LinkDest *dest; // regular destination (NULL for remote
176 // link with bad destination)
177 GString *namedDest; // named destination (only one of dest and
178 // and namedDest may be non-NULL)
181 //------------------------------------------------------------------------
182 // LinkLaunch
183 //------------------------------------------------------------------------
185 class LinkLaunch: public LinkAction {
186 public:
188 // Build a LinkLaunch from an action dictionary.
189 LinkLaunch(Object *actionObj);
191 // Destructor.
192 virtual ~LinkLaunch();
194 // Was the LinkLaunch created successfully?
195 virtual GBool isOk() { return fileName != NULL; }
197 // Accessors.
198 virtual LinkActionKind getKind() { return actionLaunch; }
199 GString *getFileName() { return fileName; }
200 GString *getParams() { return params; }
202 private:
204 GString *fileName; // file name
205 GString *params; // parameters
208 //------------------------------------------------------------------------
209 // LinkURI
210 //------------------------------------------------------------------------
212 class LinkURI: public LinkAction {
213 public:
215 // Build a LinkURI given the URI (string) and base URI.
216 LinkURI(Object *uriObj, GString *baseURI);
218 // Destructor.
219 virtual ~LinkURI();
221 // Was the LinkURI created successfully?
222 virtual GBool isOk() { return uri != NULL; }
224 // Accessors.
225 virtual LinkActionKind getKind() { return actionURI; }
226 GString *getURI() { return uri; }
228 private:
230 GString *uri; // the URI
233 //------------------------------------------------------------------------
234 // LinkNamed
235 //------------------------------------------------------------------------
237 class LinkNamed: public LinkAction {
238 public:
240 // Build a LinkNamed given the action name.
241 LinkNamed(Object *nameObj);
243 virtual ~LinkNamed();
245 virtual GBool isOk() { return name != NULL; }
247 virtual LinkActionKind getKind() { return actionNamed; }
248 GString *getName() { return name; }
250 private:
252 GString *name;
255 //------------------------------------------------------------------------
256 // LinkMovie
257 //------------------------------------------------------------------------
259 class LinkMovie: public LinkAction {
260 public:
262 LinkMovie(Object *annotObj, Object *titleObj);
264 virtual ~LinkMovie();
266 virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; }
268 virtual LinkActionKind getKind() { return actionMovie; }
269 GBool hasAnnotRef() { return annotRef.num >= 0; }
270 Ref *getAnnotRef() { return &annotRef; }
271 GString *getTitle() { return title; }
273 private:
275 Ref annotRef;
276 GString *title;
279 //------------------------------------------------------------------------
280 // LinkUnknown
281 //------------------------------------------------------------------------
283 class LinkUnknown: public LinkAction {
284 public:
286 // Build a LinkUnknown with the specified action type.
287 LinkUnknown(char *actionA);
289 // Destructor.
290 virtual ~LinkUnknown();
292 // Was the LinkUnknown create successfully?
293 virtual GBool isOk() { return action != NULL; }
295 // Accessors.
296 virtual LinkActionKind getKind() { return actionUnknown; }
297 GString *getAction() { return action; }
299 private:
301 GString *action; // action subtype
304 //------------------------------------------------------------------------
305 // LinkBorderStyle
306 //------------------------------------------------------------------------
308 enum LinkBorderType {
309 linkBorderSolid,
310 linkBorderDashed,
311 linkBorderEmbossed,
312 linkBorderEngraved,
313 linkBorderUnderlined
316 class LinkBorderStyle {
317 public:
319 LinkBorderStyle(LinkBorderType typeA, double widthA,
320 double *dashA, int dashLengthA,
321 double rA, double gA, double bA);
322 ~LinkBorderStyle();
324 LinkBorderType getType() { return type; }
325 double getWidth() { return width; }
326 void getDash(double **dashA, int *dashLengthA)
327 { *dashA = dash; *dashLengthA = dashLength; }
328 void getColor(double *rA, double *gA, double *bA)
329 { *rA = r; *gA = g; *bA = b; }
331 private:
333 LinkBorderType type;
334 double width;
335 double *dash;
336 int dashLength;
337 double r, g, b;
340 //------------------------------------------------------------------------
341 // Link
342 //------------------------------------------------------------------------
344 class Link {
345 public:
347 // Construct a link, given its dictionary.
348 Link(Dict *dict, GString *baseURI);
350 // Destructor.
351 ~Link();
353 // Was the link created successfully?
354 GBool isOk() { return ok; }
356 // Check if point is inside the link rectangle.
357 GBool inRect(double x, double y)
358 { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
360 // Get action.
361 LinkAction *getAction() { return action; }
363 // Get the link rectangle.
364 void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
365 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
367 // Get the border style info.
368 LinkBorderStyle *getBorderStyle() { return borderStyle; }
370 private:
372 double x1, y1; // lower left corner
373 double x2, y2; // upper right corner
374 LinkBorderStyle *borderStyle; // border style
375 LinkAction *action; // action
376 GBool ok; // is link valid?
379 //------------------------------------------------------------------------
380 // Links
381 //------------------------------------------------------------------------
383 class Links {
384 public:
386 // Extract links from array of annotations.
387 Links(Object *annots, GString *baseURI);
389 // Destructor.
390 ~Links();
392 // Iterate through list of links.
393 int getNumLinks() { return numLinks; }
394 Link *getLink(int i) { return links[i]; }
396 // If point <x>,<y> is in a link, return the associated action;
397 // else return NULL.
398 LinkAction *find(double x, double y);
400 // Return true if <x>,<y> is in a link.
401 GBool onLink(double x, double y);
403 private:
405 Link **links;
406 int numLinks;
409 #endif