source: trunk/poppler/mypoppler/poppler/Form.h @ 250

Last change on this file since 250 was 250, checked in by Eugene Romanenko, 13 years ago

PDF plugin: poppler library updated to version 0.8.3

File size: 12.9 KB
Line 
1//========================================================================
2//
3// Form.h
4//
5// Copyright 2006 Julien Rebetez
6//
7//========================================================================
8
9#ifndef FORM_H
10#define FORM_H
11
12#ifdef USE_GCC_PRAGMAS
13#pragma interface
14#endif
15
16#include "Object.h"
17#include "goo/GooVector.h"
18
19class GooString;
20class Array;
21class Dict;
22class Annot;
23class Catalog;
24
25enum FormFieldType {
26  formButton,
27  formText,
28  formChoice,
29  formSignature,
30  formUndef,
31};
32
33enum FormButtonType {
34  formButtonCheck,
35  formButtonPush,
36  formButtonRadio
37};
38
39class Form;
40class FormField;
41class FormFieldButton;
42class FormFieldText;
43class FormFieldSignature;
44class FormFieldChoice;
45
46//------------------------------------------------------------------------
47// FormWidget
48// A FormWidget represents the graphical part of a field and is "attached"
49// to a page.
50//------------------------------------------------------------------------
51
52class FormWidget {
53public:
54  virtual ~FormWidget();
55
56  // see the description of FormField::LoadChildrenDefaults
57  virtual void loadDefaults () {}
58 
59  // Check if point is inside the field bounding rect
60  GBool inRect(double x, double y)
61    { return x1 <= x && x <= x2 && y1 <= y && y <= y2; }
62
63  // Get the field bounding rect
64  void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
65    { *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
66
67  unsigned getID () { return ID; }
68  void setID (unsigned int i) { ID=i; }
69
70  FormField *getField () { return field; }
71  FormFieldType getType() { return type; }
72
73  Object* getObj() { return &obj; }
74  Ref getRef() { return ref; }
75
76  void setChildNum (unsigned i) { childNum = i; }
77  unsigned getChildNum () { return childNum; }
78
79  void setFontSize(double f) { fontSize = f; }
80  double getFontSize () { return fontSize; }
81
82  GBool isModified () { return modified; }
83
84  bool isReadOnly() const;
85
86  // return the unique ID corresponding to pageNum/fieldNum
87  static int encodeID (unsigned pageNum, unsigned fieldNum);
88  // decode id and retrieve pageNum and fieldNum
89  static void decodeID (unsigned id, unsigned* pageNum, unsigned* fieldNum);
90
91protected:
92  FormWidget(XRef *xrefA, Object *aobj, unsigned num, Ref aref, FormField *fieldA);
93  FormWidget(FormWidget *dest);
94
95  void updateField (const char *key, Object *value);
96
97  FormField* field;
98  FormFieldType type;
99  Object obj;
100  Ref ref;
101  XRef *xref;
102  GBool defaultsLoaded;
103  GBool modified;
104  //index of this field in the parent's child list
105  unsigned childNum;
106
107  /*
108  Field ID is an (unsigned) integer, calculated as follow :
109  the first sizeof/2 bits are the field number, relative to the page
110  the last sizeof/2 bits are the page number
111  [page number | field number]
112  (encoding) id = (pageNum << 4*sizeof(unsigned)) + fieldNum;
113  (decoding) pageNum = id >> 4*sizeof(unsigned); fieldNum = (id << 4*sizeof(unsigned)) >> 4*sizeof(unsigned);
114  */
115  unsigned ID; 
116
117  double x1, y1;                // lower left corner
118  double x2, y2;                // upper right corner
119  double fontSize; //font size if this widget has text
120
121};
122
123//------------------------------------------------------------------------
124// FormWidgetButton
125//------------------------------------------------------------------------
126
127class FormWidgetButton: public FormWidget {
128public:
129  FormWidgetButton(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
130  ~FormWidgetButton ();
131
132  FormButtonType getButtonType() const;
133 
134  void setState (GBool state, GBool calledByParent=gFalse);
135  GBool getState ();
136
137  char* getOnStr () { return onStr->getCString(); }
138
139  void loadDefaults();
140
141  void setNumSiblingsID (int i);
142  void setSiblingsID (int i, unsigned id) { siblingsID[i] = id; }
143
144  //For radio buttons, return the IDs of the other radio buttons in the same group
145  unsigned* getSiblingsID () const { return siblingsID; }
146  int getNumSiblingsID () const { return numSiblingsID; }
147
148protected:
149  unsigned* siblingsID; // IDs of dependent buttons (each button of a radio field has all the others buttons
150                        // of the same field in this array)
151  int numSiblingsID;
152  GooString *onStr;
153  FormFieldButton *parent;
154  GBool state;
155};
156
157//------------------------------------------------------------------------
158// FormWidgetText
159//------------------------------------------------------------------------
160
161class FormWidgetText: public FormWidget {
162public:
163  FormWidgetText(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
164  //return the field's content (UTF16BE)
165  GooString* getContent() ;
166  //return a copy of the field's content (UTF16BE)
167  GooString* getContentCopy();
168
169  //except a UTF16BE string
170  void setContent(GooString* new_content);
171
172  void loadDefaults ();
173
174  bool isMultiline () const; 
175  bool isPassword () const; 
176  bool isFileSelect () const; 
177  bool noSpellCheck () const; 
178  bool noScroll () const; 
179  bool isComb () const; 
180  bool isRichText () const;
181  int getMaxLen () const;
182protected:
183  FormFieldText *parent;
184};
185
186//------------------------------------------------------------------------
187// FormWidgetChoice
188//------------------------------------------------------------------------
189
190class FormWidgetChoice: public FormWidget {
191public:
192  FormWidgetChoice(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
193  ~FormWidgetChoice();
194
195  void loadDefaults ();
196  int getNumChoices();
197  //return the display name of the i-th choice (UTF16BE)
198  GooString* getChoice(int i);
199  //select the i-th choice
200  void select (int i); 
201
202  //toggle selection of the i-th choice
203  void toggle (int i);
204
205  //deselect everything
206  void deselectAll ();
207
208  //except a UTF16BE string
209  //only work for editable combo box, set the user-entered text as the current choice
210  void setEditChoice(GooString* new_content);
211
212  GooString* getEditChoice ();
213
214  bool isSelected (int i);
215
216  bool isCombo () const; 
217  bool hasEdit () const; 
218  bool isMultiSelect () const; 
219  bool noSpellCheck () const; 
220  bool commitOnSelChange () const; 
221  bool isListBox () const;
222protected:
223  void _updateV ();
224  bool _checkRange (int i);
225  FormFieldChoice *parent;
226};
227
228//------------------------------------------------------------------------
229// FormWidgetSignature
230//------------------------------------------------------------------------
231
232class FormWidgetSignature: public FormWidget {
233public:
234  FormWidgetSignature(XRef *xrefA, Object *dict, unsigned num, Ref ref, FormField *p);
235protected:
236  FormFieldSignature *parent;
237};
238
239//------------------------------------------------------------------------
240// FormField
241// A FormField implements the logical side of a field and is "attached" to
242// the Catalog. This is an internal class and client applications should
243// only interact with FormWidgets.
244//------------------------------------------------------------------------
245
246class FormField {
247public:
248  FormField(XRef* xrefa, Object *aobj, const Ref& aref, FormFieldType t=formUndef);
249
250  virtual ~FormField();
251
252  // Accessors.
253  FormFieldType getType() { return type; }
254  Object* getObj() { return &obj; }
255  Ref getRef() { return ref; }
256
257  void setReadOnly (bool b) { readOnly = b; }
258  bool isReadOnly () const { return readOnly; }
259
260  FormWidget* findWidgetByRef (Ref aref);
261  // Since while loading their defaults, children may call parents methods, it's better
262  // to do that when parents are completly constructed
263  void loadChildrenDefaults();
264
265  // only implemented in FormFieldButton
266  virtual void fillChildrenSiblingsID ();
267
268
269 protected:
270  void _createWidget (Object *obj, Ref aref);
271
272  FormFieldType type;           // field type
273  Ref ref;
274  bool terminal;
275  Object obj;
276  XRef *xref;
277  FormField **children;
278  int numChildren;
279  FormWidget **widgets;
280  bool readOnly;
281
282private:
283  FormField() {}
284};
285
286
287//------------------------------------------------------------------------
288// FormFieldButton
289//------------------------------------------------------------------------
290
291class FormFieldButton: public FormField {
292public:
293  FormFieldButton(XRef *xrefA, Object *dict, const Ref& ref);
294
295  FormButtonType getButtonType () { return btype; }
296
297  bool noToggleToOff () const { return noAllOff; }
298
299  // returns gTrue if the state modification is accepted
300  GBool setState (int num, GBool s);
301 
302  void fillChildrenSiblingsID ();
303
304  virtual ~FormFieldButton();
305protected:
306  FormButtonType btype;
307  int size;
308  int active_child; //only used for combo box
309  bool noAllOff;
310};
311
312//------------------------------------------------------------------------
313// FormFieldText
314//------------------------------------------------------------------------
315
316class FormFieldText: public FormField {
317public:
318  FormFieldText(XRef *xrefA, Object *dict, const Ref& ref);
319 
320  GooString* getContent () { return content; }
321  GooString* getContentCopy ();
322  void setContentCopy (GooString* new_content);
323  virtual ~FormFieldText();
324
325  bool isMultiline () const { return multiline; }
326  bool isPassword () const { return password; }
327  bool isFileSelect () const { return fileSelect; }
328  bool noSpellCheck () const { return doNotSpellCheck; }
329  bool noScroll () const { return doNotScroll; }
330  bool isComb () const { return comb; }
331  bool isRichText () const { return richText; }
332
333  int getMaxLen () const { return maxLen; }
334protected:
335  GooString* content;
336  bool multiline;
337  bool password;
338  bool fileSelect;
339  bool doNotSpellCheck;
340  bool doNotScroll;
341  bool comb;
342  bool richText;
343  int maxLen;
344};
345
346//------------------------------------------------------------------------
347// FormFieldChoice
348//------------------------------------------------------------------------
349
350class FormFieldChoice: public FormField {
351public:
352  FormFieldChoice(XRef *xrefA, Object *aobj, const Ref& ref);
353
354  virtual ~FormFieldChoice();
355
356  int getNumChoices() { return numChoices; }
357  GooString* getChoice(int i) { return choices[i].optionName; }
358  GooString* getExportVal (int i) { return choices[i].exportVal; }
359
360  //select the i-th choice
361  void select (int i); 
362
363  //toggle selection of the i-th choice
364  void toggle (int i);
365
366  //deselect everything
367  void deselectAll ();
368
369  //only work for editable combo box, set the user-entered text as the current choice
370  void setEditChoice(GooString* new_content);
371
372  GooString* getEditChoice ();
373
374  bool isSelected (int i) { return choices[i].selected; }
375
376  int getNumSelected ();
377
378  bool isCombo () const { return combo; }
379  bool hasEdit () const { return edit; }
380  bool isMultiSelect () const { return multiselect; }
381  bool noSpellCheck () const { return doNotSpellCheck; }
382  bool commitOnSelChange () const { return doCommitOnSelChange; }
383  bool isListBox () const { return !combo; }
384
385  /* these functions _must_ only be used by FormWidgetChoice */
386  void _setNumChoices (int i) { numChoices = i; }
387  void _createChoicesTab ();
388  void _setChoiceExportVal (int i, GooString* str) { choices[i].exportVal = str; }
389  void _setChoiceOptionName (int i, GooString* str) { choices[i].optionName = str; }
390
391protected:
392  bool combo;
393  bool edit;
394  bool multiselect;
395  bool doNotSpellCheck;
396  bool doCommitOnSelChange;
397
398  struct ChoiceOpt {
399    GooString* exportVal; //the export value ("internal" name)
400    GooString* optionName; //displayed name
401    bool selected; //if this choice is selected
402  };
403
404  int numChoices;
405  ChoiceOpt* choices;
406  GooString* editedChoice; 
407};
408
409//------------------------------------------------------------------------
410// FormFieldSignature
411//------------------------------------------------------------------------
412
413class FormFieldSignature: public FormField {
414public:
415  FormFieldSignature(XRef *xrefA, Object *dict, const Ref& ref);
416
417  virtual ~FormFieldSignature();
418};
419
420//------------------------------------------------------------------------
421// Form
422// This class handle the document-wide part of Form (things in the acroForm
423// Catalog entry).
424//------------------------------------------------------------------------
425
426class Form {
427public:
428  Form(XRef *xrefA, Object* acroForm);
429
430  ~Form();
431
432  // Look up an inheritable field dictionary entry.
433  static Object *fieldLookup(Dict *field, char *key, Object *obj);
434 
435  /* Creates a new Field of the type specified in obj's dict.
436     used in Form::Form and FormField::FormField */
437  static FormField *createFieldFromDict (Object* obj, XRef *xref, const Ref& aref);
438
439  Object *getObj () const { return acroForm; }
440  GBool getNeedAppearances () const { return needAppearances; }
441  int getNumFields() const { return numFields; }
442  FormField* getRootField(int i) const { return rootFields[i]; }
443
444  FormWidget* findWidgetByRef (Ref aref);
445
446  void postWidgetsLoad();
447private:
448  FormField** rootFields;
449  int numFields;
450  int size;
451  XRef* xref;
452  Object *acroForm;
453  GBool needAppearances;
454};
455
456//------------------------------------------------------------------------
457// FormPageWidgets
458//------------------------------------------------------------------------
459
460class FormPageWidgets {
461public:
462  FormPageWidgets (XRef *xrefA, Object* annots, unsigned int page, Form *form);
463  ~FormPageWidgets();
464 
465  int getNumWidgets() const { return numWidgets; }
466  FormWidget* getWidget(int i) const { return widgets[i]; }
467
468private:
469  FormWidget** widgets;
470  int numWidgets;
471  int size;
472  unsigned pageNum;
473  XRef* xref;
474};
475
476#endif
477
Note: See TracBrowser for help on using the repository browser.