Add AnnotWidget::setFormAdditionalAction

And the corresponding Form helper

refactor the code that gets the char * from
Annot::FormAdditionalActionsType to a function
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index eb90259..8a0c261 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -232,6 +232,14 @@
   return linkAction;
 }
 
+static const char *getFormAdditionalActionKey(Annot::FormAdditionalActionsType type)
+{
+    return (type == Annot::actionFieldModified ?  "K" :
+            type == Annot::actionFormatField ?    "F" :
+            type == Annot::actionValidateField ?  "V" :
+            type == Annot::actionCalculateField ? "C" : nullptr);
+}
+
 //------------------------------------------------------------------------
 // AnnotBorderEffect
 //------------------------------------------------------------------------
@@ -3777,10 +3785,7 @@
   Object additionalActionsObject = additionalActions.fetch(doc->getXRef());
 
   if (additionalActionsObject.isDict()) {
-    const char *key = (formAdditionalActionType == Annot::actionFieldModified ?  "K" :
-                       formAdditionalActionType == Annot::actionFormatField ?    "F" :
-                       formAdditionalActionType == Annot::actionValidateField ?  "V" :
-                       formAdditionalActionType == Annot::actionCalculateField ? "C" : nullptr);
+    const char *key = getFormAdditionalActionKey(formAdditionalActionType);
 
     Object actionObject = additionalActionsObject.dictLookup(key);
     if (actionObject.isDict())
@@ -3790,6 +3795,29 @@
   return linkAction;
 }
 
+bool AnnotWidget::setFormAdditionalAction(FormAdditionalActionsType formAdditionalActionType, const GooString &js)
+{
+  Object additionalActionsObject = additionalActions.fetch(doc->getXRef());
+
+  if (!additionalActionsObject.isDict()) {
+    additionalActionsObject = Object(new Dict(doc->getXRef()));
+    annotObj.dictSet("AA", additionalActionsObject.copy());
+  }
+
+  additionalActionsObject.dictSet(getFormAdditionalActionKey(formAdditionalActionType),
+                                  LinkJavaScript::createObject(doc->getXRef(), js));
+
+  if (additionalActions.isRef()) {
+    doc->getXRef()->setModifiedObject(&additionalActionsObject, additionalActions.getRef());
+  } else if (hasRef) {
+    doc->getXRef()->setModifiedObject(&annotObj, ref);
+  } else {
+    error(errInternal, -1, "AnnotWidget::setFormAdditionalAction, where neither additionalActions is ref nor annotobj itself is ref");
+    return false;
+  }
+  return true;
+}
+
 // Grand unified handler for preparing text strings to be drawn into form
 // fields.  Takes as input a text string (in PDFDocEncoding or UTF-16).
 // Converts some or all of this string to the appropriate encoding for the
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 96a46c7..88c165f 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -1410,6 +1410,8 @@
   LinkAction *getFormAdditionalAction(FormAdditionalActionsType type); // The caller should delete the result
   Dict *getParent() { return parent; }
 
+  bool setFormAdditionalAction(FormAdditionalActionsType type, const GooString &js);
+
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 3efa6b4..258d235 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -177,6 +177,13 @@
   return widget ? widget->getFormAdditionalAction(t) : nullptr;
 }
 
+bool FormWidget::setAdditionalAction(Annot::FormAdditionalActionsType t, const GooString &js) {
+  if (!widget)
+    return false;
+
+  return widget->setFormAdditionalAction(t, js);
+}
+
 FormWidgetButton::FormWidgetButton (PDFDoc *docA, Object *aobj, unsigned num, Ref refA, FormField *p) :
 	FormWidget(docA, aobj, num, refA, p)
 {
diff --git a/poppler/Form.h b/poppler/Form.h
index 9cc82fc..923b6c8 100644
--- a/poppler/Form.h
+++ b/poppler/Form.h
@@ -6,7 +6,7 @@
 //
 // Copyright 2006 Julien Rebetez <julienr@svn.gnome.org>
 // Copyright 2007, 2008, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
-// Copyright 2007-2010, 2012, 2015-2018 Albert Astals Cid <aacid@kde.org>
+// Copyright 2007-2010, 2012, 2015-2019 Albert Astals Cid <aacid@kde.org>
 // Copyright 2010 Mark Riedesel <mark@klowner.com>
 // Copyright 2011 Pino Toscano <pino@kde.org>
 // Copyright 2012 Fabio D'Urso <fabiodurso@hotmail.it>
@@ -119,6 +119,7 @@
 
   LinkAction *getActivationAction(); // The caller should not delete the result
   LinkAction *getAdditionalAction(Annot::FormAdditionalActionsType type); // The caller should delete the result
+  bool setAdditionalAction(Annot::FormAdditionalActionsType t, const GooString &js);
 
   // return the unique ID corresponding to pageNum/fieldNum
   static int encodeID (unsigned pageNum, unsigned fieldNum);