blob: 0c525129c4d1070f9b45143ff0cf709690cd9f39 [file] [log] [blame]
jaepark611adb82016-08-17 11:34:36 -07001// Copyright 2016 PDFium Authors. All rights reserved.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_widget.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
Henrique Nakashimaea8a6242017-06-19 14:26:54 -040010#include <sstream>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011
tsepez0e606b52016-11-18 16:22:41 -080012#include "core/fpdfapi/parser/cpdf_array.h"
dsinclair488b7ad2016-10-04 11:55:50 -070013#include "core/fpdfapi/parser/cpdf_dictionary.h"
14#include "core/fpdfapi/parser/cpdf_document.h"
tsepez0e606b52016-11-18 16:22:41 -080015#include "core/fpdfapi/parser/cpdf_reference.h"
dsinclair488b7ad2016-10-04 11:55:50 -070016#include "core/fpdfapi/parser/cpdf_stream.h"
tsepez0e606b52016-11-18 16:22:41 -080017#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair1727aee2016-09-29 13:12:56 -070018#include "core/fpdfdoc/cpdf_defaultappearance.h"
19#include "core/fpdfdoc/cpdf_formcontrol.h"
20#include "core/fpdfdoc/cpdf_formfield.h"
21#include "core/fpdfdoc/cpdf_iconfit.h"
22#include "core/fpdfdoc/cpdf_interform.h"
dsinclair74a34fc2016-09-29 16:41:42 -070023#include "core/fxge/cfx_graphstatedata.h"
24#include "core/fxge/cfx_pathdata.h"
25#include "core/fxge/cfx_renderdevice.h"
dsinclair735606d2016-10-05 15:47:02 -070026#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070027#include "fpdfsdk/cpdfsdk_interform.h"
28#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark611adb82016-08-17 11:34:36 -070029#include "fpdfsdk/formfiller/cba_fontmap.h"
dsinclair114e46a2016-09-29 17:18:21 -070030#include "fpdfsdk/fsdk_actionhandler.h"
31#include "fpdfsdk/fsdk_define.h"
Dan Sinclairc411eb92017-07-25 09:39:30 -040032#include "fpdfsdk/pwl/cpwl_appstream.h"
33#include "fpdfsdk/pwl/cpwl_edit.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Tom Sepez40e9ff32015-11-30 12:39:54 -080035#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070036#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair5b493092016-09-29 20:20:24 -070037#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclair80c48782017-03-23 12:11:20 -040038#include "xfa/fxfa/cxfa_ffdocview.h"
39#include "xfa/fxfa/cxfa_ffwidget.h"
40#include "xfa/fxfa/cxfa_ffwidgethandler.h"
41#include "xfa/fxfa/cxfa_widgetacc.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080042#endif // PDF_ENABLE_XFA
43
dsinclair72177da2016-09-15 12:07:23 -070044namespace {
45
46// Convert a FX_ARGB to a FX_COLORREF.
47FX_COLORREF ARGBToColorRef(FX_ARGB argb) {
48 return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) |
49 (static_cast<uint32_t>(argb) & 0x0000FF00) |
50 ((static_cast<uint32_t>(argb) & 0x000000FF) << 16));
51}
52
53} // namespace
54
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
56 CPDFSDK_PageView* pPageView,
57 CPDFSDK_InterForm* pInterForm)
58 : CPDFSDK_BAAnnot(pAnnot, pPageView),
59 m_pInterForm(pInterForm),
Tom Sepez7b1e53c2017-09-15 15:43:11 -070060 m_nAppearanceAge(0),
Tom Sepez40e9ff32015-11-30 12:39:54 -080061 m_nValueAge(0)
62#ifdef PDF_ENABLE_XFA
63 ,
thestig1cd352e2016-06-07 17:53:06 -070064 m_hMixXFAWidget(nullptr),
65 m_pWidgetHandler(nullptr)
Tom Sepez40e9ff32015-11-30 12:39:54 -080066#endif // PDF_ENABLE_XFA
67{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068}
69
dsinclairce04a452016-09-07 05:46:55 -070070CPDFSDK_Widget::~CPDFSDK_Widget() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Tom Sepez51da0932015-11-25 16:05:49 -080072#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070073CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
dsinclair521b7502016-11-02 13:02:28 -070074 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -040075 if (pContext->GetFormType() == FormType::kXFAForeground) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 if (!m_hMixXFAWidget) {
dsinclair521b7502016-11-02 13:02:28 -070077 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) {
Ryan Harrison275e2602017-09-18 14:23:18 -040078 WideString sName;
Lei Zhang99766722016-02-23 11:21:48 -080079 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) {
80 sName = GetAnnotName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 if (sName.IsEmpty())
82 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050083 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050085 }
Bo Xufdc00a72014-10-28 23:03:33 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -070088 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070090 }
Tom Sepezd0409af2017-05-25 15:53:57 -070091 return m_hMixXFAWidget.Get();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 }
thestig1cd352e2016-06-07 17:53:06 -070093 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094}
95
dsinclairdf4bc592016-03-31 20:34:43 -070096CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
dsinclair521b7502016-11-02 13:02:28 -070097 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -040098 if (pContext->GetFormType() != FormType::kXFAForeground)
Dan Sinclaircdba7472017-03-23 09:17:10 -040099 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100
Dan Sinclaircdba7472017-03-23 09:17:10 -0400101 CXFA_FFDocView* pDocView = pContext->GetXFADocView();
102 if (!pDocView)
103 return nullptr;
104
Ryan Harrison275e2602017-09-18 14:23:18 -0400105 WideString sName = GetName();
Dan Sinclaircdba7472017-03-23 09:17:10 -0400106 return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107}
108
dsinclairdf4bc592016-03-31 20:34:43 -0700109CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
dsinclair521b7502016-11-02 13:02:28 -0700110 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400111 if (pContext->GetFormType() != FormType::kXFAForeground)
Dan Sinclaircdba7472017-03-23 09:17:10 -0400112 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113
Dan Sinclaircdba7472017-03-23 09:17:10 -0400114 if (!m_pWidgetHandler) {
Tom Sepezd0409af2017-05-25 15:53:57 -0700115 CXFA_FFDocView* pDocView = pContext->GetXFADocView();
116 if (pDocView)
Dan Sinclaircdba7472017-03-23 09:17:10 -0400117 m_pWidgetHandler = pDocView->GetWidgetHandler();
118 }
Tom Sepezd0409af2017-05-25 15:53:57 -0700119 return m_pWidgetHandler.Get();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120}
121
122static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
123 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
124
125 switch (eXFAAAT) {
126 case PDFSDK_XFA_Click:
127 eEventType = XFA_EVENT_Click;
128 break;
129 case PDFSDK_XFA_Full:
130 eEventType = XFA_EVENT_Full;
131 break;
132 case PDFSDK_XFA_PreOpen:
133 eEventType = XFA_EVENT_PreOpen;
134 break;
135 case PDFSDK_XFA_PostOpen:
136 eEventType = XFA_EVENT_PostOpen;
137 break;
138 }
139
140 return eEventType;
141}
142
143static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
tsepez4cf55152016-11-02 14:37:54 -0700144 bool bWillCommit) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
146
147 switch (eAAT) {
148 case CPDF_AAction::CursorEnter:
149 eEventType = XFA_EVENT_MouseEnter;
150 break;
151 case CPDF_AAction::CursorExit:
152 eEventType = XFA_EVENT_MouseExit;
153 break;
154 case CPDF_AAction::ButtonDown:
155 eEventType = XFA_EVENT_MouseDown;
156 break;
157 case CPDF_AAction::ButtonUp:
158 eEventType = XFA_EVENT_MouseUp;
159 break;
160 case CPDF_AAction::GetFocus:
161 eEventType = XFA_EVENT_Enter;
162 break;
163 case CPDF_AAction::LoseFocus:
164 eEventType = XFA_EVENT_Exit;
165 break;
166 case CPDF_AAction::PageOpen:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 case CPDF_AAction::PageClose:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 case CPDF_AAction::PageVisible:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 case CPDF_AAction::PageInvisible:
170 break;
171 case CPDF_AAction::KeyStroke:
jaepark611adb82016-08-17 11:34:36 -0700172 if (!bWillCommit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 eEventType = XFA_EVENT_Change;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 break;
175 case CPDF_AAction::Validate:
176 eEventType = XFA_EVENT_Validate;
177 break;
178 case CPDF_AAction::OpenPage:
179 case CPDF_AAction::ClosePage:
180 case CPDF_AAction::Format:
181 case CPDF_AAction::Calculate:
182 case CPDF_AAction::CloseDocument:
183 case CPDF_AAction::SaveDocument:
184 case CPDF_AAction::DocumentSaved:
185 case CPDF_AAction::PrintDocument:
186 case CPDF_AAction::DocumentPrinted:
187 break;
Lei Zhang69fe7112017-09-14 18:26:26 -0700188 case CPDF_AAction::NumberOfActions:
189 NOTREACHED();
190 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 }
192
193 return eEventType;
194}
195
tsepez4cf55152016-11-02 14:37:54 -0700196bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
jaepark611adb82016-08-17 11:34:36 -0700197 CXFA_FFWidget* hWidget = GetMixXFAWidget();
198 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700199 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200
jaepark611adb82016-08-17 11:34:36 -0700201 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
202 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700203 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204
jaepark611adb82016-08-17 11:34:36 -0700205 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
206
207 CXFA_WidgetAcc* pAcc;
208 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
209 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
210 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
211 pAcc = hGroupWidget->GetDataAcc();
212 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
tsepez4cf55152016-11-02 14:37:54 -0700213 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 }
215 }
216
jaepark611adb82016-08-17 11:34:36 -0700217 pAcc = hWidget->GetDataAcc();
218 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219}
220
tsepez4cf55152016-11-02 14:37:54 -0700221bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
222 PDFSDK_FieldAction& data,
223 CPDFSDK_PageView* pPageView) {
dsinclair521b7502016-11-02 13:02:28 -0700224 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
jaepark611adb82016-08-17 11:34:36 -0700226 CXFA_FFWidget* hWidget = GetMixXFAWidget();
227 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700228 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
jaepark611adb82016-08-17 11:34:36 -0700230 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
231 if (eEventType == XFA_EVENT_Unknown)
tsepez4cf55152016-11-02 14:37:54 -0700232 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233
jaepark611adb82016-08-17 11:34:36 -0700234 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
235 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700236 return false;
jaepark611adb82016-08-17 11:34:36 -0700237
238 CXFA_EventParam param;
239 param.m_eType = eEventType;
240 param.m_wsChange = data.sChange;
241 param.m_iCommitKey = data.nCommitKey;
242 param.m_bShift = data.bShift;
243 param.m_iSelStart = data.nSelStart;
244 param.m_iSelEnd = data.nSelEnd;
245 param.m_wsFullText = data.sValue;
246 param.m_bKeyDown = data.bKeyDown;
247 param.m_bModifier = data.bModifier;
248 param.m_wsNewText = data.sValue;
249 if (data.nSelEnd > data.nSelStart)
250 param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
251
Tom Sepez3c3e2712017-04-17 15:38:19 -0700252 for (const auto& c : data.sChange)
253 param.m_wsNewText.Insert(data.nSelStart, c);
jaepark611adb82016-08-17 11:34:36 -0700254
Tom Sepez3c3e2712017-04-17 15:38:19 -0700255 param.m_wsPrevText = data.sValue;
jaepark611adb82016-08-17 11:34:36 -0700256 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
257 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
258 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
259 CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
260 param.m_pTarget = pAcc;
261 if (pXFAWidgetHandler->ProcessEvent(pAcc, &param) !=
262 XFA_EVENTERROR_Success) {
tsepez4cf55152016-11-02 14:37:54 -0700263 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 }
265 }
266 }
jaepark611adb82016-08-17 11:34:36 -0700267 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
268 param.m_pTarget = pAcc;
269 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270
dsinclair521b7502016-11-02 13:02:28 -0700271 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
jaepark611adb82016-08-17 11:34:36 -0700272 pDocView->UpdateDocView();
273
274 return nRet == XFA_EVENTERROR_Success;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275}
276
tsepez4cf55152016-11-02 14:37:54 -0700277void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
jaepark611adb82016-08-17 11:34:36 -0700278 CXFA_FFWidget* hWidget = GetMixXFAWidget();
279 if (!hWidget)
280 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281
jaepark611adb82016-08-17 11:34:36 -0700282 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
283 if (!pWidgetAcc)
284 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285
jaepark611adb82016-08-17 11:34:36 -0700286 CPDF_FormField* pFormField = GetFormField();
287 switch (GetFieldType()) {
288 case FIELDTYPE_CHECKBOX:
289 case FIELDTYPE_RADIOBUTTON: {
290 CPDF_FormControl* pFormCtrl = GetFormControl();
291 XFA_CHECKSTATE eCheckState =
292 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
293 pWidgetAcc->SetCheckState(eCheckState, true);
294 break;
295 }
296 case FIELDTYPE_TEXTFIELD:
297 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
298 break;
299 case FIELDTYPE_LISTBOX: {
300 pWidgetAcc->ClearAllSelections();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301
jaepark611adb82016-08-17 11:34:36 -0700302 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
303 int nIndex = pFormField->GetSelectedIndex(i);
Tom Sepez5c500ac2017-03-27 12:44:20 -0700304 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
tsepez4cf55152016-11-02 14:37:54 -0700305 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 }
jaepark611adb82016-08-17 11:34:36 -0700307 break;
308 }
309 case FIELDTYPE_COMBOBOX: {
310 pWidgetAcc->ClearAllSelections();
dsinclair221caf62016-04-04 12:08:40 -0700311
jaepark611adb82016-08-17 11:34:36 -0700312 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
313 int nIndex = pFormField->GetSelectedIndex(i);
Tom Sepez5c500ac2017-03-27 12:44:20 -0700314 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
tsepez4cf55152016-11-02 14:37:54 -0700315 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
jaepark611adb82016-08-17 11:34:36 -0700316 }
317 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
318 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 }
320 }
jaepark611adb82016-08-17 11:34:36 -0700321
322 if (bSynchronizeElse)
323 pWidgetAcc->ProcessValueChanged();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700324}
325
326void CPDFSDK_Widget::SynchronizeXFAValue() {
dsinclair521b7502016-11-02 13:02:28 -0700327 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
328 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 if (!pXFADocView)
330 return;
331
dsinclairdf4bc592016-03-31 20:34:43 -0700332 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700333 if (GetXFAWidgetHandler()) {
334 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
335 GetFormControl());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
337 }
338}
339
340void CPDFSDK_Widget::SynchronizeXFAItems() {
dsinclair521b7502016-11-02 13:02:28 -0700341 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
342 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 if (!pXFADocView)
344 return;
345
dsinclairdf4bc592016-03-31 20:34:43 -0700346 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700347 if (GetXFAWidgetHandler())
348 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 }
350}
351
dsinclairdf4bc592016-03-31 20:34:43 -0700352void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
353 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 CPDF_FormField* pFormField,
355 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800356 ASSERT(hWidget);
dsinclair221caf62016-04-04 12:08:40 -0700357 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358
dsinclair221caf62016-04-04 12:08:40 -0700359 switch (pFormField->GetFieldType()) {
360 case FIELDTYPE_CHECKBOX: {
361 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
362 pFormField->CheckControl(
363 pFormField->GetControlIndex(pFormControl),
364 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
365 }
jaepark611adb82016-08-17 11:34:36 -0700366 break;
367 }
dsinclair221caf62016-04-04 12:08:40 -0700368 case FIELDTYPE_RADIOBUTTON: {
369 // TODO(weili): Check whether we need to handle checkbox and radio
370 // button differently, otherwise, merge these two cases.
371 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
372 pFormField->CheckControl(
373 pFormField->GetControlIndex(pFormControl),
374 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
375 }
jaepark611adb82016-08-17 11:34:36 -0700376 break;
377 }
dsinclair221caf62016-04-04 12:08:40 -0700378 case FIELDTYPE_TEXTFIELD: {
379 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400380 WideString sValue;
dsinclair221caf62016-04-04 12:08:40 -0700381 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700382 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700383 }
jaepark611adb82016-08-17 11:34:36 -0700384 break;
385 }
dsinclair221caf62016-04-04 12:08:40 -0700386 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700387 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388
dsinclair221caf62016-04-04 12:08:40 -0700389 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
390 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
391 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392
dsinclair221caf62016-04-04 12:08:40 -0700393 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700394 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 }
396 }
dsinclair221caf62016-04-04 12:08:40 -0700397 }
jaepark611adb82016-08-17 11:34:36 -0700398 break;
399 }
dsinclair221caf62016-04-04 12:08:40 -0700400 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700401 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402
dsinclair221caf62016-04-04 12:08:40 -0700403 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
404 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
405 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406
dsinclair221caf62016-04-04 12:08:40 -0700407 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700408 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 }
dsinclair221caf62016-04-04 12:08:40 -0700411
Ryan Harrison275e2602017-09-18 14:23:18 -0400412 WideString sValue;
dsinclair221caf62016-04-04 12:08:40 -0700413 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700414 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700415 }
jaepark611adb82016-08-17 11:34:36 -0700416 break;
417 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 }
419}
420
dsinclairdf4bc592016-03-31 20:34:43 -0700421void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
422 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 CPDF_FormField* pFormField,
424 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800425 ASSERT(hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426
dsinclair221caf62016-04-04 12:08:40 -0700427 switch (pFormField->GetFieldType()) {
428 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700429 pFormField->ClearSelection(false);
430 pFormField->ClearOptions(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431
dsinclair221caf62016-04-04 12:08:40 -0700432 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700433 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz;
434 i++) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400435 WideString swText;
Tom Sepez5c500ac2017-03-27 12:44:20 -0700436 pWidgetAcc->GetChoiceListItem(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437
tsepez4cf55152016-11-02 14:37:54 -0700438 pFormField->InsertOption(swText, i, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 }
dsinclair221caf62016-04-04 12:08:40 -0700440 }
jaepark611adb82016-08-17 11:34:36 -0700441 break;
442 }
dsinclair221caf62016-04-04 12:08:40 -0700443 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700444 pFormField->ClearSelection(false);
445 pFormField->ClearOptions(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446
dsinclair221caf62016-04-04 12:08:40 -0700447 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700448 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz;
449 i++) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400450 WideString swText;
Tom Sepez5c500ac2017-03-27 12:44:20 -0700451 pWidgetAcc->GetChoiceListItem(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452
tsepez4cf55152016-11-02 14:37:54 -0700453 pFormField->InsertOption(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 }
dsinclair221caf62016-04-04 12:08:40 -0700455 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456
tsepez4cf55152016-11-02 14:37:54 -0700457 pFormField->SetValue(L"", true);
jaepark611adb82016-08-17 11:34:36 -0700458 break;
459 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 }
461}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800462#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463
tsepez4cf55152016-11-02 14:37:54 -0700464bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -0700465 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -0700467 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 // Choose the right sub-ap
Dan Sinclair812e96c2017-03-13 16:43:37 -0400470 const char* ap_entry = "N";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 if (mode == CPDF_Annot::Down)
472 ap_entry = "D";
473 else if (mode == CPDF_Annot::Rollover)
474 ap_entry = "R";
475 if (!pAP->KeyExist(ap_entry))
476 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -0700479 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 if (!psub)
tsepez4cf55152016-11-02 14:37:54 -0700481 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 int nFieldType = GetFieldType();
484 switch (nFieldType) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700485 case FIELDTYPE_PUSHBUTTON:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700486 case FIELDTYPE_COMBOBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700487 case FIELDTYPE_LISTBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700488 case FIELDTYPE_TEXTFIELD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 case FIELDTYPE_SIGNATURE:
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400490 return psub->IsStream();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 case FIELDTYPE_CHECKBOX:
492 case FIELDTYPE_RADIOBUTTON:
Dan Sinclairf1251c12015-10-20 16:24:45 -0400493 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
dsinclair38fd8442016-09-15 10:15:32 -0700494 return !!pSubDict->GetStreamFor(GetAppState());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 }
tsepez4cf55152016-11-02 14:37:54 -0700496 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 }
tsepez4cf55152016-11-02 14:37:54 -0700498 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499}
500
501int CPDFSDK_Widget::GetFieldType() const {
dsinclair92828192016-08-17 13:28:51 -0700502 CPDF_FormField* pField = GetFormField();
503 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504}
505
tsepez4cf55152016-11-02 14:37:54 -0700506bool CPDFSDK_Widget::IsAppearanceValid() {
Tom Sepez51da0932015-11-25 16:05:49 -0800507#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700508 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400509 FormType formType = pContext->GetFormType();
510 if (formType == FormType::kXFAFull)
tsepez4cf55152016-11-02 14:37:54 -0700511 return true;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800512#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800513 return CPDFSDK_BAAnnot::IsAppearanceValid();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514}
515
weili625ad662016-06-15 11:21:33 -0700516int CPDFSDK_Widget::GetLayoutOrder() const {
517 return 2;
518}
519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520int CPDFSDK_Widget::GetFieldFlags() const {
521 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 CPDF_FormControl* pFormControl =
523 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
524 CPDF_FormField* pFormField = pFormControl->GetField();
525 return pFormField->GetFieldFlags();
526}
527
jaepark9ed91372016-08-26 16:16:10 -0700528bool CPDFSDK_Widget::IsSignatureWidget() const {
529 return GetFieldType() == FIELDTYPE_SIGNATURE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530}
531
532CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
dsinclair92828192016-08-17 13:28:51 -0700533 CPDF_FormControl* pControl = GetFormControl();
534 return pControl ? pControl->GetField() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535}
536
537CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 return pPDFInterForm->GetControlByDict(GetAnnotDict());
540}
541
Lei Zhang1b700c32015-10-30 23:55:35 -0700542CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
543 CPDF_InterForm* pInterForm,
544 const CPDF_Dictionary* pAnnotDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800545 ASSERT(pAnnotDict);
Lei Zhang1b700c32015-10-30 23:55:35 -0700546 return pInterForm->GetControlByDict(pAnnotDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547}
548
549int CPDFSDK_Widget::GetRotate() const {
550 CPDF_FormControl* pCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 return pCtrl->GetRotation() % 360;
552}
553
Tom Sepez51da0932015-11-25 16:05:49 -0800554#ifdef PDF_ENABLE_XFA
Ryan Harrison275e2602017-09-18 14:23:18 -0400555WideString CPDFSDK_Widget::GetName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 return pFormField->GetFullName();
558}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800559#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560
tsepez4cf55152016-11-02 14:37:54 -0700561bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700564 color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
Dan Sinclair8e7f9322017-10-16 11:35:42 -0400565 return iColorType != CFX_Color::kTransparent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566}
567
tsepez4cf55152016-11-02 14:37:54 -0700568bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700571 color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType));
Dan Sinclair8e7f9322017-10-16 11:35:42 -0400572 return iColorType != CFX_Color::kTransparent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573}
574
tsepez4cf55152016-11-02 14:37:54 -0700575bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
jaepark611adb82016-08-17 11:34:36 -0700578 if (!da.HasColor())
tsepez4cf55152016-11-02 14:37:54 -0700579 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580
jaepark611adb82016-08-17 11:34:36 -0700581 FX_ARGB argb;
Dan Sinclair8e7f9322017-10-16 11:35:42 -0400582 int iColorType = CFX_Color::kTransparent;
jaepark611adb82016-08-17 11:34:36 -0700583 da.GetColor(argb, iColorType);
dsinclair72177da2016-09-15 12:07:23 -0700584 color = ARGBToColorRef(argb);
Dan Sinclair8e7f9322017-10-16 11:35:42 -0400585 return iColorType != CFX_Color::kTransparent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586}
587
Dan Sinclair05df0752017-03-14 14:43:42 -0400588float CPDFSDK_Widget::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
Tom Sepezc4a2b752017-04-07 13:56:13 -0700591 float fFontSize;
592 pDa.GetFont(&fFontSize);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 return fFontSize;
594}
595
Tom Sepezbf59a072015-10-21 14:07:23 -0700596int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700597#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700598 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700599 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
600 if (nIndex < pWidgetAcc->CountSelectedItems())
601 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700602 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700604#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepeza8a39e22015-10-12 15:47:07 -0700609#ifdef PDF_ENABLE_XFA
Ryan Harrison275e2602017-09-18 14:23:18 -0400610WideString CPDFSDK_Widget::GetValue(bool bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700611 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700612 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Ryan Harrison275e2602017-09-18 14:23:18 -0400613 WideString sValue;
dsinclair221caf62016-04-04 12:08:40 -0700614 pWidgetAcc->GetValue(
615 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
616 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700617 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800619#else
Ryan Harrison275e2602017-09-18 14:23:18 -0400620WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700621#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Ryan Harrison275e2602017-09-18 14:23:18 -0400626WideString CPDFSDK_Widget::GetDefaultValue() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 return pFormField->GetDefaultValue();
629}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630
Ryan Harrison275e2602017-09-18 14:23:18 -0400631WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 return pFormField->GetOptionLabel(nIndex);
634}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636int CPDFSDK_Widget::CountOptions() const {
637 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 return pFormField->CountOptions();
639}
640
tsepez4cf55152016-11-02 14:37:54 -0700641bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700642#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700643 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700644 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700645 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
dsinclair221caf62016-04-04 12:08:40 -0700646 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
tsepez4cf55152016-11-02 14:37:54 -0700648 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 }
650 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700651#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 CPDF_FormField* pFormField = GetFormField();
653 return pFormField->IsItemSelected(nIndex);
654}
655
656int CPDFSDK_Widget::GetTopVisibleIndex() const {
657 CPDF_FormField* pFormField = GetFormField();
658 return pFormField->GetTopVisibleIndex();
659}
660
Wei Li97da9762016-03-11 17:00:48 -0800661bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700662#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700663 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
664 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
665 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700667#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 return pFormCtrl->IsChecked();
670}
671
672int CPDFSDK_Widget::GetAlignment() const {
673 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 return pFormCtrl->GetControlAlignment();
675}
676
677int CPDFSDK_Widget::GetMaxLen() const {
678 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 return pFormField->GetMaxLen();
680}
681
Wei Li97da9762016-03-11 17:00:48 -0800682void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
686 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800687#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
tsepez4cf55152016-11-02 14:37:54 -0700689 ResetAppearance(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700691 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800692#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693}
694
Ryan Harrison275e2602017-09-18 14:23:18 -0400695void CPDFSDK_Widget::SetValue(const WideString& sValue, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800698#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700700 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800701#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702}
703
Ryan Harrison275e2602017-09-18 14:23:18 -0400704void CPDFSDK_Widget::SetDefaultValue(const WideString& sValue) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705void CPDFSDK_Widget::SetOptionSelection(int index,
tsepez4cf55152016-11-02 14:37:54 -0700706 bool bSelected,
707 bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800710#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700712 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800713#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714}
715
tsepez4cf55152016-11-02 14:37:54 -0700716void CPDFSDK_Widget::ClearSelection(bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800719#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700721 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800722#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723}
724
725void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
726
727void CPDFSDK_Widget::SetAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700728 m_bAppModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729}
730
731void CPDFSDK_Widget::ClearAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700732 m_bAppModified = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733}
734
tsepez4cf55152016-11-02 14:37:54 -0700735bool CPDFSDK_Widget::IsAppModified() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 return m_bAppModified;
737}
738
Tom Sepez51da0932015-11-25 16:05:49 -0800739#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700740void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 switch (GetFieldType()) {
742 case FIELDTYPE_TEXTFIELD:
743 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700744 bool bFormatted = false;
Ryan Harrison275e2602017-09-18 14:23:18 -0400745 WideString sValue = OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700746 ResetAppearance(bFormatted ? &sValue : nullptr, true);
jaepark611adb82016-08-17 11:34:36 -0700747 break;
748 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 default:
tsepez4cf55152016-11-02 14:37:54 -0700750 ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 break;
752 }
753}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800754#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755
Ryan Harrison275e2602017-09-18 14:23:18 -0400756void CPDFSDK_Widget::ResetAppearance(const WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -0700757 bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 SetAppModified();
759
Tom Sepez7b1e53c2017-09-15 15:43:11 -0700760 m_nAppearanceAge++;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 if (bValueChanged)
762 m_nValueAge++;
763
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400764 CPWL_AppStream appStream(this, GetAPDict());
765 switch (GetFieldType()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766 case FIELDTYPE_PUSHBUTTON:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400767 appStream.SetAsPushButton();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 break;
769 case FIELDTYPE_CHECKBOX:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400770 appStream.SetAsCheckBox();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 break;
772 case FIELDTYPE_RADIOBUTTON:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400773 appStream.SetAsRadioButton();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 break;
775 case FIELDTYPE_COMBOBOX:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400776 appStream.SetAsComboBox(sValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777 break;
778 case FIELDTYPE_LISTBOX:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400779 appStream.SetAsListBox();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 break;
781 case FIELDTYPE_TEXTFIELD:
Dan Sinclaircb2ea422017-07-19 15:24:49 -0400782 appStream.SetAsTextField(sValue);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783 break;
784 }
785
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786 m_pAnnot->ClearCachedAP();
787}
788
Ryan Harrison275e2602017-09-18 14:23:18 -0400789WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800791 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700792 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793}
794
tsepez4cf55152016-11-02 14:37:54 -0700795void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800797 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700798 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799}
800
801void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Lei Zhang8a449402017-08-17 15:07:47 -0700802 const CFX_Matrix& mtUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803 CPDF_Annot::AppearanceMode mode,
804 const CPDF_RenderOptions* pOptions) {
805 int nFieldType = GetFieldType();
806
807 if ((nFieldType == FIELDTYPE_CHECKBOX ||
808 nFieldType == FIELDTYPE_RADIOBUTTON) &&
809 mode == CPDF_Annot::Normal &&
810 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
811 CFX_PathData pathData;
812
Tom Sepez281a9ea2016-02-26 14:24:28 -0800813 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814
815 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
816 rcAnnot.top);
817
818 CFX_GraphStateData gsd;
819 gsd.m_LineWidth = 0.0f;
820
Lei Zhang8a449402017-08-17 15:07:47 -0700821 pDevice->DrawPath(&pathData, &mtUser2Device, &gsd, 0, 0xFFAAAAAA,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700822 FXFILL_ALTERNATE);
823 } else {
Lei Zhang8a449402017-08-17 15:07:47 -0700824 CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode, pOptions);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 }
826}
827
828void CPDFSDK_Widget::UpdateField() {
829 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800830 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 m_pInterForm->UpdateField(pFormField);
832}
833
834void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
835 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700837 if (!m_pInterForm->IsNeedHighLight(nFieldType))
838 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839
jaepark611adb82016-08-17 11:34:36 -0700840 CFX_Matrix page2device;
841 pPageView->GetCurrentMatrix(page2device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842
Dan Sinclairafb44562017-02-09 13:07:43 -0500843 CFX_FloatRect rcDevice = GetRect();
Dan Sinclaira0061af2017-02-23 09:25:17 -0500844 CFX_PointF tmp =
845 page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom));
846 rcDevice.left = tmp.x;
847 rcDevice.bottom = tmp.y;
848
849 tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top));
850 rcDevice.right = tmp.x;
851 rcDevice.top = tmp.y;
jaepark611adb82016-08-17 11:34:36 -0700852 rcDevice.Normalize();
853
Dan Sinclairafb44562017-02-09 13:07:43 -0500854 FX_RECT rcDev = rcDevice.ToFxRect();
855 pDevice->FillRect(
856 &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()),
857 m_pInterForm->GetHighlightColor(nFieldType)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700858}
859
Tom Sepez281a9ea2016-02-26 14:24:28 -0800860CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
861 CFX_FloatRect rcWindow = GetRotatedRect();
Dan Sinclair05df0752017-03-14 14:43:42 -0400862 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700863 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700864 case BorderStyle::BEVELED:
865 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 fBorderWidth *= 2.0f;
867 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700868 default:
869 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870 }
dan sinclaird6aff2f2017-07-13 21:36:29 -0400871 return rcWindow.GetDeflated(fBorderWidth, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700872}
873
Tom Sepez281a9ea2016-02-26 14:24:28 -0800874CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
875 CFX_FloatRect rectAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -0400876 float fWidth = rectAnnot.right - rectAnnot.left;
877 float fHeight = rectAnnot.top - rectAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878
879 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800880 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 switch (abs(pControl->GetRotation() % 360)) {
882 case 0:
883 case 180:
884 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800885 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 break;
887 case 90:
888 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800889 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 break;
891 }
892
893 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700894}
895
Tom Sepez60d909e2015-12-10 15:34:55 -0800896CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
897 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800899 CFX_FloatRect rcAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -0400900 float fWidth = rcAnnot.right - rcAnnot.left;
901 float fHeight = rcAnnot.top - rcAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902
903 switch (abs(pControl->GetRotation() % 360)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 default:
Lei Zhang0a913942017-06-01 01:37:51 -0700905 case 0:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 break;
907 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -0800908 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700909 break;
910 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -0800911 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 break;
913 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -0800914 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 break;
916 }
917
918 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -0700919}
920
Dan Sinclair7f55a542017-07-13 14:17:10 -0400921CFX_Color CPDFSDK_Widget::GetTextPWLColor() const {
Dan Sinclair8e7f9322017-10-16 11:35:42 -0400922 CFX_Color crText = CFX_Color(CFX_Color::kGray, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700923
924 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
926 if (da.HasColor()) {
927 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -0400928 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929 da.GetColor(iColorType, fc);
Dan Sinclair7f55a542017-07-13 14:17:10 -0400930 crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931 }
932
933 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700934}
935
Dan Sinclair7f55a542017-07-13 14:17:10 -0400936CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const {
937 CFX_Color crBorder;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938
939 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -0400941 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
943 if (iColorType > 0)
Dan Sinclair7f55a542017-07-13 14:17:10 -0400944 crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945
946 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700947}
948
Dan Sinclair7f55a542017-07-13 14:17:10 -0400949CFX_Color CPDFSDK_Widget::GetFillPWLColor() const {
950 CFX_Color crFill;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951
952 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -0400954 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
956 if (iColorType > 0)
Dan Sinclair7f55a542017-07-13 14:17:10 -0400957 crFill = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958
959 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -0700960}
961
tsepez4cf55152016-11-02 14:37:54 -0700962bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
963 PDFSDK_FieldAction& data,
964 CPDFSDK_PageView* pPageView) {
dsinclairb402b172016-10-11 09:26:32 -0700965 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700966
Tom Sepez40e9ff32015-11-30 12:39:54 -0800967#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700968 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
dsinclairdf4bc592016-03-31 20:34:43 -0700969 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
971
972 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -0700973 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974 CXFA_EventParam param;
975 param.m_eType = eEventType;
976 param.m_wsChange = data.sChange;
977 param.m_iCommitKey = data.nCommitKey;
978 param.m_bShift = data.bShift;
979 param.m_iSelStart = data.nSelStart;
980 param.m_iSelEnd = data.nSelEnd;
981 param.m_wsFullText = data.sValue;
982 param.m_bKeyDown = data.bKeyDown;
983 param.m_bModifier = data.bModifier;
984 param.m_wsNewText = data.sValue;
985 if (data.nSelEnd > data.nSelStart)
986 param.m_wsNewText.Delete(data.nSelStart,
987 data.nSelEnd - data.nSelStart);
988 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
989 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
990 param.m_wsPrevText = data.sValue;
991
dsinclair221caf62016-04-04 12:08:40 -0700992 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 param.m_pTarget = pAcc;
994 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
995
dsinclair521b7502016-11-02 13:02:28 -0700996 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700998
Wei Lie98ac2e2016-03-18 15:43:04 -0700999 if (nRet == XFA_EVENTERROR_Success)
tsepez4cf55152016-11-02 14:37:54 -07001000 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001001 }
1002 }
1003 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001004#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005
1006 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001007 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
Lei Zhangcddc8ed2017-06-20 17:26:44 -07001008 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler();
dsinclair19c198b2016-10-11 12:51:37 -07001009 return pActionHandler->DoAction_Field(action, type, pFormFillEnv,
1010 GetFormField(), data);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011 }
tsepez4cf55152016-11-02 14:37:54 -07001012 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013}
1014
1015CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1016 switch (eAAT) {
1017 case CPDF_AAction::CursorEnter:
1018 case CPDF_AAction::CursorExit:
1019 case CPDF_AAction::ButtonDown:
1020 case CPDF_AAction::ButtonUp:
1021 case CPDF_AAction::GetFocus:
1022 case CPDF_AAction::LoseFocus:
1023 case CPDF_AAction::PageOpen:
1024 case CPDF_AAction::PageClose:
1025 case CPDF_AAction::PageVisible:
1026 case CPDF_AAction::PageInvisible:
1027 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1028
1029 case CPDF_AAction::KeyStroke:
1030 case CPDF_AAction::Format:
1031 case CPDF_AAction::Validate:
1032 case CPDF_AAction::Calculate: {
1033 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001034 if (pField->GetAdditionalAction().GetDict())
1035 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1037 }
1038 default:
1039 break;
1040 }
1041
1042 return CPDF_Action();
1043}
1044
Ryan Harrison275e2602017-09-18 14:23:18 -04001045WideString CPDFSDK_Widget::GetAlternateName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001046 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047 return pFormField->GetAlternateName();
1048}