From 7ed06731a536f098241a9d6e24157d23482e9a0c Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 7 Nov 2013 00:51:11 -0500 Subject: [PATCH 2/2] glib: Support getting form widget additional actions. Signed-off-by: Elliott Sales de Andrade --- 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), "Field Modified Action:", 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), "Field Format Action:", 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), "Validate Field Action:", 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), "Calculate Field Action:", 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 874cfdb..364ff2b 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -71,6 +71,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.9.0