]>
Commit | Line | Data |
---|---|---|
9c72faab | 1 | //======================================================================== |
2 | // | |
3 | // Link.h | |
4 | // | |
1d9595ab | 5 | // Copyright 1996-2003 Glyph & Cog, LLC |
9c72faab | 6 | // |
7 | //======================================================================== | |
8 | ||
9 | #ifndef LINK_H | |
10 | #define LINK_H | |
11 | ||
ae65da6c | 12 | #include <config.h> |
13 | ||
14 | #ifdef USE_GCC_PRAGMAS | |
9c72faab | 15 | #pragma interface |
16 | #endif | |
17 | ||
18 | #include "Object.h" | |
19 | ||
20 | class GString; | |
21 | class Array; | |
22 | class Dict; | |
23 | ||
24 | //------------------------------------------------------------------------ | |
25 | // LinkAction | |
26 | //------------------------------------------------------------------------ | |
27 | ||
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 | |
b5cb0608 | 33 | actionNamed, // named action |
ae65da6c | 34 | actionMovie, // movie action |
9c72faab | 35 | actionUnknown // anything else |
36 | }; | |
37 | ||
38 | class LinkAction { | |
39 | public: | |
40 | ||
41 | // Destructor. | |
42 | virtual ~LinkAction() {} | |
43 | ||
44 | // Was the LinkAction created successfully? | |
45 | virtual GBool isOk() = 0; | |
46 | ||
47 | // Check link action type. | |
48 | virtual LinkActionKind getKind() = 0; | |
ae65da6c | 49 | |
50 | // Parse a destination (old-style action) name, string, or array. | |
51 | static LinkAction *parseDest(Object *obj); | |
52 | ||
53 | // Parse an action dictionary. | |
54 | static LinkAction *parseAction(Object *obj, GString *baseURI = NULL); | |
55 | ||
56 | // Extract a file name from a file specification (string or | |
57 | // dictionary). | |
58 | static GString *getFileSpecName(Object *fileSpecObj); | |
9c72faab | 59 | }; |
60 | ||
61 | //------------------------------------------------------------------------ | |
62 | // LinkDest | |
63 | //------------------------------------------------------------------------ | |
64 | ||
65 | enum LinkDestKind { | |
66 | destXYZ, | |
67 | destFit, | |
68 | destFitH, | |
69 | destFitV, | |
70 | destFitR, | |
71 | destFitB, | |
72 | destFitBH, | |
73 | destFitBV | |
74 | }; | |
75 | ||
76 | class LinkDest { | |
77 | public: | |
78 | ||
be8c3862 | 79 | // Build a LinkDest from the array. |
80 | LinkDest(Array *a); | |
9c72faab | 81 | |
82 | // Copy a LinkDest. | |
83 | LinkDest *copy() { return new 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 | ||
127 | // Build a LinkGoTo from a destination (dictionary, name, or string). | |
128 | LinkGoTo(Object *destObj); | |
129 | ||
130 | // Destructor. | |
131 | virtual ~LinkGoTo(); | |
132 | ||
133 | // Was the LinkGoTo created successfully? | |
134 | virtual GBool isOk() { return dest || namedDest; } | |
135 | ||
136 | // Accessors. | |
137 | virtual LinkActionKind getKind() { return actionGoTo; } | |
138 | LinkDest *getDest() { return dest; } | |
139 | GString *getNamedDest() { return namedDest; } | |
140 | ||
141 | private: | |
142 | ||
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) | |
147 | }; | |
148 | ||
149 | //------------------------------------------------------------------------ | |
150 | // LinkGoToR | |
151 | //------------------------------------------------------------------------ | |
152 | ||
153 | class LinkGoToR: public LinkAction { | |
154 | public: | |
155 | ||
156 | // Build a LinkGoToR from a file spec (dictionary) and destination | |
157 | // (dictionary, name, or string). | |
158 | LinkGoToR(Object *fileSpecObj, Object *destObj); | |
159 | ||
160 | // Destructor. | |
161 | virtual ~LinkGoToR(); | |
162 | ||
163 | // Was the LinkGoToR created successfully? | |
164 | virtual GBool isOk() { return fileName && (dest || namedDest); } | |
165 | ||
166 | // Accessors. | |
167 | virtual LinkActionKind getKind() { return actionGoToR; } | |
168 | GString *getFileName() { return fileName; } | |
169 | LinkDest *getDest() { return dest; } | |
170 | GString *getNamedDest() { return namedDest; } | |
171 | ||
172 | private: | |
173 | ||
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) | |
179 | }; | |
180 | ||
181 | //------------------------------------------------------------------------ | |
182 | // LinkLaunch | |
183 | //------------------------------------------------------------------------ | |
184 | ||
185 | class LinkLaunch: public LinkAction { | |
186 | public: | |
187 | ||
188 | // Build a LinkLaunch from an action dictionary. | |
189 | LinkLaunch(Object *actionObj); | |
190 | ||
191 | // Destructor. | |
192 | virtual ~LinkLaunch(); | |
193 | ||
194 | // Was the LinkLaunch created successfully? | |
195 | virtual GBool isOk() { return fileName != NULL; } | |
196 | ||
197 | // Accessors. | |
198 | virtual LinkActionKind getKind() { return actionLaunch; } | |
199 | GString *getFileName() { return fileName; } | |
200 | GString *getParams() { return params; } | |
201 | ||
202 | private: | |
203 | ||
204 | GString *fileName; // file name | |
205 | GString *params; // parameters | |
206 | }; | |
207 | ||
208 | //------------------------------------------------------------------------ | |
209 | // LinkURI | |
210 | //------------------------------------------------------------------------ | |
211 | ||
212 | class LinkURI: public LinkAction { | |
213 | public: | |
214 | ||
215 | // Build a LinkURI given the URI (string) and base URI. | |
216 | LinkURI(Object *uriObj, GString *baseURI); | |
217 | ||
218 | // Destructor. | |
219 | virtual ~LinkURI(); | |
220 | ||
221 | // Was the LinkURI created successfully? | |
222 | virtual GBool isOk() { return uri != NULL; } | |
223 | ||
224 | // Accessors. | |
225 | virtual LinkActionKind getKind() { return actionURI; } | |
226 | GString *getURI() { return uri; } | |
227 | ||
228 | private: | |
229 | ||
230 | GString *uri; // the URI | |
231 | }; | |
232 | ||
b5cb0608 | 233 | //------------------------------------------------------------------------ |
234 | // LinkNamed | |
235 | //------------------------------------------------------------------------ | |
236 | ||
237 | class LinkNamed: public LinkAction { | |
238 | public: | |
239 | ||
240 | // Build a LinkNamed given the action name. | |
241 | LinkNamed(Object *nameObj); | |
242 | ||
243 | virtual ~LinkNamed(); | |
244 | ||
245 | virtual GBool isOk() { return name != NULL; } | |
246 | ||
247 | virtual LinkActionKind getKind() { return actionNamed; } | |
248 | GString *getName() { return name; } | |
249 | ||
250 | private: | |
251 | ||
252 | GString *name; | |
253 | }; | |
254 | ||
ae65da6c | 255 | //------------------------------------------------------------------------ |
256 | // LinkMovie | |
257 | //------------------------------------------------------------------------ | |
258 | ||
259 | class LinkMovie: public LinkAction { | |
260 | public: | |
261 | ||
262 | LinkMovie(Object *annotObj, Object *titleObj); | |
263 | ||
264 | virtual ~LinkMovie(); | |
265 | ||
266 | virtual GBool isOk() { return annotRef.num >= 0 || title != NULL; } | |
267 | ||
268 | virtual LinkActionKind getKind() { return actionMovie; } | |
269 | GBool hasAnnotRef() { return annotRef.num >= 0; } | |
270 | Ref *getAnnotRef() { return &annotRef; } | |
271 | GString *getTitle() { return title; } | |
272 | ||
273 | private: | |
274 | ||
275 | Ref annotRef; | |
276 | GString *title; | |
277 | }; | |
278 | ||
9c72faab | 279 | //------------------------------------------------------------------------ |
280 | // LinkUnknown | |
281 | //------------------------------------------------------------------------ | |
282 | ||
283 | class LinkUnknown: public LinkAction { | |
284 | public: | |
285 | ||
286 | // Build a LinkUnknown with the specified action type. | |
ae65da6c | 287 | LinkUnknown(char *actionA); |
9c72faab | 288 | |
289 | // Destructor. | |
290 | virtual ~LinkUnknown(); | |
291 | ||
292 | // Was the LinkUnknown create successfully? | |
293 | virtual GBool isOk() { return action != NULL; } | |
294 | ||
295 | // Accessors. | |
296 | virtual LinkActionKind getKind() { return actionUnknown; } | |
297 | GString *getAction() { return action; } | |
298 | ||
299 | private: | |
300 | ||
301 | GString *action; // action subtype | |
302 | }; | |
303 | ||
304 | //------------------------------------------------------------------------ | |
305 | // Link | |
306 | //------------------------------------------------------------------------ | |
307 | ||
308 | class Link { | |
309 | public: | |
310 | ||
311 | // Construct a link, given its dictionary. | |
312 | Link(Dict *dict, GString *baseURI); | |
313 | ||
314 | // Destructor. | |
315 | ~Link(); | |
316 | ||
317 | // Was the link created successfully? | |
318 | GBool isOk() { return ok; } | |
319 | ||
320 | // Check if point is inside the link rectangle. | |
321 | GBool inRect(double x, double y) | |
322 | { return x1 <= x && x <= x2 && y1 <= y && y <= y2; } | |
323 | ||
324 | // Get action. | |
325 | LinkAction *getAction() { return action; } | |
326 | ||
327 | // Get border corners and width. | |
328 | void getBorder(double *xa1, double *ya1, double *xa2, double *ya2, | |
329 | double *wa) | |
330 | { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; *wa = borderW; } | |
331 | ||
332 | private: | |
333 | ||
334 | double x1, y1; // lower left corner | |
335 | double x2, y2; // upper right corner | |
336 | double borderW; // border width | |
337 | LinkAction *action; // action | |
338 | GBool ok; // is link valid? | |
339 | }; | |
340 | ||
341 | //------------------------------------------------------------------------ | |
342 | // Links | |
343 | //------------------------------------------------------------------------ | |
344 | ||
345 | class Links { | |
346 | public: | |
347 | ||
348 | // Extract links from array of annotations. | |
349 | Links(Object *annots, GString *baseURI); | |
350 | ||
351 | // Destructor. | |
352 | ~Links(); | |
353 | ||
354 | // Iterate through list of links. | |
355 | int getNumLinks() { return numLinks; } | |
356 | Link *getLink(int i) { return links[i]; } | |
357 | ||
358 | // If point <x>,<y> is in a link, return the associated action; | |
359 | // else return NULL. | |
360 | LinkAction *find(double x, double y); | |
361 | ||
362 | // Return true if <x>,<y> is in a link. | |
363 | GBool onLink(double x, double y); | |
364 | ||
365 | private: | |
366 | ||
367 | Link **links; | |
368 | int numLinks; | |
369 | }; | |
370 | ||
371 | #endif |