blob: 6d92b74b5fc50e87c9b7be761bcc701969f94a0a [file] [log] [blame]
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -07001// 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. Moltmannd904c1e2018-03-19 09:26:45 -070010#include <sstream>
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070011
Haibo Huang49cc9302020-04-27 16:14:24 -070012#include "constants/annotation_common.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070013#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 Huang49cc9302020-04-27 16:14:24 -070019#include "core/fpdfdoc/cba_fontmap.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070020#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 Huang49cc9302020-04-27 16:14:24 -070024#include "core/fpdfdoc/cpdf_interactiveform.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070025#include "core/fxge/cfx_graphstatedata.h"
26#include "core/fxge/cfx_pathdata.h"
27#include "core/fxge/cfx_renderdevice.h"
Haibo Huang49cc9302020-04-27 16:14:24 -070028#include "fpdfsdk/cpdfsdk_actionhandler.h"
29#include "fpdfsdk/cpdfsdk_appstream.h"
30#include "fpdfsdk/cpdfsdk_fieldaction.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070031#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
Haibo Huang49cc9302020-04-27 16:14:24 -070032#include "fpdfsdk/cpdfsdk_interactiveform.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070033#include "fpdfsdk/cpdfsdk_pageview.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070034#include "fpdfsdk/pwl/cpwl_edit.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070035
36#ifdef PDF_ENABLE_XFA
37#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
38#include "xfa/fxfa/cxfa_eventparam.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070039#include "xfa/fxfa/cxfa_ffdocview.h"
40#include "xfa/fxfa/cxfa_ffwidget.h"
41#include "xfa/fxfa/cxfa_ffwidgethandler.h"
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070042#include "xfa/fxfa/parser/cxfa_node.h"
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070043#endif // PDF_ENABLE_XFA
44
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070045CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
46 CPDFSDK_PageView* pPageView,
Haibo Huang49cc9302020-04-27 16:14:24 -070047 CPDFSDK_InteractiveForm* pInteractiveForm)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070048 : CPDFSDK_BAAnnot(pAnnot, pPageView),
Haibo Huang49cc9302020-04-27 16:14:24 -070049 m_pInteractiveForm(pInteractiveForm) {}
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070050
Haibo Huang49cc9302020-04-27 16:14:24 -070051CPDFSDK_Widget::~CPDFSDK_Widget() = default;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070052
53#ifdef PDF_ENABLE_XFA
54CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
Haibo Huang49cc9302020-04-27 16:14:24 -070055 CPDF_Document::Extension* pContext =
56 m_pPageView->GetFormFillEnv()->GetDocExtension();
57 if (!pContext || !pContext->ContainsExtensionForegroundForm())
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070058 return nullptr;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070059
Haibo Huang49cc9302020-04-27 16:14:24 -070060 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
80CXFA_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. Moltmannd904c1e2018-03-19 09:26:45 -070088 if (!pDocView)
89 return nullptr;
90
91 WideString sName = GetName();
92 return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -070093}
94
95CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
Haibo Huang49cc9302020-04-27 16:14:24 -070096 CPDF_Document::Extension* pContext =
97 m_pPageView->GetFormFillEnv()->GetDocExtension();
98 if (!pContext || !pContext->ContainsExtensionForegroundForm())
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -070099 return nullptr;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700100
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700101 if (!m_pWidgetHandler) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700102 CXFA_FFDocView* pDocView =
103 static_cast<CPDFXFA_Context*>(pContext)->GetXFADocView();
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700104 if (pDocView)
105 m_pWidgetHandler = pDocView->GetWidgetHandler();
106 }
107 return m_pWidgetHandler.Get();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700108}
109
110static 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
131static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
132 bool bWillCommit) {
133 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
134
135 switch (eAAT) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700136 case CPDF_AAction::kCursorEnter:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700137 eEventType = XFA_EVENT_MouseEnter;
138 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700139 case CPDF_AAction::kCursorExit:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700140 eEventType = XFA_EVENT_MouseExit;
141 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700142 case CPDF_AAction::kButtonDown:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700143 eEventType = XFA_EVENT_MouseDown;
144 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700145 case CPDF_AAction::kButtonUp:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700146 eEventType = XFA_EVENT_MouseUp;
147 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700148 case CPDF_AAction::kGetFocus:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700149 eEventType = XFA_EVENT_Enter;
150 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700151 case CPDF_AAction::kLoseFocus:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700152 eEventType = XFA_EVENT_Exit;
153 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700154 case CPDF_AAction::kPageOpen:
155 case CPDF_AAction::kPageClose:
156 case CPDF_AAction::kPageVisible:
157 case CPDF_AAction::kPageInvisible:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700158 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700159 case CPDF_AAction::kKeyStroke:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700160 if (!bWillCommit)
161 eEventType = XFA_EVENT_Change;
162 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700163 case CPDF_AAction::kValidate:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700164 eEventType = XFA_EVENT_Validate;
165 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700166 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. Moltmann4d3acf42017-03-20 11:05:52 -0700175 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700176 case CPDF_AAction::kDocumentOpen:
177 case CPDF_AAction::kNumberOfActions:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700178 NOTREACHED();
179 break;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700180 }
181
182 return eEventType;
183}
184
Haibo Huang49cc9302020-04-27 16:14:24 -0700185bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) const {
186 ObservedPtr<CXFA_FFWidget> pWidget(GetMixXFAWidget());
187 if (!pWidget)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700188 return false;
189
190 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
191 if (!pXFAWidgetHandler)
192 return false;
193
194 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700195 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700196 GetFieldType() == FormFieldType::kRadioButton) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700197 CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget();
198 if (hGroupWidget &&
199 hGroupWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler)) {
200 return true;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700201 }
202 }
203
Haibo Huang49cc9302020-04-27 16:14:24 -0700204 // Check |pWidget| again because JS may have destroyed it in the block above.
205 return pWidget &&
206 pWidget->HasEventUnderHandler(eEventType, pXFAWidgetHandler);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700207}
208
209bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
Haibo Huang49cc9302020-04-27 16:14:24 -0700210 CPDFSDK_FieldAction* data,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700211 CPDFSDK_PageView* pPageView) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700212 auto* pContext = static_cast<CPDFXFA_Context*>(
213 m_pPageView->GetFormFillEnv()->GetDocExtension());
214 if (!pContext)
215 return false;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700216
Haibo Huang49cc9302020-04-27 16:14:24 -0700217 ObservedPtr<CXFA_FFWidget> pWidget(GetMixXFAWidget());
218 if (!pWidget)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700219 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 Huang49cc9302020-04-27 16:14:24 -0700231 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. Moltmann4d3acf42017-03-20 11:05:52 -0700240 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700241 GetFieldType() == FormFieldType::kRadioButton) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700242 CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget();
243 if (hGroupWidget &&
244 !hGroupWidget->ProcessEventUnderHandler(&param, pXFAWidgetHandler)) {
245 return false;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700246 }
247 }
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700248
Haibo Huang49cc9302020-04-27 16:14:24 -0700249 // 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(&param, pXFAWidgetHandler);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700254 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
255 pDocView->UpdateDocView();
256
Haibo Huang49cc9302020-04-27 16:14:24 -0700257 return ret;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700258}
259
260void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
261 CXFA_FFWidget* hWidget = GetMixXFAWidget();
262 if (!hWidget)
263 return;
264
Haibo Huang49cc9302020-04-27 16:14:24 -0700265 CXFA_Node* node = hWidget->GetNode();
266 if (!node->IsWidgetReady())
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700267 return;
268
269 CPDF_FormField* pFormField = GetFormField();
270 switch (GetFieldType()) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700271 case FormFieldType::kCheckBox:
272 case FormFieldType::kRadioButton: {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700273 CPDF_FormControl* pFormCtrl = GetFormControl();
274 XFA_CHECKSTATE eCheckState =
275 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
Haibo Huang49cc9302020-04-27 16:14:24 -0700276 node->SetCheckState(eCheckState, true);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700277 break;
278 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700279 case FormFieldType::kTextField:
Haibo Huang49cc9302020-04-27 16:14:24 -0700280 node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue());
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700281 break;
Haibo Huang49cc9302020-04-27 16:14:24 -0700282 case FormFieldType::kComboBox:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700283 case FormFieldType::kListBox: {
Haibo Huang49cc9302020-04-27 16:14:24 -0700284 node->ClearAllSelections();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700285
Haibo Huang49cc9302020-04-27 16:14:24 -0700286 for (int i = 0; i < pFormField->CountSelectedItems(); ++i) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700287 int nIndex = pFormField->GetSelectedIndex(i);
Haibo Huang49cc9302020-04-27 16:14:24 -0700288 if (nIndex > -1 && nIndex < node->CountChoiceListItems(false))
289 node->SetItemState(nIndex, true, false, false, true);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700290 }
Haibo Huang49cc9302020-04-27 16:14:24 -0700291 if (GetFieldType() == FormFieldType::kComboBox)
292 node->SetValue(XFA_VALUEPICTURE_Edit, pFormField->GetValue());
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700293 break;
294 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700295 default:
296 break;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700297 }
298
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700299 if (bSynchronizeElse) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700300 auto* context = static_cast<CPDFXFA_Context*>(
301 m_pPageView->GetFormFillEnv()->GetDocExtension());
302 context->GetXFADocView()->ProcessValueChanged(node);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700303 }
304}
305#endif // PDF_ENABLE_XFA
306
307bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700308 const CPDF_Dictionary* pAP =
309 GetAnnotDict()->GetDictFor(pdfium::annotation::kAP);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700310 if (!pAP)
311 return false;
312
313 // Choose the right sub-ap
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700314 const char* ap_entry = "N";
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700315 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 Huang49cc9302020-04-27 16:14:24 -0700323 const CPDF_Object* pSub = pAP->GetDirectObjectFor(ap_entry);
324 if (!pSub)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700325 return false;
326
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700327 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 Huang49cc9302020-04-27 16:14:24 -0700334 return pSub->IsStream();
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700335 case FormFieldType::kCheckBox:
336 case FormFieldType::kRadioButton:
Haibo Huang49cc9302020-04-27 16:14:24 -0700337 if (const CPDF_Dictionary* pSubDict = pSub->AsDictionary()) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700338 return !!pSubDict->GetStreamFor(GetAppState());
339 }
340 return false;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700341 default:
342 return true;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700343 }
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700344}
345
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700346FormFieldType CPDFSDK_Widget::GetFieldType() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700347 CPDF_FormField* pField = GetFormField();
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700348 return pField ? pField->GetFieldType() : FormFieldType::kUnknown;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700349}
350
351bool CPDFSDK_Widget::IsAppearanceValid() {
352#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700353 CPDF_Document::Extension* pContext =
354 m_pPageView->GetFormFillEnv()->GetDocExtension();
355 if (pContext && pContext->ContainsExtensionFullForm())
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700356 return true;
357#endif // PDF_ENABLE_XFA
358 return CPDFSDK_BAAnnot::IsAppearanceValid();
359}
360
361int CPDFSDK_Widget::GetLayoutOrder() const {
362 return 2;
363}
364
365int CPDFSDK_Widget::GetFieldFlags() const {
Haibo Huang49cc9302020-04-27 16:14:24 -0700366 return GetFormField()->GetFieldFlags();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700367}
368
369bool CPDFSDK_Widget::IsSignatureWidget() const {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700370 return GetFieldType() == FormFieldType::kSignature;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700371}
372
373CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
374 CPDF_FormControl* pControl = GetFormControl();
375 return pControl ? pControl->GetField() : nullptr;
376}
377
378CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Haibo Huang49cc9302020-04-27 16:14:24 -0700379 CPDF_InteractiveForm* pPDFInteractiveForm =
380 m_pInteractiveForm->GetInteractiveForm();
381 return pPDFInteractiveForm->GetControlByDict(GetAnnotDict());
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700382}
383
384int CPDFSDK_Widget::GetRotate() const {
385 CPDF_FormControl* pCtrl = GetFormControl();
386 return pCtrl->GetRotation() % 360;
387}
388
389#ifdef PDF_ENABLE_XFA
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700390WideString CPDFSDK_Widget::GetName() const {
Haibo Huang49cc9302020-04-27 16:14:24 -0700391 return GetFormField()->GetFullName();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700392}
393#endif // PDF_ENABLE_XFA
394
Haibo Huang49cc9302020-04-27 16:14:24 -0700395Optional<FX_COLORREF> CPDFSDK_Widget::GetFillColor() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700396 CPDF_FormControl* pFormCtrl = GetFormControl();
397 int iColorType = 0;
Haibo Huang49cc9302020-04-27 16:14:24 -0700398 FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
399 if (iColorType == CFX_Color::kTransparent)
400 return {};
401 return color;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700402}
403
Haibo Huang49cc9302020-04-27 16:14:24 -0700404Optional<FX_COLORREF> CPDFSDK_Widget::GetBorderColor() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700405 CPDF_FormControl* pFormCtrl = GetFormControl();
406 int iColorType = 0;
Haibo Huang49cc9302020-04-27 16:14:24 -0700407 FX_COLORREF color = ArgbToColorRef(pFormCtrl->GetBorderColor(iColorType));
408 if (iColorType == CFX_Color::kTransparent)
409 return {};
410 return color;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700411}
412
Haibo Huang49cc9302020-04-27 16:14:24 -0700413Optional<FX_COLORREF> CPDFSDK_Widget::GetTextColor() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700414 CPDF_FormControl* pFormCtrl = GetFormControl();
415 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700416 FX_ARGB argb;
Haibo Huang49cc9302020-04-27 16:14:24 -0700417 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. Moltmann4d3acf42017-03-20 11:05:52 -0700426}
427
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700428float CPDFSDK_Widget::GetFontSize() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700429 CPDF_FormControl* pFormCtrl = GetFormControl();
430 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700431 float fFontSize;
432 pDa.GetFont(&fFontSize);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700433 return fFontSize;
434}
435
436int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
437#ifdef PDF_ENABLE_XFA
438 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700439 CXFA_Node* node = hWidget->GetNode();
440 if (node->IsWidgetReady()) {
441 if (nIndex < node->CountSelectedItems())
442 return node->GetSelectedItem(nIndex);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700443 }
444 }
445#endif // PDF_ENABLE_XFA
446 CPDF_FormField* pFormField = GetFormField();
447 return pFormField->GetSelectedIndex(nIndex);
448}
449
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700450WideString CPDFSDK_Widget::GetValue() const {
Haibo Huang49cc9302020-04-27 16:14:24 -0700451#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. Moltmann4d3acf42017-03-20 11:05:52 -0700457#endif // PDF_ENABLE_XFA
458 CPDF_FormField* pFormField = GetFormField();
459 return pFormField->GetValue();
460}
461
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700462WideString CPDFSDK_Widget::GetDefaultValue() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700463 CPDF_FormField* pFormField = GetFormField();
464 return pFormField->GetDefaultValue();
465}
466
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700467WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700468 CPDF_FormField* pFormField = GetFormField();
469 return pFormField->GetOptionLabel(nIndex);
470}
471
472int CPDFSDK_Widget::CountOptions() const {
473 CPDF_FormField* pFormField = GetFormField();
474 return pFormField->CountOptions();
475}
476
477bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
478#ifdef PDF_ENABLE_XFA
479 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700480 CXFA_Node* node = hWidget->GetNode();
481 if (node->IsWidgetReady()) {
482 if (nIndex > -1 && nIndex < node->CountChoiceListItems(false))
483 return node->GetItemState(nIndex);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700484
485 return false;
486 }
487 }
488#endif // PDF_ENABLE_XFA
489 CPDF_FormField* pFormField = GetFormField();
490 return pFormField->IsItemSelected(nIndex);
491}
492
493int CPDFSDK_Widget::GetTopVisibleIndex() const {
494 CPDF_FormField* pFormField = GetFormField();
495 return pFormField->GetTopVisibleIndex();
496}
497
498bool CPDFSDK_Widget::IsChecked() const {
499#ifdef PDF_ENABLE_XFA
500 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700501 CXFA_Node* node = hWidget->GetNode();
502 if (node->IsWidgetReady())
503 return node->GetCheckState() == XFA_CHECKSTATE_On;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700504 }
505#endif // PDF_ENABLE_XFA
506 CPDF_FormControl* pFormCtrl = GetFormControl();
507 return pFormCtrl->IsChecked();
508}
509
510int CPDFSDK_Widget::GetAlignment() const {
511 CPDF_FormControl* pFormCtrl = GetFormControl();
512 return pFormCtrl->GetControlAlignment();
513}
514
515int CPDFSDK_Widget::GetMaxLen() const {
516 CPDF_FormField* pFormField = GetFormField();
517 return pFormField->GetMaxLen();
518}
519
Haibo Huang49cc9302020-04-27 16:14:24 -0700520void CPDFSDK_Widget::SetCheck(bool bChecked, NotificationOption notify) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700521 CPDF_FormControl* pFormCtrl = GetFormControl();
522 CPDF_FormField* pFormField = pFormCtrl->GetField();
523 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
Haibo Huang49cc9302020-04-27 16:14:24 -0700524 notify);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700525#ifdef PDF_ENABLE_XFA
526 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
Haibo Huang49cc9302020-04-27 16:14:24 -0700527 ResetXFAAppearance(true);
528 if (notify == NotificationOption::kDoNotNotify)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700529 Synchronize(true);
530#endif // PDF_ENABLE_XFA
531}
532
Haibo Huang49cc9302020-04-27 16:14:24 -0700533void CPDFSDK_Widget::SetValue(const WideString& sValue,
534 NotificationOption notify) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700535 CPDF_FormField* pFormField = GetFormField();
Haibo Huang49cc9302020-04-27 16:14:24 -0700536 pFormField->SetValue(sValue, notify);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700537#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700538 if (notify == NotificationOption::kDoNotNotify)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700539 Synchronize(true);
540#endif // PDF_ENABLE_XFA
541}
542
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700543void CPDFSDK_Widget::SetOptionSelection(int index,
544 bool bSelected,
Haibo Huang49cc9302020-04-27 16:14:24 -0700545 NotificationOption notify) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700546 CPDF_FormField* pFormField = GetFormField();
Haibo Huang49cc9302020-04-27 16:14:24 -0700547 pFormField->SetItemSelection(index, bSelected, notify);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700548#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700549 if (notify == NotificationOption::kDoNotNotify)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700550 Synchronize(true);
551#endif // PDF_ENABLE_XFA
552}
553
Haibo Huang49cc9302020-04-27 16:14:24 -0700554void CPDFSDK_Widget::ClearSelection(NotificationOption notify) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700555 CPDF_FormField* pFormField = GetFormField();
Haibo Huang49cc9302020-04-27 16:14:24 -0700556 pFormField->ClearSelection(notify);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700557#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700558 if (notify == NotificationOption::kDoNotNotify)
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700559 Synchronize(true);
560#endif // PDF_ENABLE_XFA
561}
562
563void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
564
565void CPDFSDK_Widget::SetAppModified() {
566 m_bAppModified = true;
567}
568
569void CPDFSDK_Widget::ClearAppModified() {
570 m_bAppModified = false;
571}
572
573bool CPDFSDK_Widget::IsAppModified() const {
574 return m_bAppModified;
575}
576
577#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700578void CPDFSDK_Widget::ResetXFAAppearance(bool bValueChanged) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700579 switch (GetFieldType()) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700580 case FormFieldType::kTextField:
581 case FormFieldType::kComboBox: {
Haibo Huang49cc9302020-04-27 16:14:24 -0700582 ResetAppearance(OnFormat(), true);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700583 break;
584 }
585 default:
Haibo Huang49cc9302020-04-27 16:14:24 -0700586 ResetAppearance(pdfium::nullopt, false);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700587 break;
588 }
589}
590#endif // PDF_ENABLE_XFA
591
Haibo Huang49cc9302020-04-27 16:14:24 -0700592void CPDFSDK_Widget::ResetAppearance(Optional<WideString> sValue,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700593 bool bValueChanged) {
594 SetAppModified();
595
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700596 m_nAppearanceAge++;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700597 if (bValueChanged)
598 m_nValueAge++;
599
Haibo Huang49cc9302020-04-27 16:14:24 -0700600 CPDFSDK_AppStream appStream(this, GetAPDict());
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700601 switch (GetFieldType()) {
602 case FormFieldType::kPushButton:
603 appStream.SetAsPushButton();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700604 break;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700605 case FormFieldType::kCheckBox:
606 appStream.SetAsCheckBox();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700607 break;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700608 case FormFieldType::kRadioButton:
609 appStream.SetAsRadioButton();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700610 break;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700611 case FormFieldType::kComboBox:
612 appStream.SetAsComboBox(sValue);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700613 break;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700614 case FormFieldType::kListBox:
615 appStream.SetAsListBox();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700616 break;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700617 case FormFieldType::kTextField:
618 appStream.SetAsTextField(sValue);
619 break;
620 default:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700621 break;
622 }
623
624 m_pAnnot->ClearCachedAP();
625}
626
Haibo Huang49cc9302020-04-27 16:14:24 -0700627Optional<WideString> CPDFSDK_Widget::OnFormat() {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700628 CPDF_FormField* pFormField = GetFormField();
629 ASSERT(pFormField);
Haibo Huang49cc9302020-04-27 16:14:24 -0700630 return m_pInteractiveForm->OnFormat(pFormField);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700631}
632
Haibo Huang49cc9302020-04-27 16:14:24 -0700633void CPDFSDK_Widget::ResetFieldAppearance() {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700634 CPDF_FormField* pFormField = GetFormField();
635 ASSERT(pFormField);
Haibo Huang49cc9302020-04-27 16:14:24 -0700636 m_pInteractiveForm->ResetFieldAppearance(pFormField, pdfium::nullopt);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700637}
638
639void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700640 const CFX_Matrix& mtUser2Device,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700641 CPDF_Annot::AppearanceMode mode,
642 const CPDF_RenderOptions* pOptions) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700643 FormFieldType fieldType = GetFieldType();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700644
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700645 if ((fieldType == FormFieldType::kCheckBox ||
646 fieldType == FormFieldType::kRadioButton) &&
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700647 mode == CPDF_Annot::Normal &&
648 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700649 CFX_GraphStateData gsd;
650 gsd.m_LineWidth = 0.0f;
651
Haibo Huang49cc9302020-04-27 16:14:24 -0700652 CFX_PathData pathData;
653 pathData.AppendFloatRect(GetRect());
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700654 pDevice->DrawPath(&pathData, &mtUser2Device, &gsd, 0, 0xFFAAAAAA,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700655 FXFILL_ALTERNATE);
656 } else {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700657 CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode, pOptions);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700658 }
659}
660
661void CPDFSDK_Widget::UpdateField() {
662 CPDF_FormField* pFormField = GetFormField();
663 ASSERT(pFormField);
Haibo Huang49cc9302020-04-27 16:14:24 -0700664 m_pInteractiveForm->UpdateField(pFormField);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700665}
666
667void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
668 CPDFSDK_PageView* pPageView) {
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700669 FormFieldType fieldType = GetFieldType();
Haibo Huang49cc9302020-04-27 16:14:24 -0700670 if (!m_pInteractiveForm->IsNeedHighLight(fieldType))
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700671 return;
672
Haibo Huang49cc9302020-04-27 16:14:24 -0700673 CFX_Matrix page2device = pPageView->GetCurrentMatrix();
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700674 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. Moltmann4d3acf42017-03-20 11:05:52 -0700683 rcDevice.Normalize();
684
Philip P. Moltmann33357ca2017-05-11 09:25:13 -0700685 pDevice->FillRect(
Haibo Huang49cc9302020-04-27 16:14:24 -0700686 rcDevice.ToFxRect(),
687 AlphaAndColorRefToArgb(
688 static_cast<int>(m_pInteractiveForm->GetHighlightAlpha()),
689 m_pInteractiveForm->GetHighlightColor(fieldType)));
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700690}
691
692CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
693 CFX_FloatRect rcWindow = GetRotatedRect();
Haibo Huang49cc9302020-04-27 16:14:24 -0700694 float fBorderWidth = GetBorderWidth();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700695 switch (GetBorderStyle()) {
696 case BorderStyle::BEVELED:
697 case BorderStyle::INSET:
698 fBorderWidth *= 2.0f;
699 break;
700 default:
701 break;
702 }
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700703 return rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700704}
705
706CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
707 CFX_FloatRect rectAnnot = GetRect();
Haibo Huang49cc9302020-04-27 16:14:24 -0700708 float fWidth = rectAnnot.Width();
709 float fHeight = rectAnnot.Height();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700710
711 CPDF_FormControl* pControl = GetFormControl();
Haibo Huang49cc9302020-04-27 16:14:24 -0700712 CFX_FloatRect rcPWLWindow;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700713 switch (abs(pControl->GetRotation() % 360)) {
714 case 0:
715 case 180:
716 default:
Haibo Huang49cc9302020-04-27 16:14:24 -0700717 rcPWLWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700718 break;
719 case 90:
720 case 270:
Haibo Huang49cc9302020-04-27 16:14:24 -0700721 rcPWLWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700722 break;
723 }
724
Haibo Huang49cc9302020-04-27 16:14:24 -0700725 return rcPWLWindow;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700726}
727
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700728CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
729 CFX_Matrix mt;
730 CPDF_FormControl* pControl = GetFormControl();
731 CFX_FloatRect rcAnnot = GetRect();
Haibo Huang49cc9302020-04-27 16:14:24 -0700732 float fWidth = rcAnnot.Width();
733 float fHeight = rcAnnot.Height();
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700734
735 switch (abs(pControl->GetRotation() % 360)) {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700736 default:
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700737 case 0:
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700738 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. Moltmannd904c1e2018-03-19 09:26:45 -0700753CFX_Color CPDFSDK_Widget::GetTextPWLColor() const {
754 CFX_Color crText = CFX_Color(CFX_Color::kGray, 0);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700755
756 CPDF_FormControl* pFormCtrl = GetFormControl();
757 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
Haibo Huang49cc9302020-04-27 16:14:24 -0700758
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. Moltmann4d3acf42017-03-20 11:05:52 -0700763
764 return crText;
765}
766
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700767CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const {
768 CFX_Color crBorder;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700769
770 CPDF_FormControl* pFormCtrl = GetFormControl();
771 int32_t iColorType;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700772 float fc[4];
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700773 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
774 if (iColorType > 0)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700775 crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700776
777 return crBorder;
778}
779
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700780CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
781 CFX_Color crFill;
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700782
783 CPDF_FormControl* pFormCtrl = GetFormControl();
784 int32_t iColorType;
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700785 float fc[4];
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700786 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
787 if (iColorType > 0)
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700788 crFill = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700789
790 return crFill;
791}
792
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700793bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
Haibo Huang49cc9302020-04-27 16:14:24 -0700794 CPDFSDK_FieldAction* data,
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700795 CPDFSDK_PageView* pPageView) {
796 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
797
798#ifdef PDF_ENABLE_XFA
Haibo Huang49cc9302020-04-27 16:14:24 -0700799 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(&param, pXFAWidgetHandler);
820 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
821 pDocView->UpdateDocView();
822 if (ret)
823 return true;
824 }
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700825 }
826 }
827 }
828#endif // PDF_ENABLE_XFA
829
830 CPDF_Action action = GetAAction(type);
Haibo Huang49cc9302020-04-27 16:14:24 -0700831 if (action.GetType() != CPDF_Action::Unknown) {
832 pFormFillEnv->GetActionHandler()->DoAction_Field(action, type, pFormFillEnv,
833 GetFormField(), data);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700834 }
835 return false;
836}
837
838CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
839 switch (eAAT) {
Haibo Huang49cc9302020-04-27 16:14:24 -0700840 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. Moltmann4d3acf42017-03-20 11:05:52 -0700850 return CPDFSDK_BAAnnot::GetAAction(eAAT);
851
Haibo Huang49cc9302020-04-27 16:14:24 -0700852 case CPDF_AAction::kKeyStroke:
853 case CPDF_AAction::kFormat:
854 case CPDF_AAction::kValidate:
855 case CPDF_AAction::kCalculate: {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700856 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. Moltmannd904c1e2018-03-19 09:26:45 -0700865 return CPDF_Action(nullptr);
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700866}
867
Philip P. Moltmannd904c1e2018-03-19 09:26:45 -0700868WideString CPDFSDK_Widget::GetAlternateName() const {
Philip P. Moltmann4d3acf42017-03-20 11:05:52 -0700869 CPDF_FormField* pFormField = GetFormField();
870 return pFormField->GetAlternateName();
871}