blob: 3aef5fcbfdd5b0d5a3775900847db1b9703c3aa4 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// Copyright 2014 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 "xfa/fxfa/app/xfa_ffnotify.h"
8
dsinclair43554682016-09-29 17:29:48 -07009#include "fxjs/cfxjse_value.h"
Dan Sinclair1f5d4982017-01-10 16:37:32 -050010#include "xfa/fxfa/app/cxfa_textlayout.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040011#include "xfa/fxfa/app/xfa_ffbarcode.h"
12#include "xfa/fxfa/app/xfa_ffcheckbutton.h"
13#include "xfa/fxfa/app/xfa_ffchoicelist.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040014#include "xfa/fxfa/app/xfa_ffdraw.h"
15#include "xfa/fxfa/app/xfa_ffexclgroup.h"
16#include "xfa/fxfa/app/xfa_fffield.h"
17#include "xfa/fxfa/app/xfa_ffimage.h"
18#include "xfa/fxfa/app/xfa_ffimageedit.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040019#include "xfa/fxfa/app/xfa_ffpath.h"
20#include "xfa/fxfa/app/xfa_ffpushbutton.h"
21#include "xfa/fxfa/app/xfa_ffsignature.h"
22#include "xfa/fxfa/app/xfa_ffsubform.h"
23#include "xfa/fxfa/app/xfa_fftext.h"
24#include "xfa/fxfa/app/xfa_fftextedit.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040025#include "xfa/fxfa/app/xfa_ffwidgetacc.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040026#include "xfa/fxfa/app/xfa_fwladapter.h"
dsinclair5b493092016-09-29 20:20:24 -070027#include "xfa/fxfa/xfa_ffapp.h"
28#include "xfa/fxfa/xfa_ffdoc.h"
29#include "xfa/fxfa/xfa_ffdocview.h"
30#include "xfa/fxfa/xfa_ffpageview.h"
31#include "xfa/fxfa/xfa_ffwidget.h"
32#include "xfa/fxfa/xfa_ffwidgethandler.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040033
34static void XFA_FFDeleteWidgetAcc(void* pData) {
35 delete static_cast<CXFA_WidgetAcc*>(pData);
36}
dsinclairdf4bc592016-03-31 20:34:43 -070037
Dan Sinclair1770c022016-03-14 14:14:16 -040038static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteWidgetAcc = {
dsinclairdf4bc592016-03-31 20:34:43 -070039 XFA_FFDeleteWidgetAcc, nullptr};
40
Dan Sinclair1770c022016-03-14 14:14:16 -040041CXFA_FFNotify::CXFA_FFNotify(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {}
42CXFA_FFNotify::~CXFA_FFNotify() {}
thestigb1a59592016-04-14 18:29:56 -070043
dsinclairdf4bc592016-03-31 20:34:43 -070044void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender,
thestigb1a59592016-04-14 18:29:56 -070045 uint32_t dwEvent) {
Dan Sinclair1770c022016-03-14 14:14:16 -040046 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pSender->GetLayout());
thestigb1a59592016-04-14 18:29:56 -070047 if (pDocView)
48 pDocView->OnPageEvent(pSender, dwEvent);
Dan Sinclair1770c022016-03-14 14:14:16 -040049}
thestigb1a59592016-04-14 18:29:56 -070050
51void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender,
52 const FX_WCHAR* pLabel,
53 const FX_WCHAR* pValue,
54 int32_t iIndex) {
Dan Sinclair1770c022016-03-14 14:14:16 -040055 CXFA_WidgetAcc* pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pSender);
dsinclair56a8b192016-06-21 14:15:25 -070056 if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList)
thestigb1a59592016-04-14 18:29:56 -070057 return;
58
59 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -070060 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -070061 if (pWidget->IsLoaded()) {
62 if (pWidgetAcc->IsListBox()) {
63 static_cast<CXFA_FFListBox*>(pWidget)->InsertItem(pLabel, iIndex);
64 } else {
65 static_cast<CXFA_FFComboBox*>(pWidget)->InsertItem(pLabel, iIndex);
Dan Sinclair1770c022016-03-14 14:14:16 -040066 }
thestigb1a59592016-04-14 18:29:56 -070067 }
Dan Sinclair1770c022016-03-14 14:14:16 -040068 }
69}
thestigb1a59592016-04-14 18:29:56 -070070
71void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetData* pSender,
72 int32_t iIndex) {
73 CXFA_WidgetAcc* pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pSender);
dsinclair56a8b192016-06-21 14:15:25 -070074 if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList)
thestigb1a59592016-04-14 18:29:56 -070075 return;
76
77 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -070078 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -070079 if (pWidget->IsLoaded()) {
80 if (pWidgetAcc->IsListBox()) {
81 static_cast<CXFA_FFListBox*>(pWidget)->DeleteItem(iIndex);
82 } else {
83 static_cast<CXFA_FFComboBox*>(pWidget)->DeleteItem(iIndex);
84 }
85 }
86 }
87}
88
Dan Sinclair1770c022016-03-14 14:14:16 -040089CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) {
dsinclairdf4bc592016-03-31 20:34:43 -070090 CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetDocLayout();
Dan Sinclair1770c022016-03-14 14:14:16 -040091 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout);
dsinclair070fcdf2016-06-22 22:04:54 -070092 XFA_Element eType = pNode->GetElementType();
dsinclair56a8b192016-06-21 14:15:25 -070093 if (eType == XFA_Element::PageArea)
Dan Sinclair1770c022016-03-14 14:14:16 -040094 return new CXFA_FFPageView(pDocView, pNode);
dsinclair56a8b192016-06-21 14:15:25 -070095 if (eType == XFA_Element::ContentArea)
Dan Sinclair1770c022016-03-14 14:14:16 -040096 return new CXFA_ContainerLayoutItem(pNode);
thestigb1a59592016-04-14 18:29:56 -070097
Dan Sinclair1770c022016-03-14 14:14:16 -040098 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData());
thestigb1a59592016-04-14 18:29:56 -070099 if (!pAcc)
Dan Sinclair1770c022016-03-14 14:14:16 -0400100 return new CXFA_ContentLayoutItem(pNode);
thestigb1a59592016-04-14 18:29:56 -0700101
102 CXFA_FFWidget* pWidget;
Dan Sinclair1770c022016-03-14 14:14:16 -0400103 switch (pAcc->GetUIType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700104 case XFA_Element::Barcode:
thestigb1a59592016-04-14 18:29:56 -0700105 pWidget = new CXFA_FFBarcode(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400106 break;
dsinclair56a8b192016-06-21 14:15:25 -0700107 case XFA_Element::Button:
thestigb1a59592016-04-14 18:29:56 -0700108 pWidget = new CXFA_FFPushButton(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400109 break;
dsinclair56a8b192016-06-21 14:15:25 -0700110 case XFA_Element::CheckButton:
thestigb1a59592016-04-14 18:29:56 -0700111 pWidget = new CXFA_FFCheckButton(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400112 break;
dsinclair56a8b192016-06-21 14:15:25 -0700113 case XFA_Element::ChoiceList: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400114 if (pAcc->IsListBox()) {
thestigb1a59592016-04-14 18:29:56 -0700115 pWidget = new CXFA_FFListBox(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400116 } else {
thestigb1a59592016-04-14 18:29:56 -0700117 pWidget = new CXFA_FFComboBox(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400118 }
119 } break;
dsinclair56a8b192016-06-21 14:15:25 -0700120 case XFA_Element::DateTimeEdit:
thestigb1a59592016-04-14 18:29:56 -0700121 pWidget = new CXFA_FFDateTimeEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400122 break;
dsinclair56a8b192016-06-21 14:15:25 -0700123 case XFA_Element::ImageEdit:
thestigb1a59592016-04-14 18:29:56 -0700124 pWidget = new CXFA_FFImageEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400125 break;
dsinclair56a8b192016-06-21 14:15:25 -0700126 case XFA_Element::NumericEdit:
thestigb1a59592016-04-14 18:29:56 -0700127 pWidget = new CXFA_FFNumericEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400128 break;
dsinclair56a8b192016-06-21 14:15:25 -0700129 case XFA_Element::PasswordEdit:
thestigb1a59592016-04-14 18:29:56 -0700130 pWidget = new CXFA_FFPasswordEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400131 break;
dsinclair56a8b192016-06-21 14:15:25 -0700132 case XFA_Element::Signature:
thestigb1a59592016-04-14 18:29:56 -0700133 pWidget = new CXFA_FFSignature(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400134 break;
dsinclair56a8b192016-06-21 14:15:25 -0700135 case XFA_Element::TextEdit:
thestigb1a59592016-04-14 18:29:56 -0700136 pWidget = new CXFA_FFTextEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400137 break;
dsinclair56a8b192016-06-21 14:15:25 -0700138 case XFA_Element::Arc:
thestigb1a59592016-04-14 18:29:56 -0700139 pWidget = new CXFA_FFArc(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400140 break;
dsinclair56a8b192016-06-21 14:15:25 -0700141 case XFA_Element::Line:
thestigb1a59592016-04-14 18:29:56 -0700142 pWidget = new CXFA_FFLine(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400143 break;
dsinclair56a8b192016-06-21 14:15:25 -0700144 case XFA_Element::Rectangle:
thestigb1a59592016-04-14 18:29:56 -0700145 pWidget = new CXFA_FFRectangle(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400146 break;
dsinclair56a8b192016-06-21 14:15:25 -0700147 case XFA_Element::Text:
thestigb1a59592016-04-14 18:29:56 -0700148 pWidget = new CXFA_FFText(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400149 break;
dsinclair56a8b192016-06-21 14:15:25 -0700150 case XFA_Element::Image:
thestigb1a59592016-04-14 18:29:56 -0700151 pWidget = new CXFA_FFImage(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400152 break;
dsinclair56a8b192016-06-21 14:15:25 -0700153 case XFA_Element::Draw:
thestigb1a59592016-04-14 18:29:56 -0700154 pWidget = new CXFA_FFDraw(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400155 break;
dsinclair56a8b192016-06-21 14:15:25 -0700156 case XFA_Element::Subform:
thestigb1a59592016-04-14 18:29:56 -0700157 pWidget = new CXFA_FFSubForm(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400158 break;
dsinclair56a8b192016-06-21 14:15:25 -0700159 case XFA_Element::ExclGroup:
thestigb1a59592016-04-14 18:29:56 -0700160 pWidget = new CXFA_FFExclGroup(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400161 break;
dsinclair56a8b192016-06-21 14:15:25 -0700162 case XFA_Element::DefaultUi:
Dan Sinclair1770c022016-03-14 14:14:16 -0400163 default:
thestigb1a59592016-04-14 18:29:56 -0700164 pWidget = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400165 break;
166 }
thestigb1a59592016-04-14 18:29:56 -0700167
168 if (pWidget)
169 pWidget->SetDocView(pDocView);
Dan Sinclair1770c022016-03-14 14:14:16 -0400170 return pWidget;
171}
thestigb1a59592016-04-14 18:29:56 -0700172
Dan Sinclair1770c022016-03-14 14:14:16 -0400173void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem,
174 FX_FLOAT& fCalcWidth,
175 FX_FLOAT& fCalcHeight) {
176 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData());
dsinclaireea31b72016-07-19 10:27:12 -0700177 if (!pAcc)
Dan Sinclair1770c022016-03-14 14:14:16 -0400178 return;
dsinclaireea31b72016-07-19 10:27:12 -0700179
Dan Sinclair1770c022016-03-14 14:14:16 -0400180 pAcc->StartWidgetLayout(fCalcWidth, fCalcHeight);
181}
dsinclaireea31b72016-07-19 10:27:12 -0700182
tsepezd19e9122016-11-02 15:43:18 -0700183bool CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem,
184 int32_t iBlockIndex,
185 FX_FLOAT& fCalcHeightPos) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400186 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData());
dsinclaireea31b72016-07-19 10:27:12 -0700187 return pAcc && pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos);
Dan Sinclair1770c022016-03-14 14:14:16 -0400188}
dsinclaireea31b72016-07-19 10:27:12 -0700189
tsepezd19e9122016-11-02 15:43:18 -0700190bool CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) {
191 bool bRet = false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400192 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
193 if (!pDocView) {
194 return bRet;
195 }
196 CXFA_WidgetAcc* pWidgetAcc =
197 static_cast<CXFA_WidgetAcc*>(pFormItem->GetWidgetData());
198 if (!pWidgetAcc) {
199 return bRet;
200 }
201 CXFA_EventParam EventParam;
202 EventParam.m_eType = XFA_EVENT_Unknown;
dsinclair12a6b0c2016-05-26 11:14:08 -0700203 CFXJSE_Value* pRetValue = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400204 int32_t iRet =
205 pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue);
Wei Lie98ac2e2016-03-18 15:43:04 -0700206 if (iRet == XFA_EVENTERROR_Success && pRetValue) {
dsinclairf27aeec2016-06-07 19:36:18 -0700207 bRet = pRetValue->ToBoolean();
dsinclair86fad992016-05-31 11:34:04 -0700208 delete pRetValue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400209 }
210 return bRet;
211}
212int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode,
213 XFA_EVENTTYPE eEventType,
tsepezd19e9122016-11-02 15:43:18 -0700214 bool bIsFormReady,
215 bool bRecursive,
Dan Sinclair1770c022016-03-14 14:14:16 -0400216 CXFA_WidgetAcc* pExclude) {
217 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
218 if (!pDocView) {
219 return XFA_EVENTERROR_NotExist;
220 }
221 return pDocView->ExecEventActivityByDeepFirst(
222 pFormNode, eEventType, bIsFormReady, bRecursive,
dsinclair85d1f2c2016-06-23 12:40:16 -0700223 pExclude ? pExclude->GetNode() : nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400224}
225void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) {
226 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
227 if (!pDocView) {
228 return;
229 }
230 CXFA_WidgetAcc* pWidgetAcc =
231 static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData());
232 if (!pWidgetAcc) {
233 return;
234 }
235 pDocView->AddCalculateWidgetAcc(pWidgetAcc);
236 pDocView->AddValidateWidget(pWidgetAcc);
237}
dsinclairdf4bc592016-03-31 20:34:43 -0700238CXFA_FFDoc* CXFA_FFNotify::GetHDOC() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400239 return m_pDoc;
240}
dsinclaira440bb32016-09-14 07:01:54 -0700241IXFA_DocEnvironment* CXFA_FFNotify::GetDocEnvironment() const {
242 return m_pDoc->GetDocEnvironment();
Dan Sinclair1770c022016-03-14 14:14:16 -0400243}
244IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() {
245 return m_pDoc->GetApp()->GetAppProvider();
246}
dsinclairdf4bc592016-03-31 20:34:43 -0700247CXFA_FFWidgetHandler* CXFA_FFNotify::GetWidgetHandler() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400248 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
dsinclair85d1f2c2016-06-23 12:40:16 -0700249 return pDocView ? pDocView->GetWidgetHandler() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400250}
dsinclairdf4bc592016-03-31 20:34:43 -0700251CXFA_FFWidget* CXFA_FFNotify::GetHWidget(CXFA_LayoutItem* pLayoutItem) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400252 return XFA_GetWidgetFromLayoutItem(pLayoutItem);
253}
dsinclairdf4bc592016-03-31 20:34:43 -0700254void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) {
dsinclair56a8b192016-06-21 14:15:25 -0700255 if (hWidget->GetDataAcc()->GetUIType() != XFA_Element::ChoiceList) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400256 return;
257 }
258 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
259 pDocView->LockUpdate();
dsinclairdf4bc592016-03-31 20:34:43 -0700260 static_cast<CXFA_FFComboBox*>(hWidget)->OpenDropDownList();
Dan Sinclair1770c022016-03-14 14:14:16 -0400261 pDocView->UnlockUpdate();
262 pDocView->UpdateDocView();
263}
264CFX_WideString CXFA_FFNotify::GetCurrentDateTime() {
265 CFX_Unitime dataTime;
266 dataTime.Now();
267 CFX_WideString wsDateTime;
268 wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(),
269 dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(),
270 dataTime.GetMinute(), dataTime.GetSecond());
271 return wsDateTime;
272}
273void CXFA_FFNotify::ResetData(CXFA_WidgetData* pWidgetData) {
274 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
275 if (!pDocView) {
276 return;
277 }
278 pDocView->ResetWidgetData(static_cast<CXFA_WidgetAcc*>(pWidgetData));
279}
280int32_t CXFA_FFNotify::GetLayoutStatus() {
281 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
282 return pDocView ? pDocView->GetLayoutStatus() : 0;
283}
284void CXFA_FFNotify::RunNodeInitialize(CXFA_Node* pNode) {
285 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
286 if (!pDocView) {
287 return;
288 }
289 pDocView->AddNewFormNode(pNode);
290}
291void CXFA_FFNotify::RunSubformIndexChange(CXFA_Node* pSubformNode) {
292 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
293 if (!pDocView) {
294 return;
295 }
296 pDocView->AddIndexChangedSubform(pSubformNode);
297}
298CXFA_Node* CXFA_FFNotify::GetFocusWidgetNode() {
299 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
300 if (!pDocView) {
dsinclair85d1f2c2016-06-23 12:40:16 -0700301 return nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400302 }
303 CXFA_WidgetAcc* pAcc = pDocView->GetFocusWidgetAcc();
dsinclair85d1f2c2016-06-23 12:40:16 -0700304 return pAcc ? pAcc->GetNode() : nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400305}
306void CXFA_FFNotify::SetFocusWidgetNode(CXFA_Node* pNode) {
307 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
308 if (!pDocView) {
309 return;
310 }
311 CXFA_WidgetAcc* pAcc =
312 pNode ? static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData()) : nullptr;
313 pDocView->SetFocusWidgetAcc(pAcc);
314}
thestigb1a59592016-04-14 18:29:56 -0700315
Dan Sinclair1770c022016-03-14 14:14:16 -0400316void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) {
317 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
dsinclair56a8b192016-06-21 14:15:25 -0700318 if (!pDocView)
Dan Sinclair1770c022016-03-14 14:14:16 -0400319 return;
dsinclair56a8b192016-06-21 14:15:25 -0700320
dsinclair41cb62e2016-06-23 09:20:32 -0700321 XFA_Element eType = pNode->GetElementType();
322 if (XFA_IsCreateWidget(eType)) {
dsinclairdf4bc592016-03-31 20:34:43 -0700323 CXFA_WidgetAcc* pAcc = new CXFA_WidgetAcc(pDocView, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400324 pNode->SetObject(XFA_ATTRIBUTE_WidgetData, pAcc, &gs_XFADeleteWidgetAcc);
325 return;
326 }
dsinclair41cb62e2016-06-23 09:20:32 -0700327 switch (eType) {
dsinclair56a8b192016-06-21 14:15:25 -0700328 case XFA_Element::BindItems:
tsepezd654d782017-01-03 14:18:07 -0800329 pDocView->m_BindItems.push_back(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400330 break;
dsinclair56a8b192016-06-21 14:15:25 -0700331 case XFA_Element::Validate: {
dsinclairc5a8f212016-06-20 11:11:12 -0700332 pNode->SetFlag(XFA_NodeFlag_NeedsInitApp, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400333 } break;
334 default:
335 break;
336 }
337}
thestigb1a59592016-04-14 18:29:56 -0700338
339void CXFA_FFNotify::OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr) {
340 if (eAttr != XFA_ATTRIBUTE_Presence)
341 return;
342
343 if (pSender->GetPacketID() & XFA_XDPPACKET_Datasets)
344 return;
345
346 if (!pSender->IsFormContainer())
347 return;
348
Dan Sinclair1770c022016-03-14 14:14:16 -0400349 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
thestigb1a59592016-04-14 18:29:56 -0700350 if (!pDocView)
Dan Sinclair1770c022016-03-14 14:14:16 -0400351 return;
thestigb1a59592016-04-14 18:29:56 -0700352
353 if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End)
Dan Sinclair1770c022016-03-14 14:14:16 -0400354 return;
thestigb1a59592016-04-14 18:29:56 -0700355
356 CXFA_WidgetAcc* pWidgetAcc =
357 static_cast<CXFA_WidgetAcc*>(pSender->GetWidgetData());
358 if (!pWidgetAcc)
359 return;
360
361 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -0700362 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -0700363 if (pWidget->IsLoaded())
364 pWidget->AddInvalidateRect();
Dan Sinclair1770c022016-03-14 14:14:16 -0400365 }
366}
thestigb1a59592016-04-14 18:29:56 -0700367
Dan Sinclair1770c022016-03-14 14:14:16 -0400368void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender,
thestigb1a59592016-04-14 18:29:56 -0700369 XFA_ATTRIBUTE eAttr,
370 CXFA_Node* pParentNode,
371 CXFA_Node* pWidgetNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400372 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
thestigb1a59592016-04-14 18:29:56 -0700373 if (!pDocView)
374 return;
375
376 if (!(pSender->GetPacketID() & XFA_XDPPACKET_Form)) {
377 if (eAttr == XFA_ATTRIBUTE_Value)
378 pDocView->AddCalculateNodeNotify(pSender);
Dan Sinclair1770c022016-03-14 14:14:16 -0400379 return;
380 }
thestigb1a59592016-04-14 18:29:56 -0700381
dsinclair41cb62e2016-06-23 09:20:32 -0700382 XFA_Element eType = pParentNode->GetElementType();
tsepezd19e9122016-11-02 15:43:18 -0700383 bool bIsContainerNode = pParentNode->IsContainerNode();
thestigb1a59592016-04-14 18:29:56 -0700384 CXFA_WidgetAcc* pWidgetAcc =
385 static_cast<CXFA_WidgetAcc*>(pWidgetNode->GetWidgetData());
386 if (!pWidgetAcc)
387 return;
388
389 bool bUpdateProperty = false;
390 pDocView->SetChangeMark();
dsinclair41cb62e2016-06-23 09:20:32 -0700391 switch (eType) {
dsinclair56a8b192016-06-21 14:15:25 -0700392 case XFA_Element::Caption: {
thestigb1a59592016-04-14 18:29:56 -0700393 CXFA_TextLayout* pCapOut = pWidgetAcc->GetCaptionTextLayout();
394 if (!pCapOut)
395 return;
396
397 pCapOut->Unload();
398 } break;
dsinclair56a8b192016-06-21 14:15:25 -0700399 case XFA_Element::Ui:
400 case XFA_Element::Para:
thestigb1a59592016-04-14 18:29:56 -0700401 bUpdateProperty = true;
402 break;
403 default:
404 break;
405 }
406 if (bIsContainerNode && eAttr == XFA_ATTRIBUTE_Access)
407 bUpdateProperty = true;
408
409 if (eAttr == XFA_ATTRIBUTE_Value) {
410 pDocView->AddCalculateNodeNotify(pSender);
dsinclair41cb62e2016-06-23 09:20:32 -0700411 if (eType == XFA_Element::Value || bIsContainerNode) {
thestigb1a59592016-04-14 18:29:56 -0700412 if (bIsContainerNode) {
413 pWidgetAcc->UpdateUIDisplay();
414 pDocView->AddCalculateWidgetAcc(pWidgetAcc);
415 pDocView->AddValidateWidget(pWidgetAcc);
dsinclair070fcdf2016-06-22 22:04:54 -0700416 } else if (pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent)
417 ->GetElementType() == XFA_Element::ExclGroup) {
thestigb1a59592016-04-14 18:29:56 -0700418 pWidgetAcc->UpdateUIDisplay();
419 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400420 return;
421 }
thestigb1a59592016-04-14 18:29:56 -0700422 }
423 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -0700424 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -0700425 if (!pWidget->IsLoaded())
426 continue;
427
428 if (bUpdateProperty)
429 pWidget->UpdateWidgetProperty();
430 pWidget->PerformLayout();
431 pWidget->AddInvalidateRect();
Dan Sinclair1770c022016-03-14 14:14:16 -0400432 }
433}
thestigb1a59592016-04-14 18:29:56 -0700434
435void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400436 if (!pSender->IsFormContainer()) {
437 return;
438 }
439 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
440 if (!pDocView) {
441 return;
442 }
tsepezd19e9122016-11-02 15:43:18 -0700443 bool bLayoutReady =
Dan Sinclair1770c022016-03-14 14:14:16 -0400444 !(pDocView->m_bInLayoutStatus) &&
445 (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
thestigb1a59592016-04-14 18:29:56 -0700446 if (bLayoutReady)
dsinclaira440bb32016-09-14 07:01:54 -0700447 m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400448}
thestigb1a59592016-04-14 18:29:56 -0700449
450void CXFA_FFNotify::OnChildRemoved() {
451 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
452 if (!pDocView)
453 return;
454
455 bool bLayoutReady =
456 !(pDocView->m_bInLayoutStatus) &&
457 (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
458 if (bLayoutReady)
dsinclaira440bb32016-09-14 07:01:54 -0700459 m_pDoc->GetDocEnvironment()->SetChangeMark(m_pDoc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400460}
thestigb1a59592016-04-14 18:29:56 -0700461
462void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
463 CXFA_LayoutItem* pSender,
464 int32_t iPageIdx,
465 uint32_t dwStatus) {
466 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout);
467 if (!pDocView)
468 return;
469
470 CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender);
471 if (!pWidget)
472 return;
473
dsinclairdf4bc592016-03-31 20:34:43 -0700474 CXFA_FFPageView* pNewPageView = pDocView->GetPageView(iPageIdx);
dsinclair935d8d52016-05-17 10:32:18 -0700475 uint32_t dwFilter = XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable |
476 XFA_WidgetStatus_Printable;
Dan Sinclair1770c022016-03-14 14:14:16 -0400477 pWidget->ModifyStatus(dwStatus, dwFilter);
dsinclairdf4bc592016-03-31 20:34:43 -0700478 CXFA_FFPageView* pPrePageView = pWidget->GetPageView();
Dan Sinclair1770c022016-03-14 14:14:16 -0400479 if (pPrePageView != pNewPageView ||
dsinclair935d8d52016-05-17 10:32:18 -0700480 (dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) ==
481 (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400482 pWidget->SetPageView(pNewPageView);
dsinclaira440bb32016-09-14 07:01:54 -0700483 m_pDoc->GetDocEnvironment()->WidgetPostAdd(pWidget, pWidget->GetDataAcc());
Dan Sinclair1770c022016-03-14 14:14:16 -0400484 }
485 if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End ||
dsinclair935d8d52016-05-17 10:32:18 -0700486 !(dwStatus & XFA_WidgetStatus_Visible)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400487 return;
488 }
489 if (pWidget->IsLoaded()) {
490 CFX_RectF rtOld;
491 pWidget->GetWidgetRect(rtOld);
492 if (rtOld != pWidget->ReCacheWidgetRect())
493 pWidget->PerformLayout();
494 } else {
495 pWidget->LoadWidget();
496 }
497 pWidget->AddInvalidateRect(nullptr);
498}
thestigb1a59592016-04-14 18:29:56 -0700499
500void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout,
501 CXFA_LayoutItem* pSender) {
502 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout);
503 if (!pDocView)
504 return;
505
506 CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender);
507 if (!pWidget)
508 return;
509
Dan Sinclair1770c022016-03-14 14:14:16 -0400510 pDocView->DeleteLayoutItem(pWidget);
dsinclaira440bb32016-09-14 07:01:54 -0700511 m_pDoc->GetDocEnvironment()->WidgetPreRemove(pWidget, pWidget->GetDataAcc());
Dan Sinclair1770c022016-03-14 14:14:16 -0400512 pWidget->AddInvalidateRect(nullptr);
513}