OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/cpdfsdk_widget.h" | 7 #include "fpdfsdk/cpdfsdk_widget.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "fpdfsdk/cpdfsdk_interform.h" | 23 #include "fpdfsdk/cpdfsdk_interform.h" |
24 #include "fpdfsdk/cpdfsdk_pageview.h" | 24 #include "fpdfsdk/cpdfsdk_pageview.h" |
25 #include "fpdfsdk/formfiller/cba_fontmap.h" | 25 #include "fpdfsdk/formfiller/cba_fontmap.h" |
26 #include "fpdfsdk/fsdk_actionhandler.h" | 26 #include "fpdfsdk/fsdk_actionhandler.h" |
27 #include "fpdfsdk/fsdk_define.h" | 27 #include "fpdfsdk/fsdk_define.h" |
28 #include "fpdfsdk/fxedit/fxet_edit.h" | 28 #include "fpdfsdk/fxedit/fxet_edit.h" |
29 #include "fpdfsdk/pdfwindow/PWL_Edit.h" | 29 #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
30 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 30 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
31 | 31 |
32 #ifdef PDF_ENABLE_XFA | 32 #ifdef PDF_ENABLE_XFA |
33 #include "fpdfsdk/fpdfxfa/cpdfxfa_document.h" | 33 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
34 #include "xfa/fxfa/cxfa_eventparam.h" | 34 #include "xfa/fxfa/cxfa_eventparam.h" |
35 #include "xfa/fxfa/fxfa_widget.h" | 35 #include "xfa/fxfa/fxfa_widget.h" |
36 #include "xfa/fxfa/xfa_ffdocview.h" | 36 #include "xfa/fxfa/xfa_ffdocview.h" |
37 #include "xfa/fxfa/xfa_ffwidget.h" | 37 #include "xfa/fxfa/xfa_ffwidget.h" |
38 #include "xfa/fxfa/xfa_ffwidgethandler.h" | 38 #include "xfa/fxfa/xfa_ffwidgethandler.h" |
39 #endif // PDF_ENABLE_XFA | 39 #endif // PDF_ENABLE_XFA |
40 | 40 |
41 namespace { | 41 namespace { |
42 | 42 |
43 // Convert a FX_ARGB to a FX_COLORREF. | 43 // Convert a FX_ARGB to a FX_COLORREF. |
(...skipping 17 matching lines...) Expand all Loading... |
61 m_hMixXFAWidget(nullptr), | 61 m_hMixXFAWidget(nullptr), |
62 m_pWidgetHandler(nullptr) | 62 m_pWidgetHandler(nullptr) |
63 #endif // PDF_ENABLE_XFA | 63 #endif // PDF_ENABLE_XFA |
64 { | 64 { |
65 } | 65 } |
66 | 66 |
67 CPDFSDK_Widget::~CPDFSDK_Widget() {} | 67 CPDFSDK_Widget::~CPDFSDK_Widget() {} |
68 | 68 |
69 #ifdef PDF_ENABLE_XFA | 69 #ifdef PDF_ENABLE_XFA |
70 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { | 70 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
71 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 71 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
72 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 72 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
73 if (!m_hMixXFAWidget) { | 73 if (!m_hMixXFAWidget) { |
74 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { | 74 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { |
75 CFX_WideString sName; | 75 CFX_WideString sName; |
76 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { | 76 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
77 sName = GetAnnotName(); | 77 sName = GetAnnotName(); |
78 if (sName.IsEmpty()) | 78 if (sName.IsEmpty()) |
79 sName = GetName(); | 79 sName = GetName(); |
80 } else { | 80 } else { |
81 sName = GetName(); | 81 sName = GetName(); |
82 } | 82 } |
83 | 83 |
84 if (!sName.IsEmpty()) | 84 if (!sName.IsEmpty()) |
85 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); | 85 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); |
86 } | 86 } |
87 } | 87 } |
88 return m_hMixXFAWidget; | 88 return m_hMixXFAWidget; |
89 } | 89 } |
90 | 90 |
91 return nullptr; | 91 return nullptr; |
92 } | 92 } |
93 | 93 |
94 CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { | 94 CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
95 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 95 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
96 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 96 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
97 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { | 97 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { |
98 CFX_WideString sName = GetName(); | 98 CFX_WideString sName = GetName(); |
99 if (!sName.IsEmpty()) | 99 if (!sName.IsEmpty()) |
100 return pDocView->GetWidgetByName(sName, nullptr); | 100 return pDocView->GetWidgetByName(sName, nullptr); |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 return nullptr; | 104 return nullptr; |
105 } | 105 } |
106 | 106 |
107 CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { | 107 CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
108 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 108 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
109 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 109 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
110 if (!m_pWidgetHandler) { | 110 if (!m_pWidgetHandler) { |
111 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) | 111 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
112 m_pWidgetHandler = pDocView->GetWidgetHandler(); | 112 m_pWidgetHandler = pDocView->GetWidgetHandler(); |
113 } | 113 } |
114 return m_pWidgetHandler; | 114 return m_pWidgetHandler; |
115 } | 115 } |
116 | 116 |
117 return nullptr; | 117 return nullptr; |
118 } | 118 } |
119 | 119 |
120 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { | 120 static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
121 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; | 121 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 pAcc = hWidget->GetDataAcc(); | 215 pAcc = hWidget->GetDataAcc(); |
216 return pXFAWidgetHandler->HasEvent(pAcc, eEventType); | 216 return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
217 } | 217 } |
218 | 218 |
219 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, | 219 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
220 PDFSDK_FieldAction& data, | 220 PDFSDK_FieldAction& data, |
221 CPDFSDK_PageView* pPageView) { | 221 CPDFSDK_PageView* pPageView) { |
222 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 222 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
223 | 223 |
224 CXFA_FFWidget* hWidget = GetMixXFAWidget(); | 224 CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
225 if (!hWidget) | 225 if (!hWidget) |
226 return FALSE; | 226 return FALSE; |
227 | 227 |
228 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); | 228 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
229 if (eEventType == XFA_EVENT_Unknown) | 229 if (eEventType == XFA_EVENT_Unknown) |
230 return FALSE; | 230 return FALSE; |
231 | 231 |
232 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); | 232 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
(...skipping 26 matching lines...) Expand all Loading... |
259 if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != | 259 if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
260 XFA_EVENTERROR_Success) { | 260 XFA_EVENTERROR_Success) { |
261 return FALSE; | 261 return FALSE; |
262 } | 262 } |
263 } | 263 } |
264 } | 264 } |
265 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); | 265 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
266 param.m_pTarget = pAcc; | 266 param.m_pTarget = pAcc; |
267 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); | 267 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
268 | 268 |
269 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) | 269 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
270 pDocView->UpdateDocView(); | 270 pDocView->UpdateDocView(); |
271 | 271 |
272 return nRet == XFA_EVENTERROR_Success; | 272 return nRet == XFA_EVENTERROR_Success; |
273 } | 273 } |
274 | 274 |
275 void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { | 275 void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { |
276 CXFA_FFWidget* hWidget = GetMixXFAWidget(); | 276 CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
277 if (!hWidget) | 277 if (!hWidget) |
278 return; | 278 return; |
279 | 279 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); | 315 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
316 break; | 316 break; |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 if (bSynchronizeElse) | 320 if (bSynchronizeElse) |
321 pWidgetAcc->ProcessValueChanged(); | 321 pWidgetAcc->ProcessValueChanged(); |
322 } | 322 } |
323 | 323 |
324 void CPDFSDK_Widget::SynchronizeXFAValue() { | 324 void CPDFSDK_Widget::SynchronizeXFAValue() { |
325 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 325 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
326 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); | 326 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
327 if (!pXFADocView) | 327 if (!pXFADocView) |
328 return; | 328 return; |
329 | 329 |
330 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 330 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
331 if (GetXFAWidgetHandler()) { | 331 if (GetXFAWidgetHandler()) { |
332 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), | 332 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
333 GetFormControl()); | 333 GetFormControl()); |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 void CPDFSDK_Widget::SynchronizeXFAItems() { | 338 void CPDFSDK_Widget::SynchronizeXFAItems() { |
339 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 339 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
340 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); | 340 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
341 if (!pXFADocView) | 341 if (!pXFADocView) |
342 return; | 342 return; |
343 | 343 |
344 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 344 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
345 if (GetXFAWidgetHandler()) | 345 if (GetXFAWidgetHandler()) |
346 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); | 346 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
347 } | 347 } |
348 } | 348 } |
349 | 349 |
350 void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, | 350 void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 return TRUE; | 495 return TRUE; |
496 } | 496 } |
497 | 497 |
498 int CPDFSDK_Widget::GetFieldType() const { | 498 int CPDFSDK_Widget::GetFieldType() const { |
499 CPDF_FormField* pField = GetFormField(); | 499 CPDF_FormField* pField = GetFormField(); |
500 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; | 500 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; |
501 } | 501 } |
502 | 502 |
503 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { | 503 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { |
504 #ifdef PDF_ENABLE_XFA | 504 #ifdef PDF_ENABLE_XFA |
505 CPDFXFA_Document* pDoc = m_pPageView->GetFormFillEnv()->GetXFADocument(); | 505 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
506 int nDocType = pDoc->GetDocType(); | 506 int nDocType = pContext->GetDocType(); |
507 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) | 507 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
508 return TRUE; | 508 return TRUE; |
509 #endif // PDF_ENABLE_XFA | 509 #endif // PDF_ENABLE_XFA |
510 return CPDFSDK_BAAnnot::IsAppearanceValid(); | 510 return CPDFSDK_BAAnnot::IsAppearanceValid(); |
511 } | 511 } |
512 | 512 |
513 int CPDFSDK_Widget::GetLayoutOrder() const { | 513 int CPDFSDK_Widget::GetLayoutOrder() const { |
514 return 2; | 514 return 2; |
515 } | 515 } |
516 | 516 |
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) | 1819 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) |
1820 pAPDict->RemoveFor(sAPType); | 1820 pAPDict->RemoveFor(sAPType); |
1821 } | 1821 } |
1822 | 1822 |
1823 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, | 1823 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
1824 PDFSDK_FieldAction& data, | 1824 PDFSDK_FieldAction& data, |
1825 CPDFSDK_PageView* pPageView) { | 1825 CPDFSDK_PageView* pPageView) { |
1826 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); | 1826 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
1827 | 1827 |
1828 #ifdef PDF_ENABLE_XFA | 1828 #ifdef PDF_ENABLE_XFA |
1829 CPDFXFA_Document* pDoc = pFormFillEnv->GetXFADocument(); | 1829 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
1830 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 1830 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
1831 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); | 1831 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
1832 | 1832 |
1833 if (eEventType != XFA_EVENT_Unknown) { | 1833 if (eEventType != XFA_EVENT_Unknown) { |
1834 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { | 1834 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
1835 CXFA_EventParam param; | 1835 CXFA_EventParam param; |
1836 param.m_eType = eEventType; | 1836 param.m_eType = eEventType; |
1837 param.m_wsChange = data.sChange; | 1837 param.m_wsChange = data.sChange; |
1838 param.m_iCommitKey = data.nCommitKey; | 1838 param.m_iCommitKey = data.nCommitKey; |
1839 param.m_bShift = data.bShift; | 1839 param.m_bShift = data.bShift; |
1840 param.m_iSelStart = data.nSelStart; | 1840 param.m_iSelStart = data.nSelStart; |
1841 param.m_iSelEnd = data.nSelEnd; | 1841 param.m_iSelEnd = data.nSelEnd; |
1842 param.m_wsFullText = data.sValue; | 1842 param.m_wsFullText = data.sValue; |
1843 param.m_bKeyDown = data.bKeyDown; | 1843 param.m_bKeyDown = data.bKeyDown; |
1844 param.m_bModifier = data.bModifier; | 1844 param.m_bModifier = data.bModifier; |
1845 param.m_wsNewText = data.sValue; | 1845 param.m_wsNewText = data.sValue; |
1846 if (data.nSelEnd > data.nSelStart) | 1846 if (data.nSelEnd > data.nSelStart) |
1847 param.m_wsNewText.Delete(data.nSelStart, | 1847 param.m_wsNewText.Delete(data.nSelStart, |
1848 data.nSelEnd - data.nSelStart); | 1848 data.nSelEnd - data.nSelStart); |
1849 for (int i = data.sChange.GetLength() - 1; i >= 0; i--) | 1849 for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
1850 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); | 1850 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
1851 param.m_wsPrevText = data.sValue; | 1851 param.m_wsPrevText = data.sValue; |
1852 | 1852 |
1853 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); | 1853 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
1854 param.m_pTarget = pAcc; | 1854 param.m_pTarget = pAcc; |
1855 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); | 1855 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
1856 | 1856 |
1857 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) | 1857 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
1858 pDocView->UpdateDocView(); | 1858 pDocView->UpdateDocView(); |
1859 | 1859 |
1860 if (nRet == XFA_EVENTERROR_Success) | 1860 if (nRet == XFA_EVENTERROR_Success) |
1861 return TRUE; | 1861 return TRUE; |
1862 } | 1862 } |
1863 } | 1863 } |
1864 } | 1864 } |
1865 #endif // PDF_ENABLE_XFA | 1865 #endif // PDF_ENABLE_XFA |
1866 | 1866 |
1867 CPDF_Action action = GetAAction(type); | 1867 CPDF_Action action = GetAAction(type); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1923 return FALSE; | 1923 return FALSE; |
1924 | 1924 |
1925 if (!IsVisible()) | 1925 if (!IsVisible()) |
1926 return FALSE; | 1926 return FALSE; |
1927 | 1927 |
1928 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) | 1928 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
1929 return FALSE; | 1929 return FALSE; |
1930 | 1930 |
1931 return TRUE; | 1931 return TRUE; |
1932 } | 1932 } |
OLD | NEW |