]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | //======================================================================== |
2 | // | |
3 | // Link.h | |
4 | // | |
5 | // Copyright 1996-2003 Glyph & Cog, LLC | |
6 | // | |
7 | //======================================================================== | |
8 | ||
9 | #ifndef LINK_H | |
10 | #define LINK_H | |
11 | ||
12 | #include <config.h> | |
13 | ||
14 | #ifdef USE_GCC_PRAGMAS | |
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 | |
33 | actionNamed, // named action | |
34 | actionMovie, // movie action | |
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; | |
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); | |
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 | ||
79 | // Build a LinkDest from the array. | |
80 | LinkDest(Array *a); | |
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 | ||
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 | ||
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 | ||
279 | //------------------------------------------------------------------------ | |
280 | // LinkUnknown | |
281 | //------------------------------------------------------------------------ | |
282 | ||
283 | class LinkUnknown: public LinkAction { | |
284 | public: | |
285 | ||
286 | // Build a LinkUnknown with the specified action type. | |
287 | LinkUnknown(char *actionA); | |
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 | // LinkBorderStyle | |
306 | //------------------------------------------------------------------------ | |
307 | ||
308 | enum LinkBorderType { | |
309 | linkBorderSolid, | |
310 | linkBorderDashed, | |
311 | linkBorderEmbossed, | |
312 | linkBorderEngraved, | |
313 | linkBorderUnderlined | |
314 | }; | |
315 | ||
316 | class LinkBorderStyle { | |
317 | public: | |
318 | ||
319 | LinkBorderStyle(LinkBorderType typeA, double widthA, | |
320 | double *dashA, int dashLengthA, | |
321 | double rA, double gA, double bA); | |
322 | ~LinkBorderStyle(); | |
323 | ||
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; } | |
330 | ||
331 | private: | |
332 | ||
333 | LinkBorderType type; | |
334 | double width; | |
335 | double *dash; | |
336 | int dashLength; | |
337 | double r, g, b; | |
338 | }; | |
339 | ||
340 | //------------------------------------------------------------------------ | |
341 | // Link | |
342 | //------------------------------------------------------------------------ | |
343 | ||
344 | class Link { | |
345 | public: | |
346 | ||
347 | // Construct a link, given its dictionary. | |
348 | Link(Dict *dict, GString *baseURI); | |
349 | ||
350 | // Destructor. | |
351 | ~Link(); | |
352 | ||
353 | // Was the link created successfully? | |
354 | GBool isOk() { return ok; } | |
355 | ||
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; } | |
359 | ||
360 | // Get action. | |
361 | LinkAction *getAction() { return action; } | |
362 | ||
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; } | |
366 | ||
367 | // Get the border style info. | |
368 | LinkBorderStyle *getBorderStyle() { return borderStyle; } | |
369 | ||
370 | private: | |
371 | ||
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? | |
377 | }; | |
378 | ||
379 | //------------------------------------------------------------------------ | |
380 | // Links | |
381 | //------------------------------------------------------------------------ | |
382 | ||
383 | class Links { | |
384 | public: | |
385 | ||
386 | // Extract links from array of annotations. | |
387 | Links(Object *annots, GString *baseURI); | |
388 | ||
389 | // Destructor. | |
390 | ~Links(); | |
391 | ||
392 | // Iterate through list of links. | |
393 | int getNumLinks() { return numLinks; } | |
394 | Link *getLink(int i) { return links[i]; } | |
395 | ||
396 | // If point <x>,<y> is in a link, return the associated action; | |
397 | // else return NULL. | |
398 | LinkAction *find(double x, double y); | |
399 | ||
400 | // Return true if <x>,<y> is in a link. | |
401 | GBool onLink(double x, double y); | |
402 | ||
403 | private: | |
404 | ||
405 | Link **links; | |
406 | int numLinks; | |
407 | }; | |
408 | ||
409 | #endif |