1 //========================================================================
5 // This file is licensed under the GPLv2 or later
7 // Copyright 2006 Julien Rebetez <julienr@svn.gnome.org>
8 // Copyright 2007, 2008, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
9 // Copyright 2007-2010, 2012 Albert Astals Cid <aacid@kde.org>
10 // Copyright 2010 Mark Riedesel <mark@klowner.com>
11 // Copyright 2011 Pino Toscano <pino@kde.org>
12 // Copyright 2012 Fabio D'Urso <fabiodurso@hotmail.it>
13 // Copyright 2013 Adrian Johnson <ajohnson@redneon.com>
15 //========================================================================
20 #ifdef USE_GCC_PRAGMAS
53 enum VariableTextQuadding
{
54 quaddingLeftJustified
,
56 quaddingRightJustified
61 class FormFieldButton
;
63 class FormFieldSignature
;
64 class FormFieldChoice
;
66 //------------------------------------------------------------------------
68 // A FormWidget represents the graphical part of a field and is "attached"
70 //------------------------------------------------------------------------
74 virtual ~FormWidget();
76 // Check if point is inside the field bounding rect
77 GBool
inRect(double x
, double y
) const;
79 // Get the field bounding rect
80 void getRect(double *x1
, double *y1
, double *x2
, double *y2
) const;
82 unsigned getID () { return ID
; }
83 void setID (unsigned int i
) { ID
=i
; }
85 FormField
*getField () { return field
; }
86 FormFieldType
getType() { return type
; }
88 Object
* getObj() { return &obj
; }
89 Ref
getRef() { return ref
; }
91 void setChildNum (unsigned i
) { childNum
= i
; }
92 unsigned getChildNum () { return childNum
; }
94 double getFontSize() const;
96 GooString
*getPartialName() const;
97 GooString
*getAlternateUiName() const;
98 GooString
*getMappingName() const;
99 GooString
*getFullyQualifiedName();
101 GBool
isModified () const;
103 bool isReadOnly() const;
105 LinkAction
*getActivationAction();
106 LinkAction
*getAdditionalAction(Annot::FormAdditionalActionsType type
);
108 // return the unique ID corresponding to pageNum/fieldNum
109 static int encodeID (unsigned pageNum
, unsigned fieldNum
);
110 // decode id and retrieve pageNum and fieldNum
111 static void decodeID (unsigned id
, unsigned* pageNum
, unsigned* fieldNum
);
113 void createWidgetAnnotation();
114 AnnotWidget
*getWidgetAnnotation() const { return widget
; }
116 virtual void updateWidgetAppearance() = 0;
119 void print(int indent
= 0);
123 FormWidget(PDFDoc
*docA
, Object
*aobj
, unsigned num
, Ref aref
, FormField
*fieldA
);
133 //index of this field in the parent's child list
137 Field ID is an (unsigned) integer, calculated as follow :
138 the first sizeof/2 bits are the field number, relative to the page
139 the last sizeof/2 bits are the page number
140 [page number | field number]
141 (encoding) id = (pageNum << 4*sizeof(unsigned)) + fieldNum;
142 (decoding) pageNum = id >> 4*sizeof(unsigned); fieldNum = (id << 4*sizeof(unsigned)) >> 4*sizeof(unsigned);
147 //------------------------------------------------------------------------
149 //------------------------------------------------------------------------
151 class FormWidgetButton
: public FormWidget
{
153 FormWidgetButton(PDFDoc
*docA
, Object
*dict
, unsigned num
, Ref ref
, FormField
*p
);
154 ~FormWidgetButton ();
156 FormButtonType
getButtonType() const;
158 void setState (GBool state
);
162 void setAppearanceState(const char *state
);
163 void updateWidgetAppearance();
167 FormFieldButton
*parent
;
170 //------------------------------------------------------------------------
172 //------------------------------------------------------------------------
174 class FormWidgetText
: public FormWidget
{
176 FormWidgetText(PDFDoc
*docA
, Object
*dict
, unsigned num
, Ref ref
, FormField
*p
);
177 //return the field's content (UTF16BE)
178 GooString
* getContent() ;
179 //return a copy of the field's content (UTF16BE)
180 GooString
* getContentCopy();
182 //except a UTF16BE string
183 void setContent(GooString
* new_content
);
185 void updateWidgetAppearance();
187 bool isMultiline () const;
188 bool isPassword () const;
189 bool isFileSelect () const;
190 bool noSpellCheck () const;
191 bool noScroll () const;
192 bool isComb () const;
193 bool isRichText () const;
194 int getMaxLen () const;
196 FormFieldText
*parent
;
199 //------------------------------------------------------------------------
201 //------------------------------------------------------------------------
203 class FormWidgetChoice
: public FormWidget
{
205 FormWidgetChoice(PDFDoc
*docA
, Object
*dict
, unsigned num
, Ref ref
, FormField
*p
);
209 //return the display name of the i-th choice (UTF16BE)
210 GooString
* getChoice(int i
);
211 //select the i-th choice
214 //toggle selection of the i-th choice
217 //deselect everything
220 //except a UTF16BE string
221 //only work for editable combo box, set the user-entered text as the current choice
222 void setEditChoice(GooString
* new_content
);
224 GooString
* getEditChoice ();
226 void updateWidgetAppearance();
227 bool isSelected (int i
);
229 bool isCombo () const;
230 bool hasEdit () const;
231 bool isMultiSelect () const;
232 bool noSpellCheck () const;
233 bool commitOnSelChange () const;
234 bool isListBox () const;
236 bool _checkRange (int i
);
237 FormFieldChoice
*parent
;
240 //------------------------------------------------------------------------
241 // FormWidgetSignature
242 //------------------------------------------------------------------------
244 class FormWidgetSignature
: public FormWidget
{
246 FormWidgetSignature(PDFDoc
*docA
, Object
*dict
, unsigned num
, Ref ref
, FormField
*p
);
247 void updateWidgetAppearance();
249 FormFieldSignature
*parent
;
252 //------------------------------------------------------------------------
254 // A FormField implements the logical side of a field and is "attached" to
255 // the Catalog. This is an internal class and client applications should
256 // only interact with FormWidgets.
257 //------------------------------------------------------------------------
261 FormField(PDFDoc
*docA
, Object
*aobj
, const Ref
& aref
, FormField
*parent
, std::set
<int> *usedParents
, FormFieldType t
=formUndef
);
263 virtual ~FormField();
266 FormFieldType
getType() { return type
; }
267 Object
* getObj() { return &obj
; }
268 Ref
getRef() { return ref
; }
270 void setReadOnly (bool b
) { readOnly
= b
; }
271 bool isReadOnly () const { return readOnly
; }
273 GooString
* getDefaultAppearance() const { return defaultAppearance
; }
274 GBool
hasTextQuadding() const { return hasQuadding
; }
275 VariableTextQuadding
getTextQuadding() const { return quadding
; }
277 GooString
*getPartialName() const { return partialName
; }
278 GooString
*getAlternateUiName() const { return alternateUiName
; }
279 GooString
*getMappingName() const { return mappingName
; }
280 GooString
*getFullyQualifiedName();
282 FormWidget
* findWidgetByRef (Ref aref
);
283 int getNumWidgets() { return terminal
? numChildren
: 0; }
284 FormWidget
*getWidget(int i
) { return terminal
? widgets
[i
] : NULL
; }
286 // only implemented in FormFieldButton
287 virtual void fillChildrenSiblingsID ();
289 void createWidgetAnnotations();
292 void printTree(int indent
= 0);
293 virtual void print(int indent
= 0);
298 void _createWidget (Object
*obj
, Ref aref
);
299 void createChildren(std::set
<int> *usedParents
);
300 void updateChildrenAppearance();
302 FormFieldType type
; // field type
308 FormField
**children
;
311 FormWidget
**widgets
;
314 GooString
*partialName
; // T field
315 GooString
*alternateUiName
; // TU field
316 GooString
*mappingName
; // TM field
317 GooString
*fullyQualifiedName
;
320 GooString
*defaultAppearance
;
322 VariableTextQuadding quadding
;
329 //------------------------------------------------------------------------
331 //------------------------------------------------------------------------
333 class FormFieldButton
: public FormField
{
335 FormFieldButton(PDFDoc
*docA
, Object
*dict
, const Ref
& ref
, FormField
*parent
, std::set
<int> *usedParents
);
337 FormButtonType
getButtonType () { return btype
; }
339 bool noToggleToOff () const { return noAllOff
; }
341 // returns gTrue if the state modification is accepted
342 GBool
setState (char *state
);
343 GBool
getState(char *state
);
345 char *getAppearanceState() { return appearanceState
.isName() ? appearanceState
.getName() : NULL
; }
347 void fillChildrenSiblingsID ();
349 void setNumSiblings (int num
);
350 void setSibling (int i
, FormFieldButton
*id
) { siblings
[i
] = id
; }
352 //For radio buttons, return the fields of the other radio buttons in the same group
353 FormFieldButton
* getSibling (int i
) const { return siblings
[i
]; }
354 int getNumSiblings () const { return numSiblings
; }
357 void print(int indent
= 0);
360 virtual ~FormFieldButton();
362 void updateState(char *state
);
364 FormFieldButton
** siblings
; // IDs of dependent buttons (each button of a radio field has all the others buttons
365 // of the same field in this array)
368 FormButtonType btype
;
370 int active_child
; //only used for combo box
372 Object appearanceState
; // V
375 //------------------------------------------------------------------------
377 //------------------------------------------------------------------------
379 class FormFieldText
: public FormField
{
381 FormFieldText(PDFDoc
*docA
, Object
*dict
, const Ref
& ref
, FormField
*parent
, std::set
<int> *usedParents
);
383 GooString
* getContent () { return content
; }
384 GooString
* getContentCopy ();
385 void setContentCopy (GooString
* new_content
);
386 virtual ~FormFieldText();
388 bool isMultiline () const { return multiline
; }
389 bool isPassword () const { return password
; }
390 bool isFileSelect () const { return fileSelect
; }
391 bool noSpellCheck () const { return doNotSpellCheck
; }
392 bool noScroll () const { return doNotScroll
; }
393 bool isComb () const { return comb
; }
394 bool isRichText () const { return richText
; }
396 int getMaxLen () const { return maxLen
; }
399 void print(int indent
= 0);
406 bool doNotSpellCheck
;
413 //------------------------------------------------------------------------
415 //------------------------------------------------------------------------
417 class FormFieldChoice
: public FormField
{
419 FormFieldChoice(PDFDoc
*docA
, Object
*aobj
, const Ref
& ref
, FormField
*parent
, std::set
<int> *usedParents
);
421 virtual ~FormFieldChoice();
423 int getNumChoices() { return numChoices
; }
424 GooString
* getChoice(int i
) { return choices
? choices
[i
].optionName
: NULL
; }
425 GooString
* getExportVal (int i
) { return choices
? choices
[i
].exportVal
: NULL
; }
426 // For multi-select choices it returns the first one
427 GooString
* getSelectedChoice();
429 //select the i-th choice
432 //toggle selection of the i-th choice
435 //deselect everything
438 //only work for editable combo box, set the user-entered text as the current choice
439 void setEditChoice(GooString
* new_content
);
441 GooString
* getEditChoice ();
443 bool isSelected (int i
) { return choices
[i
].selected
; }
445 int getNumSelected ();
447 bool isCombo () const { return combo
; }
448 bool hasEdit () const { return edit
; }
449 bool isMultiSelect () const { return multiselect
; }
450 bool noSpellCheck () const { return doNotSpellCheck
; }
451 bool commitOnSelChange () const { return doCommitOnSelChange
; }
452 bool isListBox () const { return !combo
; }
454 int getTopIndex() const { return topIdx
; }
457 void print(int indent
= 0);
462 void updateSelection();
467 bool doNotSpellCheck
;
468 bool doCommitOnSelChange
;
471 GooString
* exportVal
; //the export value ("internal" name)
472 GooString
* optionName
; //displayed name
473 bool selected
; //if this choice is selected
478 GooString
* editedChoice
;
482 //------------------------------------------------------------------------
483 // FormFieldSignature
484 //------------------------------------------------------------------------
486 class FormFieldSignature
: public FormField
{
488 FormFieldSignature(PDFDoc
*docA
, Object
*dict
, const Ref
& ref
, FormField
*parent
, std::set
<int> *usedParents
);
490 virtual ~FormFieldSignature();
493 void print(int indent
= 0);
497 //------------------------------------------------------------------------
499 // This class handle the document-wide part of Form (things in the acroForm
501 //------------------------------------------------------------------------
505 Form(PDFDoc
*docA
, Object
* acroForm
);
509 // Look up an inheritable field dictionary entry.
510 static Object
*fieldLookup(Dict
*field
, const char *key
, Object
*obj
);
512 /* Creates a new Field of the type specified in obj's dict.
513 used in Form::Form and FormField::FormField */
514 static FormField
*createFieldFromDict (Object
* obj
, PDFDoc
*docA
, const Ref
& aref
, FormField
*parent
, std::set
<int> *usedParents
);
516 Object
*getObj () const { return acroForm
; }
517 GBool
getNeedAppearances () const { return needAppearances
; }
518 int getNumFields() const { return numFields
; }
519 FormField
* getRootField(int i
) const { return rootFields
[i
]; }
520 GooString
* getDefaultAppearance() const { return defaultAppearance
; }
521 VariableTextQuadding
getTextQuadding() const { return quadding
; }
522 GfxResources
* getDefaultResources() const { return defaultResources
; }
523 Object
* getDefaultResourcesObj() { return &resDict
; }
525 FormWidget
* findWidgetByRef (Ref aref
);
527 void postWidgetsLoad();
529 FormField
** rootFields
;
535 GBool needAppearances
;
536 GfxResources
*defaultResources
;
540 GooString
*defaultAppearance
;
541 VariableTextQuadding quadding
;
544 //------------------------------------------------------------------------
546 //------------------------------------------------------------------------
548 class FormPageWidgets
{
550 FormPageWidgets (Annots
* annots
, unsigned int page
, Form
*form
);
553 int getNumWidgets() const { return numWidgets
; }
554 FormWidget
* getWidget(int i
) const { return widgets
[i
]; }
557 FormWidget
** widgets
;