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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 m_hMixXFAWidget(nullptr), | 62 m_hMixXFAWidget(nullptr), |
63 m_pWidgetHandler(nullptr) | 63 m_pWidgetHandler(nullptr) |
64 #endif // PDF_ENABLE_XFA | 64 #endif // PDF_ENABLE_XFA |
65 { | 65 { |
66 } | 66 } |
67 | 67 |
68 CPDFSDK_Widget::~CPDFSDK_Widget() {} | 68 CPDFSDK_Widget::~CPDFSDK_Widget() {} |
69 | 69 |
70 #ifdef PDF_ENABLE_XFA | 70 #ifdef PDF_ENABLE_XFA |
71 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { | 71 CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
72 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 72 CPDFXFA_Document* pDoc = |
73 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 73 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
74 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 74 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
75 if (!m_hMixXFAWidget) { | 75 if (!m_hMixXFAWidget) { |
76 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { | 76 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
77 CFX_WideString sName; | 77 CFX_WideString sName; |
78 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { | 78 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
79 sName = GetAnnotName(); | 79 sName = GetAnnotName(); |
80 if (sName.IsEmpty()) | 80 if (sName.IsEmpty()) |
81 sName = GetName(); | 81 sName = GetName(); |
82 } else { | 82 } else { |
83 sName = GetName(); | 83 sName = GetName(); |
84 } | 84 } |
85 | 85 |
86 if (!sName.IsEmpty()) | 86 if (!sName.IsEmpty()) |
87 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); | 87 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); |
88 } | 88 } |
89 } | 89 } |
90 return m_hMixXFAWidget; | 90 return m_hMixXFAWidget; |
91 } | 91 } |
92 | 92 |
93 return nullptr; | 93 return nullptr; |
94 } | 94 } |
95 | 95 |
96 CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { | 96 CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
97 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 97 CPDFXFA_Document* pDoc = |
98 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 98 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
99 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 99 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
100 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { | 100 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
101 CFX_WideString sName = GetName(); | 101 CFX_WideString sName = GetName(); |
102 if (!sName.IsEmpty()) | 102 if (!sName.IsEmpty()) |
103 return pDocView->GetWidgetByName(sName, nullptr); | 103 return pDocView->GetWidgetByName(sName, nullptr); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 return nullptr; | 107 return nullptr; |
108 } | 108 } |
109 | 109 |
110 CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { | 110 CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
111 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 111 CPDFXFA_Document* pDoc = |
112 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 112 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
113 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { | 113 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
114 if (!m_pWidgetHandler) { | 114 if (!m_pWidgetHandler) { |
115 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) | 115 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) |
116 m_pWidgetHandler = pDocView->GetWidgetHandler(); | 116 m_pWidgetHandler = pDocView->GetWidgetHandler(); |
117 } | 117 } |
118 return m_pWidgetHandler; | 118 return m_pWidgetHandler; |
119 } | 119 } |
120 | 120 |
121 return nullptr; | 121 return nullptr; |
122 } | 122 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 pAcc = hWidget->GetDataAcc(); | 219 pAcc = hWidget->GetDataAcc(); |
220 return pXFAWidgetHandler->HasEvent(pAcc, eEventType); | 220 return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
221 } | 221 } |
222 | 222 |
223 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, | 223 FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
224 PDFSDK_FieldAction& data, | 224 PDFSDK_FieldAction& data, |
225 CPDFSDK_PageView* pPageView) { | 225 CPDFSDK_PageView* pPageView) { |
226 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 226 CPDFXFA_Document* pDoc = |
227 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 227 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
228 | 228 |
229 CXFA_FFWidget* hWidget = GetMixXFAWidget(); | 229 CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
230 if (!hWidget) | 230 if (!hWidget) |
231 return FALSE; | 231 return FALSE; |
232 | 232 |
233 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); | 233 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
234 if (eEventType == XFA_EVENT_Unknown) | 234 if (eEventType == XFA_EVENT_Unknown) |
235 return FALSE; | 235 return FALSE; |
236 | 236 |
237 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); | 237 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); | 320 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
321 break; | 321 break; |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 if (bSynchronizeElse) | 325 if (bSynchronizeElse) |
326 pWidgetAcc->ProcessValueChanged(); | 326 pWidgetAcc->ProcessValueChanged(); |
327 } | 327 } |
328 | 328 |
329 void CPDFSDK_Widget::SynchronizeXFAValue() { | 329 void CPDFSDK_Widget::SynchronizeXFAValue() { |
330 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 330 CPDFXFA_Document* pDoc = |
331 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 331 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
332 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); | 332 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
333 if (!pXFADocView) | 333 if (!pXFADocView) |
334 return; | 334 return; |
335 | 335 |
336 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 336 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
337 if (GetXFAWidgetHandler()) { | 337 if (GetXFAWidgetHandler()) { |
338 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), | 338 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
339 GetFormControl()); | 339 GetFormControl()); |
340 } | 340 } |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 void CPDFSDK_Widget::SynchronizeXFAItems() { | 344 void CPDFSDK_Widget::SynchronizeXFAItems() { |
345 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 345 CPDFXFA_Document* pDoc = |
346 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 346 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
347 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); | 347 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
348 if (!pXFADocView) | 348 if (!pXFADocView) |
349 return; | 349 return; |
350 | 350 |
351 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 351 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
352 if (GetXFAWidgetHandler()) | 352 if (GetXFAWidgetHandler()) |
353 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); | 353 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
354 } | 354 } |
355 } | 355 } |
356 | 356 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 return TRUE; | 502 return TRUE; |
503 } | 503 } |
504 | 504 |
505 int CPDFSDK_Widget::GetFieldType() const { | 505 int CPDFSDK_Widget::GetFieldType() const { |
506 CPDF_FormField* pField = GetFormField(); | 506 CPDF_FormField* pField = GetFormField(); |
507 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; | 507 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; |
508 } | 508 } |
509 | 509 |
510 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { | 510 FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { |
511 #ifdef PDF_ENABLE_XFA | 511 #ifdef PDF_ENABLE_XFA |
512 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); | 512 CPDFXFA_Document* pDoc = |
513 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); | 513 m_pPageView->GetFormFillEnv()->GetSDKDocument()->GetXFADocument(); |
514 int nDocType = pDoc->GetDocType(); | 514 int nDocType = pDoc->GetDocType(); |
515 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) | 515 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
516 return TRUE; | 516 return TRUE; |
517 #endif // PDF_ENABLE_XFA | 517 #endif // PDF_ENABLE_XFA |
518 return CPDFSDK_BAAnnot::IsAppearanceValid(); | 518 return CPDFSDK_BAAnnot::IsAppearanceValid(); |
519 } | 519 } |
520 | 520 |
521 int CPDFSDK_Widget::GetLayoutOrder() const { | 521 int CPDFSDK_Widget::GetLayoutOrder() const { |
522 return 2; | 522 return 2; |
523 } | 523 } |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 CPDFSDK_PageView* pPageView) { | 845 CPDFSDK_PageView* pPageView) { |
846 int nFieldType = GetFieldType(); | 846 int nFieldType = GetFieldType(); |
847 if (!m_pInterForm->IsNeedHighLight(nFieldType)) | 847 if (!m_pInterForm->IsNeedHighLight(nFieldType)) |
848 return; | 848 return; |
849 | 849 |
850 CFX_FloatRect rc = GetRect(); | 850 CFX_FloatRect rc = GetRect(); |
851 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType); | 851 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType); |
852 uint8_t alpha = m_pInterForm->GetHighlightAlpha(); | 852 uint8_t alpha = m_pInterForm->GetHighlightAlpha(); |
853 | 853 |
854 CFX_FloatRect rcDevice; | 854 CFX_FloatRect rcDevice; |
855 CPDFSDK_FormFillEnvironment* pEnv = m_pInterForm->GetFormFillEnv(); | |
856 if (!pEnv) | |
857 return; | |
858 | |
859 CFX_Matrix page2device; | 855 CFX_Matrix page2device; |
860 pPageView->GetCurrentMatrix(page2device); | 856 pPageView->GetCurrentMatrix(page2device); |
861 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), | 857 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), |
862 rcDevice.left, rcDevice.bottom); | 858 rcDevice.left, rcDevice.bottom); |
863 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), | 859 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), |
864 rcDevice.right, rcDevice.top); | 860 rcDevice.right, rcDevice.top); |
865 | 861 |
866 rcDevice.Normalize(); | 862 rcDevice.Normalize(); |
867 | 863 |
868 FX_ARGB argb = ArgbEncode((int)alpha, color); | 864 FX_ARGB argb = ArgbEncode((int)alpha, color); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 } | 1824 } |
1829 | 1825 |
1830 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { | 1826 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
1831 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) | 1827 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) |
1832 pAPDict->RemoveFor(sAPType); | 1828 pAPDict->RemoveFor(sAPType); |
1833 } | 1829 } |
1834 | 1830 |
1835 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, | 1831 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
1836 PDFSDK_FieldAction& data, | 1832 PDFSDK_FieldAction& data, |
1837 CPDFSDK_PageView* pPageView) { | 1833 CPDFSDK_PageView* pPageView) { |
1838 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); | 1834 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
1839 CPDFSDK_FormFillEnvironment* pEnv = pDocument->GetEnv(); | |
1840 | 1835 |
1841 #ifdef PDF_ENABLE_XFA | 1836 #ifdef PDF_ENABLE_XFA |
1842 CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); | 1837 CPDFXFA_Document* pDoc = pFormFillEnv->GetSDKDocument()->GetXFADocument(); |
1843 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { | 1838 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
1844 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); | 1839 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
1845 | 1840 |
1846 if (eEventType != XFA_EVENT_Unknown) { | 1841 if (eEventType != XFA_EVENT_Unknown) { |
1847 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { | 1842 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
1848 CXFA_EventParam param; | 1843 CXFA_EventParam param; |
1849 param.m_eType = eEventType; | 1844 param.m_eType = eEventType; |
1850 param.m_wsChange = data.sChange; | 1845 param.m_wsChange = data.sChange; |
1851 param.m_iCommitKey = data.nCommitKey; | 1846 param.m_iCommitKey = data.nCommitKey; |
1852 param.m_bShift = data.bShift; | 1847 param.m_bShift = data.bShift; |
(...skipping 19 matching lines...) Expand all Loading... |
1872 | 1867 |
1873 if (nRet == XFA_EVENTERROR_Success) | 1868 if (nRet == XFA_EVENTERROR_Success) |
1874 return TRUE; | 1869 return TRUE; |
1875 } | 1870 } |
1876 } | 1871 } |
1877 } | 1872 } |
1878 #endif // PDF_ENABLE_XFA | 1873 #endif // PDF_ENABLE_XFA |
1879 | 1874 |
1880 CPDF_Action action = GetAAction(type); | 1875 CPDF_Action action = GetAAction(type); |
1881 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { | 1876 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
1882 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 1877 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
1883 return pActionHandler->DoAction_Field(action, type, pDocument, | 1878 return pActionHandler->DoAction_Field( |
1884 GetFormField(), data); | 1879 action, type, pFormFillEnv->GetSDKDocument(), GetFormField(), data); |
1885 } | 1880 } |
1886 return FALSE; | 1881 return FALSE; |
1887 } | 1882 } |
1888 | 1883 |
1889 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { | 1884 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
1890 switch (eAAT) { | 1885 switch (eAAT) { |
1891 case CPDF_AAction::CursorEnter: | 1886 case CPDF_AAction::CursorEnter: |
1892 case CPDF_AAction::CursorExit: | 1887 case CPDF_AAction::CursorExit: |
1893 case CPDF_AAction::ButtonDown: | 1888 case CPDF_AAction::ButtonDown: |
1894 case CPDF_AAction::ButtonUp: | 1889 case CPDF_AAction::ButtonUp: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 return FALSE; | 1931 return FALSE; |
1937 | 1932 |
1938 if (!IsVisible()) | 1933 if (!IsVisible()) |
1939 return FALSE; | 1934 return FALSE; |
1940 | 1935 |
1941 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) | 1936 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
1942 return FALSE; | 1937 return FALSE; |
1943 | 1938 |
1944 return TRUE; | 1939 return TRUE; |
1945 } | 1940 } |
OLD | NEW |