Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1 | // 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 | |
dsinclair | 8bd9ce0 | 2016-06-09 13:24:34 -0700 | [diff] [blame] | 9 | #include "fxjse/include/cfxjse_value.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 10 | #include "xfa/fxfa/app/xfa_ffbarcode.h" |
| 11 | #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
| 12 | #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 13 | #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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 18 | #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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 24 | #include "xfa/fxfa/app/xfa_ffwidgetacc.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 25 | #include "xfa/fxfa/app/xfa_fwladapter.h" |
| 26 | #include "xfa/fxfa/app/xfa_textlayout.h" |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 27 | #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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 33 | |
| 34 | static void XFA_FFDeleteWidgetAcc(void* pData) { |
| 35 | delete static_cast<CXFA_WidgetAcc*>(pData); |
| 36 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 37 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 38 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteWidgetAcc = { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 39 | XFA_FFDeleteWidgetAcc, nullptr}; |
| 40 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 41 | CXFA_FFNotify::CXFA_FFNotify(CXFA_FFDoc* pDoc) : m_pDoc(pDoc) {} |
| 42 | CXFA_FFNotify::~CXFA_FFNotify() {} |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 43 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 44 | void CXFA_FFNotify::OnPageEvent(CXFA_ContainerLayoutItem* pSender, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 45 | uint32_t dwEvent) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 46 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pSender->GetLayout()); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 47 | if (pDocView) |
| 48 | pDocView->OnPageEvent(pSender, dwEvent); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 49 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 50 | |
| 51 | void CXFA_FFNotify::OnWidgetListItemAdded(CXFA_WidgetData* pSender, |
| 52 | const FX_WCHAR* pLabel, |
| 53 | const FX_WCHAR* pValue, |
| 54 | int32_t iIndex) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 55 | CXFA_WidgetAcc* pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pSender); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 56 | if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 57 | return; |
| 58 | |
| 59 | CXFA_FFWidget* pWidget = nullptr; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 60 | while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 61 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 66 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 67 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 68 | } |
| 69 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 70 | |
| 71 | void CXFA_FFNotify::OnWidgetListItemRemoved(CXFA_WidgetData* pSender, |
| 72 | int32_t iIndex) { |
| 73 | CXFA_WidgetAcc* pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pSender); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 74 | if (pWidgetAcc->GetUIType() != XFA_Element::ChoiceList) |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 75 | return; |
| 76 | |
| 77 | CXFA_FFWidget* pWidget = nullptr; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 78 | while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 79 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | CXFA_LayoutItem* CXFA_FFNotify::OnCreateLayoutItem(CXFA_Node* pNode) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 90 | CXFA_LayoutProcessor* pLayout = m_pDoc->GetXFADoc()->GetDocLayout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(pLayout); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 92 | XFA_Element eType = pNode->GetClassID(); |
| 93 | if (eType == XFA_Element::PageArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 94 | return new CXFA_FFPageView(pDocView, pNode); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 95 | |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 96 | if (eType == XFA_Element::ContentArea) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 97 | return new CXFA_ContainerLayoutItem(pNode); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 98 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 99 | CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData()); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 100 | if (!pAcc) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 101 | return new CXFA_ContentLayoutItem(pNode); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 102 | |
| 103 | CXFA_FFWidget* pWidget; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 104 | switch (pAcc->GetUIType()) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 105 | case XFA_Element::Barcode: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 106 | pWidget = new CXFA_FFBarcode(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 107 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 108 | case XFA_Element::Button: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 109 | pWidget = new CXFA_FFPushButton(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 110 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 111 | case XFA_Element::CheckButton: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 112 | pWidget = new CXFA_FFCheckButton(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 113 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 114 | case XFA_Element::ChoiceList: { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 115 | if (pAcc->IsListBox()) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 116 | pWidget = new CXFA_FFListBox(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 117 | } else { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 118 | pWidget = new CXFA_FFComboBox(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 119 | } |
| 120 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 121 | case XFA_Element::DateTimeEdit: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 122 | pWidget = new CXFA_FFDateTimeEdit(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 123 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 124 | case XFA_Element::ImageEdit: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 125 | pWidget = new CXFA_FFImageEdit(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 126 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 127 | case XFA_Element::NumericEdit: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 128 | pWidget = new CXFA_FFNumericEdit(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 129 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 130 | case XFA_Element::PasswordEdit: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 131 | pWidget = new CXFA_FFPasswordEdit(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 132 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 133 | case XFA_Element::Signature: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 134 | pWidget = new CXFA_FFSignature(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 135 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 136 | case XFA_Element::TextEdit: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 137 | pWidget = new CXFA_FFTextEdit(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 138 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 139 | case XFA_Element::Arc: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 140 | pWidget = new CXFA_FFArc(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 141 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 142 | case XFA_Element::Line: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 143 | pWidget = new CXFA_FFLine(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 144 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 145 | case XFA_Element::Rectangle: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 146 | pWidget = new CXFA_FFRectangle(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 148 | case XFA_Element::Text: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 149 | pWidget = new CXFA_FFText(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 150 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 151 | case XFA_Element::Image: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 152 | pWidget = new CXFA_FFImage(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 153 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 154 | case XFA_Element::Draw: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 155 | pWidget = new CXFA_FFDraw(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 157 | case XFA_Element::Subform: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 158 | pWidget = new CXFA_FFSubForm(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 159 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 160 | case XFA_Element::ExclGroup: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 161 | pWidget = new CXFA_FFExclGroup(nullptr, pAcc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 162 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 163 | case XFA_Element::DefaultUi: |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 164 | default: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 165 | pWidget = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 166 | break; |
| 167 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 168 | |
| 169 | if (pWidget) |
| 170 | pWidget->SetDocView(pDocView); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 171 | return pWidget; |
| 172 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 173 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 174 | void 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 | } |
| 183 | FX_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 | } |
| 192 | FX_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; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 205 | CFXJSE_Value* pRetValue = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 206 | int32_t iRet = |
| 207 | pWidgetAcc->ExecuteScript(CXFA_Script(pScript), &EventParam, &pRetValue); |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 208 | if (iRet == XFA_EVENTERROR_Success && pRetValue) { |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 209 | bRet = pRetValue->ToBoolean(); |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 210 | delete pRetValue; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 211 | } |
| 212 | return bRet; |
| 213 | } |
| 214 | int32_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 | } |
| 227 | void 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 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 240 | CXFA_FFDoc* CXFA_FFNotify::GetHDOC() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 241 | return m_pDoc; |
| 242 | } |
| 243 | IXFA_DocProvider* CXFA_FFNotify::GetDocProvider() { |
| 244 | return m_pDoc->GetDocProvider(); |
| 245 | } |
| 246 | IXFA_AppProvider* CXFA_FFNotify::GetAppProvider() { |
| 247 | return m_pDoc->GetApp()->GetAppProvider(); |
| 248 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 249 | CXFA_FFWidgetHandler* CXFA_FFNotify::GetWidgetHandler() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 250 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
| 251 | return pDocView ? pDocView->GetWidgetHandler() : NULL; |
| 252 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 253 | CXFA_FFWidget* CXFA_FFNotify::GetHWidget(CXFA_LayoutItem* pLayoutItem) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 254 | return XFA_GetWidgetFromLayoutItem(pLayoutItem); |
| 255 | } |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 256 | void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 257 | if (hWidget->GetDataAcc()->GetUIType() != XFA_Element::ChoiceList) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 258 | return; |
| 259 | } |
| 260 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
| 261 | pDocView->LockUpdate(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 262 | static_cast<CXFA_FFComboBox*>(hWidget)->OpenDropDownList(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 263 | pDocView->UnlockUpdate(); |
| 264 | pDocView->UpdateDocView(); |
| 265 | } |
| 266 | CFX_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 | } |
| 275 | void 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 | } |
| 282 | int32_t CXFA_FFNotify::GetLayoutStatus() { |
| 283 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
| 284 | return pDocView ? pDocView->GetLayoutStatus() : 0; |
| 285 | } |
| 286 | void CXFA_FFNotify::RunNodeInitialize(CXFA_Node* pNode) { |
| 287 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
| 288 | if (!pDocView) { |
| 289 | return; |
| 290 | } |
| 291 | pDocView->AddNewFormNode(pNode); |
| 292 | } |
| 293 | void CXFA_FFNotify::RunSubformIndexChange(CXFA_Node* pSubformNode) { |
| 294 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
| 295 | if (!pDocView) { |
| 296 | return; |
| 297 | } |
| 298 | pDocView->AddIndexChangedSubform(pSubformNode); |
| 299 | } |
| 300 | CXFA_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 | } |
| 308 | void 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 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 317 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 318 | void CXFA_FFNotify::OnNodeReady(CXFA_Node* pNode) { |
| 319 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 320 | if (!pDocView) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 321 | return; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 322 | |
| 323 | XFA_Element iType = pNode->GetClassID(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 324 | if (XFA_IsCreateWidget(iType)) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 325 | CXFA_WidgetAcc* pAcc = new CXFA_WidgetAcc(pDocView, pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 326 | pNode->SetObject(XFA_ATTRIBUTE_WidgetData, pAcc, &gs_XFADeleteWidgetAcc); |
| 327 | return; |
| 328 | } |
| 329 | switch (iType) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 330 | case XFA_Element::BindItems: |
tsepez | 0e5f87a | 2016-04-27 15:51:19 -0700 | [diff] [blame] | 331 | pDocView->m_BindItems.Add(pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 332 | break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 333 | case XFA_Element::Validate: { |
dsinclair | c5a8f21 | 2016-06-20 11:11:12 -0700 | [diff] [blame] | 334 | pNode->SetFlag(XFA_NodeFlag_NeedsInitApp, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 335 | } break; |
| 336 | default: |
| 337 | break; |
| 338 | } |
| 339 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 340 | |
| 341 | void 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 351 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 352 | if (!pDocView) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 353 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 354 | |
| 355 | if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 356 | return; |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 357 | |
| 358 | CXFA_WidgetAcc* pWidgetAcc = |
| 359 | static_cast<CXFA_WidgetAcc*>(pSender->GetWidgetData()); |
| 360 | if (!pWidgetAcc) |
| 361 | return; |
| 362 | |
| 363 | CXFA_FFWidget* pWidget = nullptr; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 364 | while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 365 | if (pWidget->IsLoaded()) |
| 366 | pWidget->AddInvalidateRect(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 367 | } |
| 368 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 369 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 370 | void CXFA_FFNotify::OnValueChanged(CXFA_Node* pSender, |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 371 | XFA_ATTRIBUTE eAttr, |
| 372 | CXFA_Node* pParentNode, |
| 373 | CXFA_Node* pWidgetNode) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 374 | CXFA_FFDocView* pDocView = m_pDoc->GetDocView(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 375 | if (!pDocView) |
| 376 | return; |
| 377 | |
| 378 | if (!(pSender->GetPacketID() & XFA_XDPPACKET_Form)) { |
| 379 | if (eAttr == XFA_ATTRIBUTE_Value) |
| 380 | pDocView->AddCalculateNodeNotify(pSender); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 381 | return; |
| 382 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 383 | |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 384 | XFA_Element ePType = pParentNode->GetClassID(); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 385 | 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) { |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 394 | case XFA_Element::Caption: { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 395 | CXFA_TextLayout* pCapOut = pWidgetAcc->GetCaptionTextLayout(); |
| 396 | if (!pCapOut) |
| 397 | return; |
| 398 | |
| 399 | pCapOut->Unload(); |
| 400 | } break; |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 401 | case XFA_Element::Ui: |
| 402 | case XFA_Element::Para: |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 403 | 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); |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 413 | if (ePType == XFA_Element::Value || bIsContainerNode) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 414 | if (bIsContainerNode) { |
| 415 | pWidgetAcc->UpdateUIDisplay(); |
| 416 | pDocView->AddCalculateWidgetAcc(pWidgetAcc); |
| 417 | pDocView->AddValidateWidget(pWidgetAcc); |
| 418 | } else if (pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent)->GetClassID() == |
dsinclair | 56a8b19 | 2016-06-21 14:15:25 -0700 | [diff] [blame] | 419 | XFA_Element::ExclGroup) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 420 | pWidgetAcc->UpdateUIDisplay(); |
| 421 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 422 | return; |
| 423 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 424 | } |
| 425 | CXFA_FFWidget* pWidget = nullptr; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 426 | while ((pWidget = pWidgetAcc->GetNextWidget(pWidget)) != nullptr) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 427 | if (!pWidget->IsLoaded()) |
| 428 | continue; |
| 429 | |
| 430 | if (bUpdateProperty) |
| 431 | pWidget->UpdateWidgetProperty(); |
| 432 | pWidget->PerformLayout(); |
| 433 | pWidget->AddInvalidateRect(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 434 | } |
| 435 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 436 | |
| 437 | void CXFA_FFNotify::OnChildAdded(CXFA_Node* pSender) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 438 | 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); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 448 | if (bLayoutReady) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 449 | m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 450 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 451 | |
| 452 | void 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 462 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 463 | |
| 464 | void 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 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 476 | CXFA_FFPageView* pNewPageView = pDocView->GetPageView(iPageIdx); |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 477 | uint32_t dwFilter = XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | |
| 478 | XFA_WidgetStatus_Printable; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 479 | pWidget->ModifyStatus(dwStatus, dwFilter); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 480 | CXFA_FFPageView* pPrePageView = pWidget->GetPageView(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 481 | if (pPrePageView != pNewPageView || |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 482 | (dwStatus & (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) == |
| 483 | (XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 484 | pWidget->SetPageView(pNewPageView); |
dsinclair | c6450bb | 2016-05-16 13:37:46 -0700 | [diff] [blame] | 485 | m_pDoc->GetDocProvider()->WidgetPostAdd(pWidget, pWidget->GetDataAcc()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 486 | } |
| 487 | if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End || |
dsinclair | 935d8d5 | 2016-05-17 10:32:18 -0700 | [diff] [blame] | 488 | !(dwStatus & XFA_WidgetStatus_Visible)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 489 | 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 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 501 | |
| 502 | void 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 512 | pDocView->DeleteLayoutItem(pWidget); |
dsinclair | c6450bb | 2016-05-16 13:37:46 -0700 | [diff] [blame] | 513 | m_pDoc->GetDocProvider()->WidgetPreRemove(pWidget, pWidget->GetDataAcc()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 514 | pWidget->AddInvalidateRect(nullptr); |
| 515 | } |