From a9ee173d2daaae7b020efd66f6c8d4a54606d58a Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Wed, 2 May 2018 16:20:40 +0200 Subject: [PATCH] qt5: Add widget annot actions to FormFields This adds simple API to access AnnotWidget actions which are connected to a FormField. While FormAdditionalActions and Annot::AdditionalActions are something different internally, it is cleaner API to just have a single additionalActions interface. --- qt5/src/poppler-form.cc | 35 ++++++++++++++++++++++++++++++----- qt5/src/poppler-form.h | 10 ++++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc index 7962771b..02ebf357 100644 --- a/qt5/src/poppler-form.cc +++ b/qt5/src/poppler-form.cc @@ -186,18 +186,43 @@ Link* FormField::activationAction() const Link *FormField::additionalAction(AdditionalActionType type) const { - Annot::FormAdditionalActionsType actionType = Annot::actionFieldModified; - switch ( type ) + ::LinkAction *act = nullptr; + if ( type == FieldModified || type == FormatField || type == ValidateField || type == CalculateField ) { + Annot::FormAdditionalActionsType actionType = Annot::actionFieldModified; + switch ( type ) + { case FieldModified: actionType = Annot::actionFieldModified; break; case FormatField: actionType = Annot::actionFormatField; break; case ValidateField: actionType = Annot::actionValidateField; break; case CalculateField: actionType = Annot::actionCalculateField; break; - + default: break; /* not reached */ + } + act = m_formData->fm->getAdditionalAction(actionType); + } + else + { + // Handle the actions of the corresponding widget + ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation(); + if ( !w ) + { + return nullptr; + } + Annot::AdditionalActionsType actionType = Annot::actionMouseReleased; + switch ( type ) + { + case CursorEntering: actionType = Annot::actionCursorEntering; break; + case CursorLeaving: actionType = Annot::actionCursorLeaving; break; + case MousePressed: actionType = Annot::actionMousePressed; break; + case MouseReleased: actionType = Annot::actionMouseReleased; break; + case FocusIn: actionType = Annot::actionFocusIn; break; + case FocusOut: actionType = Annot::actionFocusOut; break; + default: break; /* not reached */ + } + act = w->getAdditionalAction( actionType ); } - Link* action = nullptr; - if (::LinkAction *act = m_formData->fm->getAdditionalAction(actionType)) + if ( act ) { action = PageData::convertLinkActionToLink(act, m_formData->doc, QRectF()); } diff --git a/qt5/src/poppler-form.h b/qt5/src/poppler-form.h index c1d19928..fc14f570 100644 --- a/qt5/src/poppler-form.h +++ b/qt5/src/poppler-form.h @@ -134,8 +134,8 @@ namespace Poppler { */ Link* activationAction() const; - /** - * Describes the flags from the form 'AA' dictionary. + /** + * Describes the additional actions to be executed for this FormField. * * \since 0.53 */ @@ -145,6 +145,12 @@ namespace Poppler { FormatField, ///< A JavaScript action to be performed before the field is formatted to display its value ValidateField, ///< A JavaScript action to be performed when the field value changes CalculateField, ///< A JavaScript action to be performed when the field needs to be recalculated + CursorEntering, ///< To be performed when the cursor enters the field's active area \since 0.65 + CursorLeaving, ///< To be performed when the cursor exists the field's active area \since 0.65 + MousePressed, ///< To be performed when the mouse button is pressed inside the field's active area \since 0.65 + MouseReleased, ///< To be performed when the mouse button is released inside the field's active area \since 0.65 + FocusIn, ///< To be performed when the field receives the input focus \since 0.65 + FocusOut, ///< To be performed when the field loses the input focus \since 0.65 }; /** * Returns a given form additional action -- 2.11.0