Commit 0582ea96 authored by Marek Kasik's avatar Marek Kasik Committed by Albert Astals Cid

Add support for ResetForm action

Add ability to reset FormField class, its descendants and Form class. This takes hierarchy into account so that resetting a field resets also its children. If exclude flag is specified then all fields are reset except those which are listed in Fields key.

FormFieldText set DV key as its V key if DV is available. Otherwise, it just removes the V key.

FormFieldChoice unselect selected items and set the default ones if specified.

FormFieldButton set default apearance state if it is available, otherwise it just removes V key (and set the state to "Off" if it is check button, which is what Adobe Reader does in this situation).

FormFieldSignature is not reset.

Add LinkResetForm class which stores information needed for resetting of fields of forms.

Issue #225
parent 62727d01
This diff is collapsed.
......@@ -21,6 +21,7 @@
// Copyright 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright 2019 João Netto <joaonetto901@gmail.com>
// Copyright 2020 Nelson Benítez León <nbenitezl@gmail.com>
// Copyright 2020 Marek Kasik <mkasik@redhat.com>
//
//========================================================================
......@@ -73,6 +74,11 @@ enum FormSignatureType {
ETSI_CAdES_detached
};
enum FillValueType {
fillValue,
fillDefaultValue
};
class Form;
class FormField;
class FormFieldButton;
......@@ -330,11 +336,16 @@ public:
void printTree(int indent = 0);
virtual void print(int indent = 0);
virtual void reset(const std::vector<std::string>& excludedFields);
void resetChildren(const std::vector<std::string>& excludedFields);
FormField* findFieldByRef(Ref aref);
FormField* findFieldByFullyQualifiedName(const std::string &name);
protected:
void _createWidget (Object *obj, Ref aref);
void createChildren(std::set<int> *usedParents);
void updateChildrenAppearance();
bool isAmongExcludedFields(const std::vector<std::string>& excludedFields);
FormFieldType type; // field type
Ref ref;
......@@ -383,6 +394,7 @@ public:
bool getState(const char *state) const;
const char *getAppearanceState() const { return appearanceState.isName() ? appearanceState.getName() : nullptr; }
const char *getDefaultAppearanceState() const { return defaultAppearanceState.isName() ? defaultAppearanceState.getName() : nullptr; }
void fillChildrenSiblingsID () override;
......@@ -394,6 +406,7 @@ public:
int getNumSiblings () const { return numSiblings; }
void print(int indent) override;
void reset(const std::vector<std::string>& excludedFields) override;
~FormFieldButton() override;
protected:
......@@ -408,6 +421,7 @@ protected:
int active_child; //only used for combo box
bool noAllOff;
Object appearanceState; // V
Object defaultAppearanceState; // DV
};
//------------------------------------------------------------------------
......@@ -440,14 +454,17 @@ public:
void setTextFontSize(int fontSize);
void print(int indent) override;
void reset(const std::vector<std::string>& excludedFields) override;
static int tokenizeDA(const GooString* daString, std::vector<GooString*>* daToks, const char* searchTok);
protected:
int parseDA(std::vector<GooString*>* daToks);
void fillContent(FillValueType fillType);
GooString* content;
GooString* internalContent;
GooString* defaultContent;
bool multiline;
bool password;
bool fileSelect;
......@@ -502,10 +519,12 @@ public:
int getTopIndex() const { return topIdx; }
void print(int indent) override;
void reset(const std::vector<std::string>& excludedFields) override;
protected:
void unselectAll();
void updateSelection();
void fillChoices(FillValueType fillType);
bool combo;
bool edit;
......@@ -521,6 +540,7 @@ protected:
int numChoices;
ChoiceOpt* choices;
bool* defaultChoices;
GooString* editedChoice;
int topIdx; // TI
};
......@@ -595,11 +615,15 @@ public:
Object* getDefaultResourcesObj() { return &resDict; }
FormWidget* findWidgetByRef (Ref aref);
FormField* findFieldByRef(Ref aref) const;
FormField* findFieldByFullyQualifiedName(const std::string &name) const;
void postWidgetsLoad();
const std::vector<Ref> &getCalculateOrder() const { return calculateOrder; }
void reset(const std::vector<std::string>& fields, bool excludeFields);
private:
FormField** rootFields;
int numFields;
......
......@@ -24,6 +24,7 @@
// Copyright (C) 2018 Intevation GmbH <intevation@intevation.de>
// Copyright (C) 2018, 2020 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2020 Marek Kasik <mkasik@redhat.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -129,6 +130,10 @@ std::unique_ptr<LinkAction> LinkAction::parseAction(const Object *obj, const Goo
} else if (obj2.isName("Hide")) {
action = std::make_unique<LinkHide>(obj);
// ResetForm action
} else if (obj2.isName("ResetForm")) {
action = std::make_unique<LinkResetForm>(obj);
// unknown action
} else if (obj2.isName()) {
action = std::make_unique<LinkUnknown>(obj2.getName());
......@@ -832,6 +837,42 @@ LinkHide::LinkHide(const Object *hideObj) {
LinkHide::~LinkHide() = default;
//------------------------------------------------------------------------
// LinkResetForm
//------------------------------------------------------------------------
LinkResetForm::LinkResetForm(const Object *obj) {
Object obj1;
exclude = false;
obj1 = obj->dictLookup("Fields");
if (obj1.isArray()) {
fields.resize(obj1.arrayGetLength());
for (int i = 0; i < obj1.arrayGetLength(); ++i) {
const Object &obj2 = obj1.arrayGetNF(i);
if (obj2.isName())
fields[i] = std::string (obj2.getName ());
else if (obj2.isRef()) {
fields[i] = std::to_string(obj2.getRef().num);
fields[i].append(" ");
fields[i].append(std::to_string(obj2.getRef().gen));
fields[i].append(" R");
}
}
}
obj1 = obj->dictLookup("Flags");
if (obj1.isInt()) {
int flags = obj1.getInt();
if (flags & 0x1)
exclude = true;
}
}
LinkResetForm::~LinkResetForm() = default;
//------------------------------------------------------------------------
// LinkUnknown
//------------------------------------------------------------------------
......
......@@ -22,6 +22,7 @@
// Copyright (C) 2018 Intevation GmbH <intevation@intevation.de>
// Copyright (C) 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2020 Adam Reichold <adam.reichold@t-online.de>
// Copyright (C) 2020 Marek Kasik <mkasik@redhat.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -59,6 +60,7 @@ enum LinkActionKind {
actionJavaScript, // JavaScript action
actionOCGState, // Set-OCG-State action
actionHide, // Hide action
actionResetForm, // ResetForm action
actionUnknown // anything else
};
......@@ -491,6 +493,32 @@ private:
bool show;
};
//------------------------------------------------------------------------
// LinkResetForm
//------------------------------------------------------------------------
class LinkResetForm: public LinkAction {
public:
// Build a LinkResetForm.
LinkResetForm(const Object *nameObj);
~LinkResetForm() override;
bool isOk() const override { return true; }
LinkActionKind getKind() const override { return actionResetForm; }
const std::vector<std::string>& getFields() const { return fields; }
bool getExclude() const { return exclude; }
private:
std::vector<std::string> fields;
bool exclude;
};
//------------------------------------------------------------------------
// LinkUnknown
//------------------------------------------------------------------------
......
......@@ -355,6 +355,10 @@ Link* PageData::convertLinkActionToLink(::LinkAction * a, DocumentData *parentDo
}
break;
case actionResetForm:
// Not handled in Qt5 front-end yet
break;
case actionUnknown:
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment