[poppler] [PATCH 2/2] glib: Support getting form widget additional actions.

Elliott Sales de Andrade quantum.analyst at gmail.com
Wed Dec 18 21:52:10 PST 2013


Signed-off-by: Elliott Sales de Andrade <quantum.analyst at gmail.com>
---
 glib/demo/forms.c          | 40 ++++++++++++++++++++++++++++++++++
 glib/poppler-form-field.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 glib/poppler-form-field.h  |  9 ++++++++
 glib/poppler-private.h     |  4 ++++
 4 files changed, 107 insertions(+)

diff --git a/glib/demo/forms.c b/glib/demo/forms.c
index fcd5b8b..41cc1fb 100644
--- a/glib/demo/forms.c
+++ b/glib/demo/forms.c
@@ -179,6 +179,46 @@ pgd_form_field_view_set_field (GtkWidget        *field_view,
 		gtk_widget_show (action_view);
 	}
 
+	action = poppler_form_field_get_additional_action (field, POPPLER_ADDITIONAL_ACTION_FIELD_MODIFIED);
+	if (action) {
+		GtkWidget *action_view;
+
+		action_view = pgd_action_view_new (NULL);
+		pgd_action_view_set_action (action_view, action);
+		pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Field Modified Action:</b>", action_view, &row);
+		gtk_widget_show (action_view);
+	}
+
+	action = poppler_form_field_get_additional_action (field, POPPLER_ADDITIONAL_ACTION_FORMAT_FIELD);
+	if (action) {
+		GtkWidget *action_view;
+
+		action_view = pgd_action_view_new (NULL);
+		pgd_action_view_set_action (action_view, action);
+		pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Field Format Action:</b>", action_view, &row);
+		gtk_widget_show (action_view);
+	}
+
+	action = poppler_form_field_get_additional_action (field, POPPLER_ADDITIONAL_ACTION_VALIDATE_FIELD);
+	if (action) {
+		GtkWidget *action_view;
+
+		action_view = pgd_action_view_new (NULL);
+		pgd_action_view_set_action (action_view, action);
+		pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Validate Field Action:</b>", action_view, &row);
+		gtk_widget_show (action_view);
+	}
+
+	action = poppler_form_field_get_additional_action (field, POPPLER_ADDITIONAL_ACTION_CALCULATE_FIELD);
+	if (action) {
+		GtkWidget *action_view;
+
+		action_view = pgd_action_view_new (NULL);
+		pgd_action_view_set_action (action_view, action);
+		pgd_table_add_property_with_custom_widget (GTK_GRID (table), "<b>Calculate Field Action:</b>", action_view, &row);
+		gtk_widget_show (action_view);
+	}
+
 	switch (poppler_form_field_get_field_type (field)) {
 	case POPPLER_FORM_FIELD_BUTTON:
 		enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_FORM_BUTTON_TYPE),
diff --git a/glib/poppler-form-field.cc b/glib/poppler-form-field.cc
index 5687799..809ff61 100644
--- a/glib/poppler-form-field.cc
+++ b/glib/poppler-form-field.cc
@@ -193,6 +193,60 @@ poppler_form_field_get_action (PopplerFormField *field)
   return field->action;
 }
 
+/**
+ * poppler_form_field_get_additional_action:
+ * @field: a #PopplerFormField
+ * @type: the type of additional action
+ *
+ * Retrieves the action (#PopplerAction) that shall be performed when
+ * an additional action is triggered on @field , or %NULL.
+ *
+ * Return value: (transfer none): the action to perform.
+ *
+ * Since: 0.26
+ */
+PopplerAction *
+poppler_form_field_get_additional_action (PopplerFormField           *field,
+					  PopplerAdditionalActionType type)
+{
+  Annot::FormAdditionalActionsType form_action;
+  LinkAction *link_action;
+  PopplerAction **action;
+
+  switch (type)
+  {
+    case POPPLER_ADDITIONAL_ACTION_FIELD_MODIFIED:
+      form_action = Annot::actionFieldModified;
+      action = &field->field_modified_action;
+      break;
+    case POPPLER_ADDITIONAL_ACTION_FORMAT_FIELD:
+      form_action = Annot::actionFormatField;
+      action = &field->format_field_action;
+      break;
+    case POPPLER_ADDITIONAL_ACTION_VALIDATE_FIELD:
+      form_action = Annot::actionValidateField;
+      action = &field->validate_field_action;
+      break;
+    case POPPLER_ADDITIONAL_ACTION_CALCULATE_FIELD:
+      form_action = Annot::actionCalculateField;
+      action = &field->calculate_field_action;
+      break;
+    default:
+      g_return_val_if_reached (NULL);
+  }
+
+  if (*action)
+    return *action;
+
+  link_action = field->widget->getAdditionalAction (form_action);
+  if (!link_action)
+    return NULL;
+
+  *action = _poppler_action_new (NULL, link_action, NULL);
+
+  return *action;
+}
+
 /* Button Field */
 /**
  * poppler_form_field_button_get_button_type:
diff --git a/glib/poppler-form-field.h b/glib/poppler-form-field.h
index 898e0f6..505fdc8 100644
--- a/glib/poppler-form-field.h
+++ b/glib/poppler-form-field.h
@@ -58,6 +58,14 @@ typedef enum
   POPPLER_FORM_CHOICE_LIST
 } PopplerFormChoiceType;
 
+typedef enum
+{
+  POPPLER_ADDITIONAL_ACTION_FIELD_MODIFIED,
+  POPPLER_ADDITIONAL_ACTION_FORMAT_FIELD,
+  POPPLER_ADDITIONAL_ACTION_VALIDATE_FIELD,
+  POPPLER_ADDITIONAL_ACTION_CALCULATE_FIELD
+} PopplerAdditionalActionType;
+
 GType                 poppler_form_field_get_type                (void) G_GNUC_CONST;
 
 PopplerFormFieldType  poppler_form_field_get_field_type          (PopplerFormField *field);
@@ -68,6 +76,7 @@ gchar                *poppler_form_field_get_partial_name        (PopplerFormFie
 gchar                *poppler_form_field_get_mapping_name        (PopplerFormField *field);
 gchar                *poppler_form_field_get_name                (PopplerFormField *field);
 PopplerAction        *poppler_form_field_get_action              (PopplerFormField *field);
+PopplerAction        *poppler_form_field_get_additional_action   (PopplerFormField *field, PopplerAdditionalActionType type);
 
 /* Button Field */
 PopplerFormButtonType poppler_form_field_button_get_button_type  (PopplerFormField *field);
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index 1a1dab9..d86afc8 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -70,6 +70,10 @@ struct _PopplerFormField
   PopplerDocument *document;
   FormWidget *widget;
   PopplerAction *action;
+  PopplerAction *field_modified_action;
+  PopplerAction *format_field_action;
+  PopplerAction *validate_field_action;
+  PopplerAction *calculate_field_action;
 };
 
 struct _PopplerAnnot
-- 
1.8.3.1



More information about the poppler mailing list