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

Last change on this file since 277 was 277, checked in by rbri, 12 years ago

PDF plugin: Poppler library updated to version 0.12.3

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