Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / xpdf / Annotations.h
blob11abfbe61d674867370b440bfd29237e84619fce
1 //========================================================================
2 //
3 // Annotations.h
4 //
5 // Copyright 2000-2005 Emmanuel Lesueur
6 //
7 //========================================================================
9 #ifndef ANNOTATIONS_H
10 #define ANNOTATIONS_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "Object.h"
19 #include "Action.h"
21 class GfxColor;
22 class AcroForm;
23 class Field;
24 class Annot;
26 //------------------------------------------------------------------------
27 // Annot
28 //------------------------------------------------------------------------
30 const int annotInvisible = 1 << 0;
31 const int annotHidden = 1 << 1;
32 const int annotPrint = 1 << 2;
33 const int annotNoZoom = 1 << 3;
34 const int annotNoRotate = 1 << 4;
35 const int annotNoView = 1 << 5;
36 const int annotReadOnly = 1 << 6;
38 enum AnnotKind {
39 annotText,
40 annotLink,
41 annotMovie,
42 annotSound,
43 annotFreeText,
44 annotRubberStamp,
45 annotLine,
46 annotSquare,
47 annotCircle,
48 annotStrikeOut,
49 annotHighlight,
50 annotUnderline,
51 annotInk,
52 annotFileAttachment,
53 annotPopup,
54 annotTrapNet,
55 annotWidget,
56 annotUnknown
59 enum AnnotHighlight {
60 highlightInvert,
61 highlightNone,
62 highlightOutline,
63 highlightPush
66 /*enum AnnotBorder {
67 borderNone,
68 borderSolid,
69 borderDashed,
70 borderBeveled,
71 borderInset,
72 borderUnderlined
73 };*/
75 enum AnnotAppearance {
76 appearanceNormal,
77 appearanceRollover,
78 appearanceDown
81 class AnnotState {
82 friend class Annot;
83 public:
85 AnnotState(): setFlags(0), clrFlags(0), additionalAction(NULL) {}
86 ~AnnotState();
88 // Import from an FDF dictionary.
89 void import(Dict *);
91 private:
92 AnnotState(const AnnotState&);
93 AnnotState& operator = (const AnnotState&);
95 int setFlags;
96 int clrFlags;
97 Object appearance[3];
98 Object appearanceState;
99 AdditionalAction *additionalAction;
103 class Annot {
104 public:
106 // Constructor.
107 Annot(XRef *, Object *);
109 // Destructor.
110 virtual ~Annot();
112 // Check annotation type.
113 virtual AnnotKind getKind() { return annotUnknown; }
115 // Get the annotation description string.
116 virtual char *getDescr() { return NULL; }
118 // Was the Annot created successfully?
119 GBool isOk() { return ok; }
121 // Get annotation box.
122 void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
123 { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
125 // Check if point is inside the link rectangle.
126 //GBool inRect(double x, double y)
127 // { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
129 // Is the annotation invisible?
130 GBool isInvisible() { return flags & annotInvisible; }
132 // Is the annotation hidden?
133 GBool isHidden() { return flags & annotHidden; }
135 // Is the annotation read-only?
136 GBool isReadOnly() { return flags & annotReadOnly; }
138 // Get the highlight mode.
139 AnnotHighlight getHighlightMode() { return highlightMode; }
141 // Get the annotation appearance.
142 Object *getAppearance(XRef *xref, AnnotAppearance a, Object *obj);
143 Object *getAppearance(XRef *xref, Object *obj) {
144 return getAppearance(xref, curAppearance, obj);
146 Dict *getAppearanceDict() {
147 return appearance[appearanceNormal].isDict() ?
148 appearance[appearanceNormal].getDict() : NULL;
151 // Get the annotation border.
152 Object *getBorder(Object *obj) { return border.copy(obj); }
154 // Get the appearance state.
155 char *getAppearanceState();
157 // Get the additional action.
158 AdditionalAction *getAdditionalAction() { return additionalAction; }
160 // Set the additional action.
161 //void setAdditionalAction(AdditionalAction *);
163 // Add an action.
164 void addAdditionalAction(ActionTrigger, Action *);
166 // Set the appearance state.
167 GBool setAppearance(AnnotAppearance a) {
168 if (curAppearance == a)
169 return gFalse;
170 curAppearance = a;
171 return gTrue;
173 void setAppearance(AnnotAppearance a, Object *);
175 // Set the appearance state.
176 void setAppearanceState(char *);
178 // Change the hidden flag.
179 void hide(GBool f) { if (f) flags |= annotHidden; else flags &= ~annotHidden; }
181 // Check if an annotation has a specific appearance
182 GBool hasAppearance(AnnotAppearance);
184 // Build an appearance stream.
185 Object *makeAppearanceStream(GString *, Object *);
187 // Remove the border.
188 void noBorder() { border.free(); border.initNull(); }
190 // Get the annotation title.
191 GString *getTitle() { return title; }
193 // Save the annotation state.
194 void saveState(AnnotState *);
196 // Restore the annotation state.
197 void restoreState(AnnotState *);
199 private:
201 double x1, y1; // lower left corner
202 double x2, y2; // upper right corner
203 GfxColor *color; // annotation color
204 GString *title; // annotation title
205 int flags;
206 AnnotHighlight highlightMode; // highlight mode
207 Object appearance[3]; // appearances
208 Object appearanceState;
209 Object border;
210 AnnotAppearance curAppearance;// current appearance
211 AdditionalAction *additionalAction;
212 //~ Dict *popup;
213 //~ Dict *page;
214 GBool ok; // is link valid?
218 //------------------------------------------------------------------------
219 // RawTextAnnot
220 //------------------------------------------------------------------------
222 class RawTextAnnot : public Annot {
223 public:
225 // Constructor.
226 RawTextAnnot(XRef *, Object *);
228 // Destructor.
229 virtual ~RawTextAnnot();
231 // Accessors.
232 virtual AnnotKind getKind() { return annotUnknown; }
233 GString *getContents() { return contents; }
235 private:
236 GString *contents;
237 GBool open;
240 //------------------------------------------------------------------------
241 // TextAnnot
242 //------------------------------------------------------------------------
244 class TextAnnot : public RawTextAnnot {
245 public:
247 // Constructor.
248 TextAnnot(XRef *, Object *);
250 // Accessors.
251 virtual AnnotKind getKind() { return annotText; }
255 //------------------------------------------------------------------------
256 // LineAnnot
257 //------------------------------------------------------------------------
259 class LineAnnot : public RawTextAnnot {
260 public:
262 // Constructor.
263 LineAnnot(XRef *, Object *);
265 // Accessor.
266 virtual AnnotKind getKind() { return annotLine; }
270 //------------------------------------------------------------------------
271 // SquareAnnot
272 //------------------------------------------------------------------------
274 class SquareAnnot : public RawTextAnnot {
275 public:
277 // Constructor.
278 SquareAnnot(XRef *, Object *);
280 // Accessor.
281 virtual AnnotKind getKind() { return annotSquare; }
285 //------------------------------------------------------------------------
286 // CircleAnnot
287 //------------------------------------------------------------------------
289 class CircleAnnot : public RawTextAnnot {
290 public:
292 // Constructor.
293 CircleAnnot(XRef *, Object *);
295 // Accessor.
296 virtual AnnotKind getKind() { return annotCircle; }
300 //------------------------------------------------------------------------
301 // LinkAnnot
302 //------------------------------------------------------------------------
304 class LinkAnnot : public Annot {
305 public:
307 // Constructor.
308 LinkAnnot(XRef *, Object *);
310 // Destructor.
311 virtual ~LinkAnnot();
313 // Accessors.
314 virtual AnnotKind getKind() { return annotLink; }
316 // Get the description string.
317 virtual char *getDescr() { return action ? action->getDescr() : NULL; }
319 // Get action.
320 Action *getAction() { return action; }
322 private:
323 Action *action;
327 //------------------------------------------------------------------------
328 // WidgetAnnot
329 //------------------------------------------------------------------------
331 class WidgetAnnot : public Annot {
332 public:
334 WidgetAnnot(XRef *, Object *, Field *);
336 // Destructor.
337 virtual ~WidgetAnnot();
339 // Accessors.
340 virtual AnnotKind getKind() { return annotWidget; }
342 private:
343 Field *field;
347 //------------------------------------------------------------------------
348 // Annots
349 //------------------------------------------------------------------------
351 class Annots {
352 public:
354 // Read the array of annotations.
355 Annots(XRef *xref, Object *annots, AcroForm *form);
357 // Destructor.
358 ~Annots();
360 // Iterate through list of links.
361 int getNumAnnots() { return numAnnots; }
362 Annot *getAnnot(int i) { return annots[i]; }
364 // If point <x>,<y> is on an annotation, return it,
365 // else return NULL.
366 Annot *find(double x, double y);
368 // Return true if <x>,<y> is on an annotation.
369 GBool onAnnot(double x, double y);
371 private:
373 Annot **annots;
374 int numAnnots;
377 #endif