Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "fpdfsdk/cpdfsdk_widget.h" |
| 8 | |
| 9 | #include <memory> |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 10 | #include <sstream> |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 11 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 12 | #include "constants/annotation_common.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_array.h" |
| 14 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 15 | #include "core/fpdfapi/parser/cpdf_document.h" |
| 16 | #include "core/fpdfapi/parser/cpdf_reference.h" |
| 17 | #include "core/fpdfapi/parser/cpdf_stream.h" |
| 18 | #include "core/fpdfapi/parser/cpdf_string.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 19 | #include "core/fpdfdoc/cba_fontmap.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 20 | #include "core/fpdfdoc/cpdf_defaultappearance.h" |
| 21 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 22 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 23 | #include "core/fpdfdoc/cpdf_iconfit.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 24 | #include "core/fpdfdoc/cpdf_interactiveform.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 25 | #include "core/fxge/cfx_graphstatedata.h" |
| 26 | #include "core/fxge/cfx_pathdata.h" |
| 27 | #include "core/fxge/cfx_renderdevice.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 28 | #include "fpdfsdk/cpdfsdk_actionhandler.h" |
| 29 | #include "fpdfsdk/cpdfsdk_appstream.h" |
| 30 | #include "fpdfsdk/cpdfsdk_fieldaction.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 32 | #include "fpdfsdk/cpdfsdk_interactiveform.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 33 | #include "fpdfsdk/cpdfsdk_pageview.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 34 | #include "fpdfsdk/pwl/cpwl_edit.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 35 | |
| 36 | #ifdef PDF_ENABLE_XFA |
| 37 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
| 38 | #include "xfa/fxfa/cxfa_eventparam.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 39 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 40 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 41 | #include "xfa/fxfa/cxfa_ffwidgethandler.h" |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 42 | #include "xfa/fxfa/parser/cxfa_node.h" |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 43 | #endif // PDF_ENABLE_XFA |
| 44 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 45 | CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 46 | CPDFSDK_PageView* pPageView, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 47 | CPDFSDK_InteractiveForm* pInteractiveForm) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 48 | : CPDFSDK_BAAnnot(pAnnot, pPageView), |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 49 | m_pInteractiveForm(pInteractiveForm) {} |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 50 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 51 | CPDFSDK_Widget::~CPDFSDK_Widget() = default; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 52 | |
| 53 | #ifdef PDF_ENABLE_XFA |
| 54 | CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 55 | CPDF_Document::Extension* pContext = |
| 56 | m_pPageView->GetFormFillEnv()->GetDocExtension(); |
| 57 | if (!pContext || !pContext->ContainsExtensionForegroundForm()) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 58 | return nullptr; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 59 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 60 | CXFA_FFDocView* pDocView = |
| 61 | static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); |
| 62 | if (!pDocView) |
| 63 | return nullptr; |
| 64 | |
| 65 | WideString sName; |
| 66 | if (GetFieldType() == FormFieldType::kRadioButton) { |
| 67 | sName = GetAnnotName(); |
| 68 | if (sName.IsEmpty()) |
| 69 | sName = GetName(); |
| 70 | } else { |
| 71 | sName = GetName(); |
| 72 | } |
| 73 | |
| 74 | if (sName.IsEmpty()) |
| 75 | return nullptr; |
| 76 | |
| 77 | return pDocView->GetWidgetByName(sName, nullptr); |
| 78 | } |
| 79 | |
| 80 | CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() const { |
| 81 | CPDF_Document::Extension* pContext = |
| 82 | m_pPageView->GetFormFillEnv()->GetDocExtension(); |
| 83 | if (!pContext || !pContext->ContainsExtensionForegroundForm()) |
| 84 | return nullptr; |
| 85 | |
| 86 | CXFA_FFDocView* pDocView = |
| 87 | static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 88 | if (!pDocView) |
| 89 | return nullptr; |
| 90 | |
| 91 | WideString sName = GetName(); |
| 92 | return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 96 | CPDF_Document::Extension* pContext = |
| 97 | m_pPageView->GetFormFillEnv()->GetDocExtension(); |
| 98 | if (!pContext || !pContext->ContainsExtensionForegroundForm()) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 99 | return nullptr; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 100 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 101 | if (!m_pWidgetHandler) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 102 | CXFA_FFDocView* pDocView = |
| 103 | static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 104 | if (pDocView) |
| 105 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
| 106 | } |
| 107 | return m_pWidgetHandler.Get(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 111 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 112 | |
| 113 | switch (eXFAAAT) { |
| 114 | case PDFSDK_XFA_Click: |
| 115 | eEventType = XFA_EVENT_Click; |
| 116 | break; |
| 117 | case PDFSDK_XFA_Full: |
| 118 | eEventType = XFA_EVENT_Full; |
| 119 | break; |
| 120 | case PDFSDK_XFA_PreOpen: |
| 121 | eEventType = XFA_EVENT_PreOpen; |
| 122 | break; |
| 123 | case PDFSDK_XFA_PostOpen: |
| 124 | eEventType = XFA_EVENT_PostOpen; |
| 125 | break; |
| 126 | } |
| 127 | |
| 128 | return eEventType; |
| 129 | } |
| 130 | |
| 131 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
| 132 | bool bWillCommit) { |
| 133 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 134 | |
| 135 | switch (eAAT) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 136 | case CPDF_AAction::kCursorEnter: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 137 | eEventType = XFA_EVENT_MouseEnter; |
| 138 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 139 | case CPDF_AAction::kCursorExit: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 140 | eEventType = XFA_EVENT_MouseExit; |
| 141 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 142 | case CPDF_AAction::kButtonDown: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 143 | eEventType = XFA_EVENT_MouseDown; |
| 144 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 145 | case CPDF_AAction::kButtonUp: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 146 | eEventType = XFA_EVENT_MouseUp; |
| 147 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 148 | case CPDF_AAction::kGetFocus: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 149 | eEventType = XFA_EVENT_Enter; |
| 150 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 151 | case CPDF_AAction::kLoseFocus: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 152 | eEventType = XFA_EVENT_Exit; |
| 153 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 154 | case CPDF_AAction::kPageOpen: |
| 155 | case CPDF_AAction::kPageClose: |
| 156 | case CPDF_AAction::kPageVisible: |
| 157 | case CPDF_AAction::kPageInvisible: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 158 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 159 | case CPDF_AAction::kKeyStroke: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 160 | if (!bWillCommit) |
| 161 | eEventType = XFA_EVENT_Change; |
| 162 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 163 | case CPDF_AAction::kValidate: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 164 | eEventType = XFA_EVENT_Validate; |
| 165 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 166 | case CPDF_AAction::kOpenPage: |
| 167 | case CPDF_AAction::kClosePage: |
| 168 | case CPDF_AAction::kFormat: |
| 169 | case CPDF_AAction::kCalculate: |
| 170 | case CPDF_AAction::kCloseDocument: |
| 171 | case CPDF_AAction::kSaveDocument: |
| 172 | case CPDF_AAction::kDocumentSaved: |
| 173 | case CPDF_AAction::kPrintDocument: |
| 174 | case CPDF_AAction::kDocumentPrinted: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 175 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 176 | case CPDF_AAction::kDocumentOpen: |
| 177 | case CPDF_AAction::kNumberOfActions: |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 178 | NOTREACHED(); |
| 179 | break; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | return eEventType; |
| 183 | } |
| 184 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 185 | bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const { |
| 186 | ObservedPtr<CXFA_FFWidget> pWidget(GetMixXFAWidget()); |
| 187 | if (!pWidget) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 188 | return false; |
| 189 | |
| 190 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 191 | if (!pXFAWidgetHandler) |
| 192 | return false; |
| 193 | |
| 194 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 195 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 196 | GetFieldType() == FormFieldType::kRadioButton) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 197 | CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget(); |
| 198 | if (hGroupWidget && |
| 199 | hGroupWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler)) { |
| 200 | return true; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 204 | // Check |pWidget| again because JS may have destroyed it in the block above. |
| 205 | return pWidget && |
| 206 | pWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 210 | CPDFSDK_FieldAction* data, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 211 | CPDFSDK_PageView* pPageView) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 212 | auto* pContext = static_cast<CPDFXFA_Context*>( |
| 213 | m_pPageView->GetFormFillEnv()->GetDocExtension()); |
| 214 | if (!pContext) |
| 215 | return false; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 216 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 217 | ObservedPtr<CXFA_FFWidget> pWidget(GetMixXFAWidget()); |
| 218 | if (!pWidget) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 219 | return false; |
| 220 | |
| 221 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 222 | if (eEventType == XFA_EVENT_Unknown) |
| 223 | return false; |
| 224 | |
| 225 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 226 | if (!pXFAWidgetHandler) |
| 227 | return false; |
| 228 | |
| 229 | CXFA_EventParam param; |
| 230 | param.m_eType = eEventType; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 231 | param.m_wsChange = data->sChange; |
| 232 | param.m_iCommitKey = 0; |
| 233 | param.m_bShift = data->bShift; |
| 234 | param.m_iSelStart = data->nSelStart; |
| 235 | param.m_iSelEnd = data->nSelEnd; |
| 236 | param.m_wsFullText = data->sValue; |
| 237 | param.m_bKeyDown = data->bKeyDown; |
| 238 | param.m_bModifier = data->bModifier; |
| 239 | param.m_wsPrevText = data->sValue; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 240 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 241 | GetFieldType() == FormFieldType::kRadioButton) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 242 | CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget(); |
| 243 | if (hGroupWidget && |
| 244 | !hGroupWidget->ProcessEventUnderHandler(¶m, pXFAWidgetHandler)) { |
| 245 | return false; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 246 | } |
| 247 | } |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 248 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 249 | // Check |pWidget| again because JS may have destroyed it in the block above. |
| 250 | if (!pWidget) |
| 251 | return false; |
| 252 | |
| 253 | bool ret = pWidget->ProcessEventUnderHandler(¶m, pXFAWidgetHandler); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 254 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
| 255 | pDocView->UpdateDocView(); |
| 256 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 257 | return ret; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) { |
| 261 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 262 | if (!hWidget) |
| 263 | return; |
| 264 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 265 | CXFA_Node* node = hWidget->GetNode(); |
| 266 | if (!node->IsWidgetReady()) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 267 | return; |
| 268 | |
| 269 | CPDF_FormField* pFormField = GetFormField(); |
| 270 | switch (GetFieldType()) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 271 | case FormFieldType::kCheckBox: |
| 272 | case FormFieldType::kRadioButton: { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 273 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 274 | XFA_CHECKSTATE eCheckState = |
| 275 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 276 | node->SetCheckState(eCheckState, true); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 277 | break; |
| 278 | } |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 279 | case FormFieldType::kTextField: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 280 | node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue()); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 281 | break; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 282 | case FormFieldType::kComboBox: |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 283 | case FormFieldType::kListBox: { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 284 | node->ClearAllSelections(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 285 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 286 | for (int i = 0; i < pFormField->CountSelectedItems(); ++i) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 287 | int nIndex = pFormField->GetSelectedIndex(i); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 288 | if (nIndex > -1 && nIndex < node->CountChoiceListItems(false)) |
| 289 | node->SetItemState(nIndex, true, false, false, true); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 290 | } |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 291 | if (GetFieldType() == FormFieldType::kComboBox) |
| 292 | node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue()); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 293 | break; |
| 294 | } |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 295 | default: |
| 296 | break; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 299 | if (bSynchronizeElse) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 300 | auto* context = static_cast<CPDFXFA_Context*>( |
| 301 | m_pPageView->GetFormFillEnv()->GetDocExtension()); |
| 302 | context->GetXFADocView()->ProcessValueChanged(node); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | #endif // PDF_ENABLE_XFA |
| 306 | |
| 307 | bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 308 | const CPDF_Dictionary* pAP = |
| 309 | GetAnnotDict()->GetDictFor(pdfium::annotation::kAP); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 310 | if (!pAP) |
| 311 | return false; |
| 312 | |
| 313 | // Choose the right sub-ap |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 314 | const char* ap_entry = "N"; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 315 | if (mode == CPDF_Annot::Down) |
| 316 | ap_entry = "D"; |
| 317 | else if (mode == CPDF_Annot::Rollover) |
| 318 | ap_entry = "R"; |
| 319 | if (!pAP->KeyExist(ap_entry)) |
| 320 | ap_entry = "N"; |
| 321 | |
| 322 | // Get the AP stream or subdirectory |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 323 | const CPDF_Object* pSub = pAP->GetDirectObjectFor(ap_entry); |
| 324 | if (!pSub) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 325 | return false; |
| 326 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 327 | FormFieldType fieldType = GetFieldType(); |
| 328 | switch (fieldType) { |
| 329 | case FormFieldType::kPushButton: |
| 330 | case FormFieldType::kComboBox: |
| 331 | case FormFieldType::kListBox: |
| 332 | case FormFieldType::kTextField: |
| 333 | case FormFieldType::kSignature: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 334 | return pSub->IsStream(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 335 | case FormFieldType::kCheckBox: |
| 336 | case FormFieldType::kRadioButton: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 337 | if (const CPDF_Dictionary* pSubDict = pSub->AsDictionary()) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 338 | return !!pSubDict->GetStreamFor(GetAppState()); |
| 339 | } |
| 340 | return false; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 341 | default: |
| 342 | return true; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 343 | } |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 346 | FormFieldType CPDFSDK_Widget::GetFieldType() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 347 | CPDF_FormField* pField = GetFormField(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 348 | return pField ? pField->GetFieldType() : FormFieldType::kUnknown; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | bool CPDFSDK_Widget::IsAppearanceValid() { |
| 352 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 353 | CPDF_Document::Extension* pContext = |
| 354 | m_pPageView->GetFormFillEnv()->GetDocExtension(); |
| 355 | if (pContext && pContext->ContainsExtensionFullForm()) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 356 | return true; |
| 357 | #endif // PDF_ENABLE_XFA |
| 358 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
| 359 | } |
| 360 | |
| 361 | int CPDFSDK_Widget::GetLayoutOrder() const { |
| 362 | return 2; |
| 363 | } |
| 364 | |
| 365 | int CPDFSDK_Widget::GetFieldFlags() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 366 | return GetFormField()->GetFieldFlags(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | bool CPDFSDK_Widget::IsSignatureWidget() const { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 370 | return GetFieldType() == FormFieldType::kSignature; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
| 374 | CPDF_FormControl* pControl = GetFormControl(); |
| 375 | return pControl ? pControl->GetField() : nullptr; |
| 376 | } |
| 377 | |
| 378 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 379 | CPDF_InteractiveForm* pPDFInteractiveForm = |
| 380 | m_pInteractiveForm->GetInteractiveForm(); |
| 381 | return pPDFInteractiveForm->GetControlByDict(GetAnnotDict()); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | int CPDFSDK_Widget::GetRotate() const { |
| 385 | CPDF_FormControl* pCtrl = GetFormControl(); |
| 386 | return pCtrl->GetRotation() % 360; |
| 387 | } |
| 388 | |
| 389 | #ifdef PDF_ENABLE_XFA |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 390 | WideString CPDFSDK_Widget::GetName() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 391 | return GetFormField()->GetFullName(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 392 | } |
| 393 | #endif // PDF_ENABLE_XFA |
| 394 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 395 | Optional<FX_COLORREF> CPDFSDK_Widget::GetFillColor() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 396 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 397 | int iColorType = 0; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 398 | FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBackgroundColor(iColorType)); |
| 399 | if (iColorType == CFX_Color::kTransparent) |
| 400 | return {}; |
| 401 | return color; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 404 | Optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 405 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 406 | int iColorType = 0; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 407 | FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBorderColor(iColorType)); |
| 408 | if (iColorType == CFX_Color::kTransparent) |
| 409 | return {}; |
| 410 | return color; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 413 | Optional<FX_COLORREF> CPDFSDK_Widget::GetTextColor() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 414 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 415 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 416 | FX_ARGB argb; |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 417 | Optional<CFX_Color::Type> iColorType; |
| 418 | std::tie(iColorType, argb) = da.GetColor(); |
| 419 | if (!iColorType.has_value()) |
| 420 | return {}; |
| 421 | |
| 422 | FX_COLORREF color = ArgbToColorRef(argb); |
| 423 | if (iColorType.value() == CFX_Color::kTransparent) |
| 424 | return {}; |
| 425 | return color; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 428 | float CPDFSDK_Widget::GetFontSize() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 429 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 430 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 431 | float fFontSize; |
| 432 | pDa.GetFont(&fFontSize); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 433 | return fFontSize; |
| 434 | } |
| 435 | |
| 436 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
| 437 | #ifdef PDF_ENABLE_XFA |
| 438 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 439 | CXFA_Node* node = hWidget->GetNode(); |
| 440 | if (node->IsWidgetReady()) { |
| 441 | if (nIndex < node->CountSelectedItems()) |
| 442 | return node->GetSelectedItem(nIndex); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | #endif // PDF_ENABLE_XFA |
| 446 | CPDF_FormField* pFormField = GetFormField(); |
| 447 | return pFormField->GetSelectedIndex(nIndex); |
| 448 | } |
| 449 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 450 | WideString CPDFSDK_Widget::GetValue() const { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 451 | #ifdef PDF_ENABLE_XFA |
| 452 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 453 | CXFA_Node* node = hWidget->GetNode(); |
| 454 | if (node->IsWidgetReady()) |
| 455 | return node->GetValue(XFA_VALUEPICTURE_Display); |
| 456 | } |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 457 | #endif // PDF_ENABLE_XFA |
| 458 | CPDF_FormField* pFormField = GetFormField(); |
| 459 | return pFormField->GetValue(); |
| 460 | } |
| 461 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 462 | WideString CPDFSDK_Widget::GetDefaultValue() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 463 | CPDF_FormField* pFormField = GetFormField(); |
| 464 | return pFormField->GetDefaultValue(); |
| 465 | } |
| 466 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 467 | WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 468 | CPDF_FormField* pFormField = GetFormField(); |
| 469 | return pFormField->GetOptionLabel(nIndex); |
| 470 | } |
| 471 | |
| 472 | int CPDFSDK_Widget::CountOptions() const { |
| 473 | CPDF_FormField* pFormField = GetFormField(); |
| 474 | return pFormField->CountOptions(); |
| 475 | } |
| 476 | |
| 477 | bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
| 478 | #ifdef PDF_ENABLE_XFA |
| 479 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 480 | CXFA_Node* node = hWidget->GetNode(); |
| 481 | if (node->IsWidgetReady()) { |
| 482 | if (nIndex > -1 && nIndex < node->CountChoiceListItems(false)) |
| 483 | return node->GetItemState(nIndex); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 484 | |
| 485 | return false; |
| 486 | } |
| 487 | } |
| 488 | #endif // PDF_ENABLE_XFA |
| 489 | CPDF_FormField* pFormField = GetFormField(); |
| 490 | return pFormField->IsItemSelected(nIndex); |
| 491 | } |
| 492 | |
| 493 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 494 | CPDF_FormField* pFormField = GetFormField(); |
| 495 | return pFormField->GetTopVisibleIndex(); |
| 496 | } |
| 497 | |
| 498 | bool CPDFSDK_Widget::IsChecked() const { |
| 499 | #ifdef PDF_ENABLE_XFA |
| 500 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 501 | CXFA_Node* node = hWidget->GetNode(); |
| 502 | if (node->IsWidgetReady()) |
| 503 | return node->GetCheckState() == XFA_CHECKSTATE_On; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 504 | } |
| 505 | #endif // PDF_ENABLE_XFA |
| 506 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 507 | return pFormCtrl->IsChecked(); |
| 508 | } |
| 509 | |
| 510 | int CPDFSDK_Widget::GetAlignment() const { |
| 511 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 512 | return pFormCtrl->GetControlAlignment(); |
| 513 | } |
| 514 | |
| 515 | int CPDFSDK_Widget::GetMaxLen() const { |
| 516 | CPDF_FormField* pFormField = GetFormField(); |
| 517 | return pFormField->GetMaxLen(); |
| 518 | } |
| 519 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 520 | void CPDFSDK_Widget::SetCheck(bool bChecked, NotificationOption notify) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 521 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 522 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
| 523 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 524 | notify); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 525 | #ifdef PDF_ENABLE_XFA |
| 526 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 527 | ResetXFAAppearance(true); |
| 528 | if (notify == NotificationOption::kDoNotNotify) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 529 | Synchronize(true); |
| 530 | #endif // PDF_ENABLE_XFA |
| 531 | } |
| 532 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 533 | void CPDFSDK_Widget::SetValue(const WideString& sValue, |
| 534 | NotificationOption notify) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 535 | CPDF_FormField* pFormField = GetFormField(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 536 | pFormField->SetValue(sValue, notify); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 537 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 538 | if (notify == NotificationOption::kDoNotNotify) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 539 | Synchronize(true); |
| 540 | #endif // PDF_ENABLE_XFA |
| 541 | } |
| 542 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 543 | void CPDFSDK_Widget::SetOptionSelection(int index, |
| 544 | bool bSelected, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 545 | NotificationOption notify) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 546 | CPDF_FormField* pFormField = GetFormField(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 547 | pFormField->SetItemSelection(index, bSelected, notify); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 548 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 549 | if (notify == NotificationOption::kDoNotNotify) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 550 | Synchronize(true); |
| 551 | #endif // PDF_ENABLE_XFA |
| 552 | } |
| 553 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 554 | void CPDFSDK_Widget::ClearSelection(NotificationOption notify) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 555 | CPDF_FormField* pFormField = GetFormField(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 556 | pFormField->ClearSelection(notify); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 557 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 558 | if (notify == NotificationOption::kDoNotNotify) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 559 | Synchronize(true); |
| 560 | #endif // PDF_ENABLE_XFA |
| 561 | } |
| 562 | |
| 563 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 564 | |
| 565 | void CPDFSDK_Widget::SetAppModified() { |
| 566 | m_bAppModified = true; |
| 567 | } |
| 568 | |
| 569 | void CPDFSDK_Widget::ClearAppModified() { |
| 570 | m_bAppModified = false; |
| 571 | } |
| 572 | |
| 573 | bool CPDFSDK_Widget::IsAppModified() const { |
| 574 | return m_bAppModified; |
| 575 | } |
| 576 | |
| 577 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 578 | void CPDFSDK_Widget::ResetXFAAppearance(bool bValueChanged) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 579 | switch (GetFieldType()) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 580 | case FormFieldType::kTextField: |
| 581 | case FormFieldType::kComboBox: { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 582 | ResetAppearance(OnFormat(), true); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 583 | break; |
| 584 | } |
| 585 | default: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 586 | ResetAppearance(pdfium::nullopt, false); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 587 | break; |
| 588 | } |
| 589 | } |
| 590 | #endif // PDF_ENABLE_XFA |
| 591 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 592 | void CPDFSDK_Widget::ResetAppearance(Optional<WideString> sValue, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 593 | bool bValueChanged) { |
| 594 | SetAppModified(); |
| 595 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 596 | m_nAppearanceAge++; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 597 | if (bValueChanged) |
| 598 | m_nValueAge++; |
| 599 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 600 | CPDFSDK_AppStream appStream(this, GetAPDict()); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 601 | switch (GetFieldType()) { |
| 602 | case FormFieldType::kPushButton: |
| 603 | appStream.SetAsPushButton(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 604 | break; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 605 | case FormFieldType::kCheckBox: |
| 606 | appStream.SetAsCheckBox(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 607 | break; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 608 | case FormFieldType::kRadioButton: |
| 609 | appStream.SetAsRadioButton(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 610 | break; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 611 | case FormFieldType::kComboBox: |
| 612 | appStream.SetAsComboBox(sValue); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 613 | break; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 614 | case FormFieldType::kListBox: |
| 615 | appStream.SetAsListBox(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 616 | break; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 617 | case FormFieldType::kTextField: |
| 618 | appStream.SetAsTextField(sValue); |
| 619 | break; |
| 620 | default: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 621 | break; |
| 622 | } |
| 623 | |
| 624 | m_pAnnot->ClearCachedAP(); |
| 625 | } |
| 626 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 627 | Optional<WideString> CPDFSDK_Widget::OnFormat() { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 628 | CPDF_FormField* pFormField = GetFormField(); |
| 629 | ASSERT(pFormField); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 630 | return m_pInteractiveForm->OnFormat(pFormField); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 633 | void CPDFSDK_Widget::ResetFieldAppearance() { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 634 | CPDF_FormField* pFormField = GetFormField(); |
| 635 | ASSERT(pFormField); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 636 | m_pInteractiveForm->ResetFieldAppearance(pFormField, pdfium::nullopt); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 640 | const CFX_Matrix& mtUser2Device, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 641 | CPDF_Annot::AppearanceMode mode, |
| 642 | const CPDF_RenderOptions* pOptions) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 643 | FormFieldType fieldType = GetFieldType(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 644 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 645 | if ((fieldType == FormFieldType::kCheckBox || |
| 646 | fieldType == FormFieldType::kRadioButton) && |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 647 | mode == CPDF_Annot::Normal && |
| 648 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 649 | CFX_GraphStateData gsd; |
| 650 | gsd.m_LineWidth = 0.0f; |
| 651 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 652 | CFX_PathData pathData; |
| 653 | pathData.AppendFloatRect(GetRect()); |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 654 | pDevice->DrawPath(&pathData, &mtUser2Device, &gsd, 0, 0xFFAAAAAA, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 655 | FXFILL_ALTERNATE); |
| 656 | } else { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 657 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode, pOptions); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
| 661 | void CPDFSDK_Widget::UpdateField() { |
| 662 | CPDF_FormField* pFormField = GetFormField(); |
| 663 | ASSERT(pFormField); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 664 | m_pInteractiveForm->UpdateField(pFormField); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 668 | CPDFSDK_PageView* pPageView) { |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 669 | FormFieldType fieldType = GetFieldType(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 670 | if (!m_pInteractiveForm->IsNeedHighLight(fieldType)) |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 671 | return; |
| 672 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 673 | CFX_Matrix page2device = pPageView->GetCurrentMatrix(); |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 674 | CFX_FloatRect rcDevice = GetRect(); |
| 675 | CFX_PointF tmp = |
| 676 | page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom)); |
| 677 | rcDevice.left = tmp.x; |
| 678 | rcDevice.bottom = tmp.y; |
| 679 | |
| 680 | tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top)); |
| 681 | rcDevice.right = tmp.x; |
| 682 | rcDevice.top = tmp.y; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 683 | rcDevice.Normalize(); |
| 684 | |
Philip P. Moltmann | 33357ca | 2017-05-11 09:25:13 -0700 | [diff] [blame] | 685 | pDevice->FillRect( |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 686 | rcDevice.ToFxRect(), |
| 687 | AlphaAndColorRefToArgb( |
| 688 | static_cast<int>(m_pInteractiveForm->GetHighlightAlpha()), |
| 689 | m_pInteractiveForm->GetHighlightColor(fieldType))); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 693 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 694 | float fBorderWidth = GetBorderWidth(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 695 | switch (GetBorderStyle()) { |
| 696 | case BorderStyle::BEVELED: |
| 697 | case BorderStyle::INSET: |
| 698 | fBorderWidth *= 2.0f; |
| 699 | break; |
| 700 | default: |
| 701 | break; |
| 702 | } |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 703 | return rcWindow.GetDeflated(fBorderWidth, fBorderWidth); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 707 | CFX_FloatRect rectAnnot = GetRect(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 708 | float fWidth = rectAnnot.Width(); |
| 709 | float fHeight = rectAnnot.Height(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 710 | |
| 711 | CPDF_FormControl* pControl = GetFormControl(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 712 | CFX_FloatRect rcPWLWindow; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 713 | switch (abs(pControl->GetRotation() % 360)) { |
| 714 | case 0: |
| 715 | case 180: |
| 716 | default: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 717 | rcPWLWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 718 | break; |
| 719 | case 90: |
| 720 | case 270: |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 721 | rcPWLWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 722 | break; |
| 723 | } |
| 724 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 725 | return rcPWLWindow; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 728 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 729 | CFX_Matrix mt; |
| 730 | CPDF_FormControl* pControl = GetFormControl(); |
| 731 | CFX_FloatRect rcAnnot = GetRect(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 732 | float fWidth = rcAnnot.Width(); |
| 733 | float fHeight = rcAnnot.Height(); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 734 | |
| 735 | switch (abs(pControl->GetRotation() % 360)) { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 736 | default: |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 737 | case 0: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 738 | break; |
| 739 | case 90: |
| 740 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
| 741 | break; |
| 742 | case 180: |
| 743 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
| 744 | break; |
| 745 | case 270: |
| 746 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | return mt; |
| 751 | } |
| 752 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 753 | CFX_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 754 | CFX_Color crText = CFX_Color(CFX_Color::kGray, 0); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 755 | |
| 756 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 757 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 758 | |
| 759 | float fc[4]; |
| 760 | Optional<CFX_Color::Type> iColorType = da.GetColor(fc); |
| 761 | if (iColorType) |
| 762 | crText = CFX_Color(*iColorType, fc[0], fc[1], fc[2], fc[3]); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 763 | |
| 764 | return crText; |
| 765 | } |
| 766 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 767 | CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 768 | CFX_Color crBorder; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 769 | |
| 770 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 771 | int32_t iColorType; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 772 | float fc[4]; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 773 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 774 | if (iColorType > 0) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 775 | crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 776 | |
| 777 | return crBorder; |
| 778 | } |
| 779 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 780 | CFX_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 781 | CFX_Color crFill; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 782 | |
| 783 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 784 | int32_t iColorType; |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 785 | float fc[4]; |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 786 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 787 | if (iColorType > 0) |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 788 | crFill = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 789 | |
| 790 | return crFill; |
| 791 | } |
| 792 | |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 793 | bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 794 | CPDFSDK_FieldAction* data, |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 795 | CPDFSDK_PageView* pPageView) { |
| 796 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
| 797 | |
| 798 | #ifdef PDF_ENABLE_XFA |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 799 | auto* pContext = |
| 800 | static_cast<CPDFXFA_Context*>(pFormFillEnv->GetDocExtension()); |
| 801 | if (pContext) { |
| 802 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 803 | if (hWidget) { |
| 804 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data->bWillCommit); |
| 805 | if (eEventType != XFA_EVENT_Unknown) { |
| 806 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
| 807 | CXFA_EventParam param; |
| 808 | param.m_eType = eEventType; |
| 809 | param.m_wsChange = data->sChange; |
| 810 | param.m_iCommitKey = 0; |
| 811 | param.m_bShift = data->bShift; |
| 812 | param.m_iSelStart = data->nSelStart; |
| 813 | param.m_iSelEnd = data->nSelEnd; |
| 814 | param.m_wsFullText = data->sValue; |
| 815 | param.m_bKeyDown = data->bKeyDown; |
| 816 | param.m_bModifier = data->bModifier; |
| 817 | param.m_wsPrevText = data->sValue; |
| 818 | bool ret = |
| 819 | hWidget->ProcessEventUnderHandler(¶m, pXFAWidgetHandler); |
| 820 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
| 821 | pDocView->UpdateDocView(); |
| 822 | if (ret) |
| 823 | return true; |
| 824 | } |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | } |
| 828 | #endif // PDF_ENABLE_XFA |
| 829 | |
| 830 | CPDF_Action action = GetAAction(type); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 831 | if (action.GetType() != CPDF_Action::Unknown) { |
| 832 | pFormFillEnv->GetActionHandler()->DoAction_Field(action, type, pFormFillEnv, |
| 833 | GetFormField(), data); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 834 | } |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 839 | switch (eAAT) { |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 840 | case CPDF_AAction::kCursorEnter: |
| 841 | case CPDF_AAction::kCursorExit: |
| 842 | case CPDF_AAction::kButtonDown: |
| 843 | case CPDF_AAction::kButtonUp: |
| 844 | case CPDF_AAction::kGetFocus: |
| 845 | case CPDF_AAction::kLoseFocus: |
| 846 | case CPDF_AAction::kPageOpen: |
| 847 | case CPDF_AAction::kPageClose: |
| 848 | case CPDF_AAction::kPageVisible: |
| 849 | case CPDF_AAction::kPageInvisible: |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 850 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 851 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame^] | 852 | case CPDF_AAction::kKeyStroke: |
| 853 | case CPDF_AAction::kFormat: |
| 854 | case CPDF_AAction::kValidate: |
| 855 | case CPDF_AAction::kCalculate: { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 856 | CPDF_FormField* pField = GetFormField(); |
| 857 | if (pField->GetAdditionalAction().GetDict()) |
| 858 | return pField->GetAdditionalAction().GetAction(eAAT); |
| 859 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 860 | } |
| 861 | default: |
| 862 | break; |
| 863 | } |
| 864 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 865 | return CPDF_Action(nullptr); |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Philip P. Moltmann | d904c1e | 2018-03-19 09:26:45 -0700 | [diff] [blame] | 868 | WideString CPDFSDK_Widget::GetAlternateName() const { |
Philip P. Moltmann | 4d3acf4 | 2017-03-20 11:05:52 -0700 | [diff] [blame] | 869 | CPDF_FormField* pFormField = GetFormField(); |
| 870 | return pFormField->GetAlternateName(); |
| 871 | } |