~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/xpdflib/link.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2005-02-24 22:09:16 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050224220916-9vxiiqjz066r5489
Tags: 6.0pre23-2
debian/control: Ipe should depend on exact version of libipe.
Closes: #296771.

Show diffs side-by-side

added added

removed removed

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