blob: e4b8312841786de16dd4cda9734c3aa4382780d4 [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
dsinclair8bd9ce02016-06-09 13:24:34 -07009#include "fxjse/include/cfxjse_value.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040010#include "xfa/fxfa/app/xfa_ffbarcode.h"
11#include "xfa/fxfa/app/xfa_ffcheckbutton.h"
12#include "xfa/fxfa/app/xfa_ffchoicelist.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040013#include "xfa/fxfa/app/xfa_ffdraw.h"
14#include "xfa/fxfa/app/xfa_ffexclgroup.h"
15#include "xfa/fxfa/app/xfa_fffield.h"
16#include "xfa/fxfa/app/xfa_ffimage.h"
17#include "xfa/fxfa/app/xfa_ffimageedit.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040018#include "xfa/fxfa/app/xfa_ffpath.h"
19#include "xfa/fxfa/app/xfa_ffpushbutton.h"
20#include "xfa/fxfa/app/xfa_ffsignature.h"
21#include "xfa/fxfa/app/xfa_ffsubform.h"
22#include "xfa/fxfa/app/xfa_fftext.h"
23#include "xfa/fxfa/app/xfa_fftextedit.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040024#include "xfa/fxfa/app/xfa_ffwidgetacc.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040025#include "xfa/fxfa/app/xfa_fwladapter.h"
26#include "xfa/fxfa/app/xfa_textlayout.h"
dsinclair7222ea62016-04-06 14:33:07 -070027#include "xfa/fxfa/include/xfa_ffapp.h"
28#include "xfa/fxfa/include/xfa_ffdoc.h"
29#include "xfa/fxfa/include/xfa_ffdocview.h"
30#include "xfa/fxfa/include/xfa_ffpageview.h"
31#include "xfa/fxfa/include/xfa_ffwidget.h"
32#include "xfa/fxfa/include/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);
thestigb1a59592016-04-14 18:29:56 -070095
dsinclair56a8b192016-06-21 14:15:25 -070096 if (eType == XFA_Element::ContentArea)
Dan Sinclair1770c022016-03-14 14:14:16 -040097 return new CXFA_ContainerLayoutItem(pNode);
thestigb1a59592016-04-14 18:29:56 -070098
Dan Sinclair1770c022016-03-14 14:14:16 -040099 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData());
thestigb1a59592016-04-14 18:29:56 -0700100 if (!pAcc)
Dan Sinclair1770c022016-03-14 14:14:16 -0400101 return new CXFA_ContentLayoutItem(pNode);
thestigb1a59592016-04-14 18:29:56 -0700102
103 CXFA_FFWidget* pWidget;
Dan Sinclair1770c022016-03-14 14:14:16 -0400104 switch (pAcc->GetUIType()) {
dsinclair56a8b192016-06-21 14:15:25 -0700105 case XFA_Element::Barcode:
thestigb1a59592016-04-14 18:29:56 -0700106 pWidget = new CXFA_FFBarcode(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400107 break;
dsinclair56a8b192016-06-21 14:15:25 -0700108 case XFA_Element::Button:
thestigb1a59592016-04-14 18:29:56 -0700109 pWidget = new CXFA_FFPushButton(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400110 break;
dsinclair56a8b192016-06-21 14:15:25 -0700111 case XFA_Element::CheckButton:
thestigb1a59592016-04-14 18:29:56 -0700112 pWidget = new CXFA_FFCheckButton(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400113 break;
dsinclair56a8b192016-06-21 14:15:25 -0700114 case XFA_Element::ChoiceList: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400115 if (pAcc->IsListBox()) {
thestigb1a59592016-04-14 18:29:56 -0700116 pWidget = new CXFA_FFListBox(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400117 } else {
thestigb1a59592016-04-14 18:29:56 -0700118 pWidget = new CXFA_FFComboBox(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400119 }
120 } break;
dsinclair56a8b192016-06-21 14:15:25 -0700121 case XFA_Element::DateTimeEdit:
thestigb1a59592016-04-14 18:29:56 -0700122 pWidget = new CXFA_FFDateTimeEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400123 break;
dsinclair56a8b192016-06-21 14:15:25 -0700124 case XFA_Element::ImageEdit:
thestigb1a59592016-04-14 18:29:56 -0700125 pWidget = new CXFA_FFImageEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400126 break;
dsinclair56a8b192016-06-21 14:15:25 -0700127 case XFA_Element::NumericEdit:
thestigb1a59592016-04-14 18:29:56 -0700128 pWidget = new CXFA_FFNumericEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400129 break;
dsinclair56a8b192016-06-21 14:15:25 -0700130 case XFA_Element::PasswordEdit:
thestigb1a59592016-04-14 18:29:56 -0700131 pWidget = new CXFA_FFPasswordEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400132 break;
dsinclair56a8b192016-06-21 14:15:25 -0700133 case XFA_Element::Signature:
thestigb1a59592016-04-14 18:29:56 -0700134 pWidget = new CXFA_FFSignature(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400135 break;
dsinclair56a8b192016-06-21 14:15:25 -0700136 case XFA_Element::TextEdit:
thestigb1a59592016-04-14 18:29:56 -0700137 pWidget = new CXFA_FFTextEdit(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400138 break;
dsinclair56a8b192016-06-21 14:15:25 -0700139 case XFA_Element::Arc:
thestigb1a59592016-04-14 18:29:56 -0700140 pWidget = new CXFA_FFArc(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400141 break;
dsinclair56a8b192016-06-21 14:15:25 -0700142 case XFA_Element::Line:
thestigb1a59592016-04-14 18:29:56 -0700143 pWidget = new CXFA_FFLine(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400144 break;
dsinclair56a8b192016-06-21 14:15:25 -0700145 case XFA_Element::Rectangle:
thestigb1a59592016-04-14 18:29:56 -0700146 pWidget = new CXFA_FFRectangle(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400147 break;
dsinclair56a8b192016-06-21 14:15:25 -0700148 case XFA_Element::Text:
thestigb1a59592016-04-14 18:29:56 -0700149 pWidget = new CXFA_FFText(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400150 break;
dsinclair56a8b192016-06-21 14:15:25 -0700151 case XFA_Element::Image:
thestigb1a59592016-04-14 18:29:56 -0700152 pWidget = new CXFA_FFImage(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400153 break;
dsinclair56a8b192016-06-21 14:15:25 -0700154 case XFA_Element::Draw:
thestigb1a59592016-04-14 18:29:56 -0700155 pWidget = new CXFA_FFDraw(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400156 break;
dsinclair56a8b192016-06-21 14:15:25 -0700157 case XFA_Element::Subform:
thestigb1a59592016-04-14 18:29:56 -0700158 pWidget = new CXFA_FFSubForm(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400159 break;
dsinclair56a8b192016-06-21 14:15:25 -0700160 case XFA_Element::ExclGroup:
thestigb1a59592016-04-14 18:29:56 -0700161 pWidget = new CXFA_FFExclGroup(nullptr, pAcc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400162 break;
dsinclair56a8b192016-06-21 14:15:25 -0700163 case XFA_Element::DefaultUi:
Dan Sinclair1770c022016-03-14 14:14:16 -0400164 default:
thestigb1a59592016-04-14 18:29:56 -0700165 pWidget = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400166 break;
167 }
thestigb1a59592016-04-14 18:29:56 -0700168
169 if (pWidget)
170 pWidget->SetDocView(pDocView);
Dan Sinclair1770c022016-03-14 14:14:16 -0400171 return pWidget;
172}
thestigb1a59592016-04-14 18:29:56 -0700173
Dan Sinclair1770c022016-03-14 14:14:16 -0400174void CXFA_FFNotify::StartFieldDrawLayout(CXFA_Node* pItem,
175 FX_FLOAT& fCalcWidth,
176 FX_FLOAT& fCalcHeight) {
177 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData());
178 if (!pAcc) {
179 return;
180 }
181 pAcc->StartWidgetLayout(fCalcWidth, fCalcHeight);
182}
183FX_BOOL CXFA_FFNotify::FindSplitPos(CXFA_Node* pItem,
184 int32_t iBlockIndex,
185 FX_FLOAT& fCalcHeightPos) {
186 CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData());
187 if (!pAcc) {
188 return FALSE;
189 }
190 return (XFA_LAYOUTRESULT)pAcc->FindSplitPos(iBlockIndex, fCalcHeightPos);
191}
192FX_BOOL CXFA_FFNotify::RunScript(CXFA_Node* pScript, CXFA_Node* pFormItem) {
193 FX_BOOL bRet = FALSE;
194 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
195 if (!pDocView) {
196 return bRet;
197 }
198 CXFA_WidgetAcc* pWidgetAcc =
199 static_cast<CXFA_WidgetAcc*>(pFormItem->GetWidgetData());
200 if (!pWidgetAcc) {
201 return bRet;
202 }
203 CXFA_EventParam EventParam;
204 EventParam.m_eType = XFA_EVENT_Unknown;
dsinclair12a6b0c2016-05-26 11:14:08 -0700205 CFXJSE_Value* pRetValue = nullptr;
Dan Sinclair1770c022016-03-14 14:14:16 -0400206 int32_t iRet =
207 pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue);
Wei Lie98ac2e2016-03-18 15:43:04 -0700208 if (iRet == XFA_EVENTERROR_Success && pRetValue) {
dsinclairf27aeec2016-06-07 19:36:18 -0700209 bRet = pRetValue->ToBoolean();
dsinclair86fad992016-05-31 11:34:04 -0700210 delete pRetValue;
Dan Sinclair1770c022016-03-14 14:14:16 -0400211 }
212 return bRet;
213}
214int32_t CXFA_FFNotify::ExecEventByDeepFirst(CXFA_Node* pFormNode,
215 XFA_EVENTTYPE eEventType,
216 FX_BOOL bIsFormReady,
217 FX_BOOL bRecursive,
218 CXFA_WidgetAcc* pExclude) {
219 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
220 if (!pDocView) {
221 return XFA_EVENTERROR_NotExist;
222 }
223 return pDocView->ExecEventActivityByDeepFirst(
224 pFormNode, eEventType, bIsFormReady, bRecursive,
225 pExclude ? pExclude->GetNode() : NULL);
226}
227void CXFA_FFNotify::AddCalcValidate(CXFA_Node* pNode) {
228 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
229 if (!pDocView) {
230 return;
231 }
232 CXFA_WidgetAcc* pWidgetAcc =
233 static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData());
234 if (!pWidgetAcc) {
235 return;
236 }
237 pDocView->AddCalculateWidgetAcc(pWidgetAcc);
238 pDocView->AddValidateWidget(pWidgetAcc);
239}
dsinclairdf4bc592016-03-31 20:34:43 -0700240CXFA_FFDoc* CXFA_FFNotify::GetHDOC() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400241 return m_pDoc;
242}
243IXFA_DocProvider* CXFA_FFNotify::GetDocProvider() {
244 return m_pDoc->GetDocProvider();
245}
246IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() {
247 return m_pDoc->GetApp()->GetAppProvider();
248}
dsinclairdf4bc592016-03-31 20:34:43 -0700249CXFA_FFWidgetHandler* CXFA_FFNotify::GetWidgetHandler() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400250 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
251 return pDocView ? pDocView->GetWidgetHandler() : NULL;
252}
dsinclairdf4bc592016-03-31 20:34:43 -0700253CXFA_FFWidget* CXFA_FFNotify::GetHWidget(CXFA_LayoutItem* pLayoutItem) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400254 return XFA_GetWidgetFromLayoutItem(pLayoutItem);
255}
dsinclairdf4bc592016-03-31 20:34:43 -0700256void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) {
dsinclair56a8b192016-06-21 14:15:25 -0700257 if (hWidget->GetDataAcc()->GetUIType() != XFA_Element::ChoiceList) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400258 return;
259 }
260 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
261 pDocView->LockUpdate();
dsinclairdf4bc592016-03-31 20:34:43 -0700262 static_cast<CXFA_FFComboBox*>(hWidget)->OpenDropDownList();
Dan Sinclair1770c022016-03-14 14:14:16 -0400263 pDocView->UnlockUpdate();
264 pDocView->UpdateDocView();
265}
266CFX_WideString CXFA_FFNotify::GetCurrentDateTime() {
267 CFX_Unitime dataTime;
268 dataTime.Now();
269 CFX_WideString wsDateTime;
270 wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(),
271 dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(),
272 dataTime.GetMinute(), dataTime.GetSecond());
273 return wsDateTime;
274}
275void CXFA_FFNotify::ResetData(CXFA_WidgetData* pWidgetData) {
276 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
277 if (!pDocView) {
278 return;
279 }
280 pDocView->ResetWidgetData(static_cast<CXFA_WidgetAcc*>(pWidgetData));
281}
282int32_t CXFA_FFNotify::GetLayoutStatus() {
283 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
284 return pDocView ? pDocView->GetLayoutStatus() : 0;
285}
286void CXFA_FFNotify::RunNodeInitialize(CXFA_Node* pNode) {
287 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
288 if (!pDocView) {
289 return;
290 }
291 pDocView->AddNewFormNode(pNode);
292}
293void CXFA_FFNotify::RunSubformIndexChange(CXFA_Node* pSubformNode) {
294 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
295 if (!pDocView) {
296 return;
297 }
298 pDocView->AddIndexChangedSubform(pSubformNode);
299}
300CXFA_Node* CXFA_FFNotify::GetFocusWidgetNode() {
301 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
302 if (!pDocView) {
303 return NULL;
304 }
305 CXFA_WidgetAcc* pAcc = pDocView->GetFocusWidgetAcc();
306 return pAcc ? pAcc->GetNode() : NULL;
307}
308void CXFA_FFNotify::SetFocusWidgetNode(CXFA_Node* pNode) {
309 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
310 if (!pDocView) {
311 return;
312 }
313 CXFA_WidgetAcc* pAcc =
314 pNode ? static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData()) : nullptr;
315 pDocView->SetFocusWidgetAcc(pAcc);
316}
thestigb1a59592016-04-14 18:29:56 -0700317
Dan Sinclair1770c022016-03-14 14:14:16 -0400318void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) {
319 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
dsinclair56a8b192016-06-21 14:15:25 -0700320 if (!pDocView)
Dan Sinclair1770c022016-03-14 14:14:16 -0400321 return;
dsinclair56a8b192016-06-21 14:15:25 -0700322
dsinclair070fcdf2016-06-22 22:04:54 -0700323 XFA_Element iType = pNode->GetElementType();
Dan Sinclair1770c022016-03-14 14:14:16 -0400324 if (XFA_IsCreateWidget(iType)) {
dsinclairdf4bc592016-03-31 20:34:43 -0700325 CXFA_WidgetAcc* pAcc = new CXFA_WidgetAcc(pDocView, pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400326 pNode->SetObject(XFA_ATTRIBUTE_WidgetData, pAcc, &gs_XFADeleteWidgetAcc);
327 return;
328 }
329 switch (iType) {
dsinclair56a8b192016-06-21 14:15:25 -0700330 case XFA_Element::BindItems:
tsepez0e5f87a2016-04-27 15:51:19 -0700331 pDocView->m_BindItems.Add(pNode);
Dan Sinclair1770c022016-03-14 14:14:16 -0400332 break;
dsinclair56a8b192016-06-21 14:15:25 -0700333 case XFA_Element::Validate: {
dsinclairc5a8f212016-06-20 11:11:12 -0700334 pNode->SetFlag(XFA_NodeFlag_NeedsInitApp, false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400335 } break;
336 default:
337 break;
338 }
339}
thestigb1a59592016-04-14 18:29:56 -0700340
341void CXFA_FFNotify::OnValueChanging(CXFA_Node* pSender, XFA_ATTRIBUTE eAttr) {
342 if (eAttr != XFA_ATTRIBUTE_Presence)
343 return;
344
345 if (pSender->GetPacketID() & XFA_XDPPACKET_Datasets)
346 return;
347
348 if (!pSender->IsFormContainer())
349 return;
350
Dan Sinclair1770c022016-03-14 14:14:16 -0400351 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
thestigb1a59592016-04-14 18:29:56 -0700352 if (!pDocView)
Dan Sinclair1770c022016-03-14 14:14:16 -0400353 return;
thestigb1a59592016-04-14 18:29:56 -0700354
355 if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End)
Dan Sinclair1770c022016-03-14 14:14:16 -0400356 return;
thestigb1a59592016-04-14 18:29:56 -0700357
358 CXFA_WidgetAcc* pWidgetAcc =
359 static_cast<CXFA_WidgetAcc*>(pSender->GetWidgetData());
360 if (!pWidgetAcc)
361 return;
362
363 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -0700364 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -0700365 if (pWidget->IsLoaded())
366 pWidget->AddInvalidateRect();
Dan Sinclair1770c022016-03-14 14:14:16 -0400367 }
368}
thestigb1a59592016-04-14 18:29:56 -0700369
Dan Sinclair1770c022016-03-14 14:14:16 -0400370void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender,
thestigb1a59592016-04-14 18:29:56 -0700371 XFA_ATTRIBUTE eAttr,
372 CXFA_Node* pParentNode,
373 CXFA_Node* pWidgetNode) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400374 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
thestigb1a59592016-04-14 18:29:56 -0700375 if (!pDocView)
376 return;
377
378 if (!(pSender->GetPacketID() & XFA_XDPPACKET_Form)) {
379 if (eAttr == XFA_ATTRIBUTE_Value)
380 pDocView->AddCalculateNodeNotify(pSender);
Dan Sinclair1770c022016-03-14 14:14:16 -0400381 return;
382 }
thestigb1a59592016-04-14 18:29:56 -0700383
dsinclair070fcdf2016-06-22 22:04:54 -0700384 XFA_Element ePType = pParentNode->GetElementType();
thestigb1a59592016-04-14 18:29:56 -0700385 FX_BOOL bIsContainerNode = pParentNode->IsContainerNode();
386 CXFA_WidgetAcc* pWidgetAcc =
387 static_cast<CXFA_WidgetAcc*>(pWidgetNode->GetWidgetData());
388 if (!pWidgetAcc)
389 return;
390
391 bool bUpdateProperty = false;
392 pDocView->SetChangeMark();
393 switch (ePType) {
dsinclair56a8b192016-06-21 14:15:25 -0700394 case XFA_Element::Caption: {
thestigb1a59592016-04-14 18:29:56 -0700395 CXFA_TextLayout* pCapOut = pWidgetAcc->GetCaptionTextLayout();
396 if (!pCapOut)
397 return;
398
399 pCapOut->Unload();
400 } break;
dsinclair56a8b192016-06-21 14:15:25 -0700401 case XFA_Element::Ui:
402 case XFA_Element::Para:
thestigb1a59592016-04-14 18:29:56 -0700403 bUpdateProperty = true;
404 break;
405 default:
406 break;
407 }
408 if (bIsContainerNode && eAttr == XFA_ATTRIBUTE_Access)
409 bUpdateProperty = true;
410
411 if (eAttr == XFA_ATTRIBUTE_Value) {
412 pDocView->AddCalculateNodeNotify(pSender);
dsinclair56a8b192016-06-21 14:15:25 -0700413 if (ePType == XFA_Element::Value || bIsContainerNode) {
thestigb1a59592016-04-14 18:29:56 -0700414 if (bIsContainerNode) {
415 pWidgetAcc->UpdateUIDisplay();
416 pDocView->AddCalculateWidgetAcc(pWidgetAcc);
417 pDocView->AddValidateWidget(pWidgetAcc);
dsinclair070fcdf2016-06-22 22:04:54 -0700418 } else if (pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent)
419 ->GetElementType() == XFA_Element::ExclGroup) {
thestigb1a59592016-04-14 18:29:56 -0700420 pWidgetAcc->UpdateUIDisplay();
421 }
Dan Sinclair1770c022016-03-14 14:14:16 -0400422 return;
423 }
thestigb1a59592016-04-14 18:29:56 -0700424 }
425 CXFA_FFWidget* pWidget = nullptr;
weili038aa532016-05-20 15:38:29 -0700426 while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) {
thestigb1a59592016-04-14 18:29:56 -0700427 if (!pWidget->IsLoaded())
428 continue;
429
430 if (bUpdateProperty)
431 pWidget->UpdateWidgetProperty();
432 pWidget->PerformLayout();
433 pWidget->AddInvalidateRect();
Dan Sinclair1770c022016-03-14 14:14:16 -0400434 }
435}
thestigb1a59592016-04-14 18:29:56 -0700436
437void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400438 if (!pSender->IsFormContainer()) {
439 return;
440 }
441 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
442 if (!pDocView) {
443 return;
444 }
445 FX_BOOL bLayoutReady =
446 !(pDocView->m_bInLayoutStatus) &&
447 (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
thestigb1a59592016-04-14 18:29:56 -0700448 if (bLayoutReady)
Dan Sinclair1770c022016-03-14 14:14:16 -0400449 m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400450}
thestigb1a59592016-04-14 18:29:56 -0700451
452void CXFA_FFNotify::OnChildRemoved() {
453 CXFA_FFDocView* pDocView = m_pDoc->GetDocView();
454 if (!pDocView)
455 return;
456
457 bool bLayoutReady =
458 !(pDocView->m_bInLayoutStatus) &&
459 (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
460 if (bLayoutReady)
461 m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
Dan Sinclair1770c022016-03-14 14:14:16 -0400462}
thestigb1a59592016-04-14 18:29:56 -0700463
464void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout,
465 CXFA_LayoutItem* pSender,
466 int32_t iPageIdx,
467 uint32_t dwStatus) {
468 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout);
469 if (!pDocView)
470 return;
471
472 CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender);
473 if (!pWidget)
474 return;
475
dsinclairdf4bc592016-03-31 20:34:43 -0700476 CXFA_FFPageView* pNewPageView = pDocView->GetPageView(iPageIdx);
dsinclair935d8d52016-05-17 10:32:18 -0700477 uint32_t dwFilter = XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable |
478 XFA_WidgetStatus_Printable;
Dan Sinclair1770c022016-03-14 14:14:16 -0400479 pWidget->ModifyStatus(dwStatus, dwFilter);
dsinclairdf4bc592016-03-31 20:34:43 -0700480 CXFA_FFPageView* pPrePageView = pWidget->GetPageView();
Dan Sinclair1770c022016-03-14 14:14:16 -0400481 if (pPrePageView != pNewPageView ||
dsinclair935d8d52016-05-17 10:32:18 -0700482 (dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) ==
483 (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400484 pWidget->SetPageView(pNewPageView);
dsinclairc6450bb2016-05-16 13:37:46 -0700485 m_pDoc->GetDocProvider()->WidgetPostAdd(pWidget, pWidget->GetDataAcc());
Dan Sinclair1770c022016-03-14 14:14:16 -0400486 }
487 if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End ||
dsinclair935d8d52016-05-17 10:32:18 -0700488 !(dwStatus & XFA_WidgetStatus_Visible)) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400489 return;
490 }
491 if (pWidget->IsLoaded()) {
492 CFX_RectF rtOld;
493 pWidget->GetWidgetRect(rtOld);
494 if (rtOld != pWidget->ReCacheWidgetRect())
495 pWidget->PerformLayout();
496 } else {
497 pWidget->LoadWidget();
498 }
499 pWidget->AddInvalidateRect(nullptr);
500}
thestigb1a59592016-04-14 18:29:56 -0700501
502void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_LayoutProcessor* pLayout,
503 CXFA_LayoutItem* pSender) {
504 CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout);
505 if (!pDocView)
506 return;
507
508 CXFA_FFWidget* pWidget = XFA_GetWidgetFromLayoutItem(pSender);
509 if (!pWidget)
510 return;
511
Dan Sinclair1770c022016-03-14 14:14:16 -0400512 pDocView->DeleteLayoutItem(pWidget);
dsinclairc6450bb2016-05-16 13:37:46 -0700513 m_pDoc->GetDocProvider()->WidgetPreRemove(pWidget, pWidget->GetDataAcc());
Dan Sinclair1770c022016-03-14 14:14:16 -0400514 pWidget->AddInvalidateRect(nullptr);
515}