jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/cpdfsdk_widget.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 9 | #include <memory> |
Henrique Nakashima | ea8a624 | 2017-06-19 14:26:54 -0400 | [diff] [blame] | 10 | #include <sstream> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_array.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 14 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_stream.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 17 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 18 | #include "core/fpdfdoc/cpdf_defaultappearance.h" |
| 19 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 20 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 21 | #include "core/fpdfdoc/cpdf_iconfit.h" |
| 22 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 23 | #include "core/fxge/cfx_graphstatedata.h" |
| 24 | #include "core/fxge/cfx_pathdata.h" |
| 25 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 26 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 28 | #include "fpdfsdk/cpdfsdk_pageview.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 29 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 30 | #include "fpdfsdk/fsdk_actionhandler.h" |
| 31 | #include "fpdfsdk/fsdk_define.h" |
Dan Sinclair | c411eb9 | 2017-07-25 09:39:30 -0400 | [diff] [blame] | 32 | #include "fpdfsdk/pwl/cpwl_appstream.h" |
| 33 | #include "fpdfsdk/pwl/cpwl_edit.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 35 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 36 | #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 37 | #include "xfa/fxfa/cxfa_eventparam.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 38 | #include "xfa/fxfa/cxfa_ffdocview.h" |
| 39 | #include "xfa/fxfa/cxfa_ffwidget.h" |
| 40 | #include "xfa/fxfa/cxfa_ffwidgethandler.h" |
| 41 | #include "xfa/fxfa/cxfa_widgetacc.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 42 | #endif // PDF_ENABLE_XFA |
| 43 | |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 44 | namespace { |
| 45 | |
| 46 | // Convert a FX_ARGB to a FX_COLORREF. |
| 47 | FX_COLORREF ARGBToColorRef(FX_ARGB argb) { |
| 48 | return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) | |
| 49 | (static_cast<uint32_t>(argb) & 0x0000FF00) | |
| 50 | ((static_cast<uint32_t>(argb) & 0x000000FF) << 16)); |
| 51 | } |
| 52 | |
| 53 | } // namespace |
| 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 56 | CPDFSDK_PageView* pPageView, |
| 57 | CPDFSDK_InterForm* pInterForm) |
| 58 | : CPDFSDK_BAAnnot(pAnnot, pPageView), |
| 59 | m_pInterForm(pInterForm), |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 60 | m_nAppearanceAge(0), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 61 | m_nValueAge(0) |
| 62 | #ifdef PDF_ENABLE_XFA |
| 63 | , |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 64 | m_hMixXFAWidget(nullptr), |
| 65 | m_pWidgetHandler(nullptr) |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 66 | #endif // PDF_ENABLE_XFA |
| 67 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
| 69 | |
dsinclair | ce04a45 | 2016-09-07 05:46:55 -0700 | [diff] [blame] | 70 | CPDFSDK_Widget::~CPDFSDK_Widget() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 72 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 73 | CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 74 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 75 | if (pContext->GetFormType() == FormType::kXFAForeground) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | if (!m_hMixXFAWidget) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 77 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 78 | WideString sName; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 79 | if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 80 | sName = GetAnnotName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | if (sName.IsEmpty()) |
| 82 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 83 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 85 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | if (!sName.IsEmpty()) |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 88 | m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 90 | } |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 91 | return m_hMixXFAWidget.Get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | } |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 93 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | } |
| 95 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 96 | CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 97 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 98 | if (pContext->GetFormType() != FormType::kXFAForeground) |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 99 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 101 | CXFA_FFDocView* pDocView = pContext->GetXFADocView(); |
| 102 | if (!pDocView) |
| 103 | return nullptr; |
| 104 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 105 | WideString sName = GetName(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 106 | return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 107 | } |
| 108 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 109 | CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 110 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 111 | if (pContext->GetFormType() != FormType::kXFAForeground) |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 112 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 114 | if (!m_pWidgetHandler) { |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 115 | CXFA_FFDocView* pDocView = pContext->GetXFADocView(); |
| 116 | if (pDocView) |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 117 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
| 118 | } |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 119 | return m_pWidgetHandler.Get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 123 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 124 | |
| 125 | switch (eXFAAAT) { |
| 126 | case PDFSDK_XFA_Click: |
| 127 | eEventType = XFA_EVENT_Click; |
| 128 | break; |
| 129 | case PDFSDK_XFA_Full: |
| 130 | eEventType = XFA_EVENT_Full; |
| 131 | break; |
| 132 | case PDFSDK_XFA_PreOpen: |
| 133 | eEventType = XFA_EVENT_PreOpen; |
| 134 | break; |
| 135 | case PDFSDK_XFA_PostOpen: |
| 136 | eEventType = XFA_EVENT_PostOpen; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return eEventType; |
| 141 | } |
| 142 | |
| 143 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 144 | bool bWillCommit) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 146 | |
| 147 | switch (eAAT) { |
| 148 | case CPDF_AAction::CursorEnter: |
| 149 | eEventType = XFA_EVENT_MouseEnter; |
| 150 | break; |
| 151 | case CPDF_AAction::CursorExit: |
| 152 | eEventType = XFA_EVENT_MouseExit; |
| 153 | break; |
| 154 | case CPDF_AAction::ButtonDown: |
| 155 | eEventType = XFA_EVENT_MouseDown; |
| 156 | break; |
| 157 | case CPDF_AAction::ButtonUp: |
| 158 | eEventType = XFA_EVENT_MouseUp; |
| 159 | break; |
| 160 | case CPDF_AAction::GetFocus: |
| 161 | eEventType = XFA_EVENT_Enter; |
| 162 | break; |
| 163 | case CPDF_AAction::LoseFocus: |
| 164 | eEventType = XFA_EVENT_Exit; |
| 165 | break; |
| 166 | case CPDF_AAction::PageOpen: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | case CPDF_AAction::PageClose: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | case CPDF_AAction::PageVisible: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | case CPDF_AAction::PageInvisible: |
| 170 | break; |
| 171 | case CPDF_AAction::KeyStroke: |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 172 | if (!bWillCommit) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | eEventType = XFA_EVENT_Change; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | break; |
| 175 | case CPDF_AAction::Validate: |
| 176 | eEventType = XFA_EVENT_Validate; |
| 177 | break; |
| 178 | case CPDF_AAction::OpenPage: |
| 179 | case CPDF_AAction::ClosePage: |
| 180 | case CPDF_AAction::Format: |
| 181 | case CPDF_AAction::Calculate: |
| 182 | case CPDF_AAction::CloseDocument: |
| 183 | case CPDF_AAction::SaveDocument: |
| 184 | case CPDF_AAction::DocumentSaved: |
| 185 | case CPDF_AAction::PrintDocument: |
| 186 | case CPDF_AAction::DocumentPrinted: |
| 187 | break; |
Lei Zhang | 69fe711 | 2017-09-14 18:26:26 -0700 | [diff] [blame] | 188 | case CPDF_AAction::NumberOfActions: |
| 189 | NOTREACHED(); |
| 190 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | return eEventType; |
| 194 | } |
| 195 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 196 | bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 197 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 198 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 199 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 201 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 202 | if (!pXFAWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 203 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 205 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 206 | |
| 207 | CXFA_WidgetAcc* pAcc; |
| 208 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 209 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 210 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 211 | pAcc = hGroupWidget->GetDataAcc(); |
| 212 | if (pXFAWidgetHandler->HasEvent(pAcc, eEventType)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 213 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 217 | pAcc = hWidget->GetDataAcc(); |
| 218 | return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | } |
| 220 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 221 | bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 222 | PDFSDK_FieldAction& data, |
| 223 | CPDFSDK_PageView* pPageView) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 224 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 226 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 227 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 228 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 230 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 231 | if (eEventType == XFA_EVENT_Unknown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 232 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 234 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 235 | if (!pXFAWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 236 | return false; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 237 | |
| 238 | CXFA_EventParam param; |
| 239 | param.m_eType = eEventType; |
| 240 | param.m_wsChange = data.sChange; |
| 241 | param.m_iCommitKey = data.nCommitKey; |
| 242 | param.m_bShift = data.bShift; |
| 243 | param.m_iSelStart = data.nSelStart; |
| 244 | param.m_iSelEnd = data.nSelEnd; |
| 245 | param.m_wsFullText = data.sValue; |
| 246 | param.m_bKeyDown = data.bKeyDown; |
| 247 | param.m_bModifier = data.bModifier; |
| 248 | param.m_wsNewText = data.sValue; |
| 249 | if (data.nSelEnd > data.nSelStart) |
| 250 | param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart); |
| 251 | |
Tom Sepez | 3c3e271 | 2017-04-17 15:38:19 -0700 | [diff] [blame] | 252 | for (const auto& c : data.sChange) |
| 253 | param.m_wsNewText.Insert(data.nSelStart, c); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 254 | |
Tom Sepez | 3c3e271 | 2017-04-17 15:38:19 -0700 | [diff] [blame] | 255 | param.m_wsPrevText = data.sValue; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 256 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 257 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 258 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 259 | CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc(); |
| 260 | param.m_pTarget = pAcc; |
| 261 | if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
| 262 | XFA_EVENTERROR_Success) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 263 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 267 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
| 268 | param.m_pTarget = pAcc; |
| 269 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 271 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 272 | pDocView->UpdateDocView(); |
| 273 | |
| 274 | return nRet == XFA_EVENTERROR_Success; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | } |
| 276 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 277 | void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 278 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 279 | if (!hWidget) |
| 280 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 282 | CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
| 283 | if (!pWidgetAcc) |
| 284 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 286 | CPDF_FormField* pFormField = GetFormField(); |
| 287 | switch (GetFieldType()) { |
| 288 | case FIELDTYPE_CHECKBOX: |
| 289 | case FIELDTYPE_RADIOBUTTON: { |
| 290 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 291 | XFA_CHECKSTATE eCheckState = |
| 292 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
| 293 | pWidgetAcc->SetCheckState(eCheckState, true); |
| 294 | break; |
| 295 | } |
| 296 | case FIELDTYPE_TEXTFIELD: |
| 297 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 298 | break; |
| 299 | case FIELDTYPE_LISTBOX: { |
| 300 | pWidgetAcc->ClearAllSelections(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 302 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 303 | int nIndex = pFormField->GetSelectedIndex(i); |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 304 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 305 | pWidgetAcc->SetItemState(nIndex, true, false, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | } |
| 309 | case FIELDTYPE_COMBOBOX: { |
| 310 | pWidgetAcc->ClearAllSelections(); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 311 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 312 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 313 | int nIndex = pFormField->GetSelectedIndex(i); |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 314 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 315 | pWidgetAcc->SetItemState(nIndex, true, false, false, true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 316 | } |
| 317 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 318 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 321 | |
| 322 | if (bSynchronizeElse) |
| 323 | pWidgetAcc->ProcessValueChanged(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void CPDFSDK_Widget::SynchronizeXFAValue() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 327 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
| 328 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 329 | if (!pXFADocView) |
| 330 | return; |
| 331 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 332 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 333 | if (GetXFAWidgetHandler()) { |
| 334 | CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
| 335 | GetFormControl()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void CPDFSDK_Widget::SynchronizeXFAItems() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 341 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
| 342 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | if (!pXFADocView) |
| 344 | return; |
| 345 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 346 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 347 | if (GetXFAWidgetHandler()) |
| 348 | SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 352 | void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
| 353 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | CPDF_FormField* pFormField, |
| 355 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 356 | ASSERT(hWidget); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 357 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 359 | switch (pFormField->GetFieldType()) { |
| 360 | case FIELDTYPE_CHECKBOX: { |
| 361 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 362 | pFormField->CheckControl( |
| 363 | pFormField->GetControlIndex(pFormControl), |
| 364 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 365 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 366 | break; |
| 367 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 368 | case FIELDTYPE_RADIOBUTTON: { |
| 369 | // TODO(weili): Check whether we need to handle checkbox and radio |
| 370 | // button differently, otherwise, merge these two cases. |
| 371 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 372 | pFormField->CheckControl( |
| 373 | pFormField->GetControlIndex(pFormControl), |
| 374 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 375 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 376 | break; |
| 377 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 378 | case FIELDTYPE_TEXTFIELD: { |
| 379 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 380 | WideString sValue; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 381 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 382 | pFormField->SetValue(sValue, true); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 383 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 384 | break; |
| 385 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 386 | case FIELDTYPE_LISTBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 387 | pFormField->ClearSelection(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 388 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 389 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 390 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 391 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 393 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 394 | pFormField->SetItemSelection(nIndex, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | } |
| 396 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 397 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 398 | break; |
| 399 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 400 | case FIELDTYPE_COMBOBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 401 | pFormField->ClearSelection(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 403 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 404 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 405 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 406 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 407 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 408 | pFormField->SetItemSelection(nIndex, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 409 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 411 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 412 | WideString sValue; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 413 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 414 | pFormField->SetValue(sValue, true); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 415 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 416 | break; |
| 417 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 421 | void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, |
| 422 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | CPDF_FormField* pFormField, |
| 424 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 425 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 426 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 427 | switch (pFormField->GetFieldType()) { |
| 428 | case FIELDTYPE_LISTBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 429 | pFormField->ClearSelection(false); |
| 430 | pFormField->ClearOptions(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 431 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 432 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 433 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz; |
| 434 | i++) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 435 | WideString swText; |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 436 | pWidgetAcc->GetChoiceListItem(swText, i, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 438 | pFormField->InsertOption(swText, i, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 440 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 441 | break; |
| 442 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 443 | case FIELDTYPE_COMBOBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 444 | pFormField->ClearSelection(false); |
| 445 | pFormField->ClearOptions(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 447 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 448 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz; |
| 449 | i++) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 450 | WideString swText; |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 451 | pWidgetAcc->GetChoiceListItem(swText, i, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 453 | pFormField->InsertOption(swText, i, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 455 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 457 | pFormField->SetValue(L"", true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 458 | break; |
| 459 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | } |
| 461 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 462 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 464 | bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 465 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | if (!pAP) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 467 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 468 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | // Choose the right sub-ap |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 470 | const char* ap_entry = "N"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | if (mode == CPDF_Annot::Down) |
| 472 | ap_entry = "D"; |
| 473 | else if (mode == CPDF_Annot::Rollover) |
| 474 | ap_entry = "R"; |
| 475 | if (!pAP->KeyExist(ap_entry)) |
| 476 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 477 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | // Get the AP stream or subdirectory |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 479 | CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 480 | if (!psub) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 481 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 482 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 483 | int nFieldType = GetFieldType(); |
| 484 | switch (nFieldType) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 485 | case FIELDTYPE_PUSHBUTTON: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 486 | case FIELDTYPE_COMBOBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 487 | case FIELDTYPE_LISTBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 488 | case FIELDTYPE_TEXTFIELD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 489 | case FIELDTYPE_SIGNATURE: |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 490 | return psub->IsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 491 | case FIELDTYPE_CHECKBOX: |
| 492 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 493 | if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 494 | return !!pSubDict->GetStreamFor(GetAppState()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 496 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 498 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | int CPDFSDK_Widget::GetFieldType() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 502 | CPDF_FormField* pField = GetFormField(); |
| 503 | return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 504 | } |
| 505 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 506 | bool CPDFSDK_Widget::IsAppearanceValid() { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 507 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 508 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Ryan Harrison | 854d71c | 2017-10-18 12:28:14 -0400 | [diff] [blame] | 509 | FormType formType = pContext->GetFormType(); |
| 510 | if (formType == FormType::kXFAFull) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 511 | return true; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 512 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 513 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | } |
| 515 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 516 | int CPDFSDK_Widget::GetLayoutOrder() const { |
| 517 | return 2; |
| 518 | } |
| 519 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 520 | int CPDFSDK_Widget::GetFieldFlags() const { |
| 521 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | CPDF_FormControl* pFormControl = |
| 523 | pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); |
| 524 | CPDF_FormField* pFormField = pFormControl->GetField(); |
| 525 | return pFormField->GetFieldFlags(); |
| 526 | } |
| 527 | |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 528 | bool CPDFSDK_Widget::IsSignatureWidget() const { |
| 529 | return GetFieldType() == FIELDTYPE_SIGNATURE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 533 | CPDF_FormControl* pControl = GetFormControl(); |
| 534 | return pControl ? pControl->GetField() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 539 | return pPDFInterForm->GetControlByDict(GetAnnotDict()); |
| 540 | } |
| 541 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 542 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl( |
| 543 | CPDF_InterForm* pInterForm, |
| 544 | const CPDF_Dictionary* pAnnotDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 545 | ASSERT(pAnnotDict); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 546 | return pInterForm->GetControlByDict(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | int CPDFSDK_Widget::GetRotate() const { |
| 550 | CPDF_FormControl* pCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 551 | return pCtrl->GetRotation() % 360; |
| 552 | } |
| 553 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 554 | #ifdef PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 555 | WideString CPDFSDK_Widget::GetName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | return pFormField->GetFullName(); |
| 558 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 559 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 560 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 561 | bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 562 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 563 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 564 | color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 565 | return iColorType != CFX_Color::kTransparent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 566 | } |
| 567 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 568 | bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 571 | color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType)); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 572 | return iColorType != CFX_Color::kTransparent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 573 | } |
| 574 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 575 | bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 577 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 578 | if (!da.HasColor()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 579 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 581 | FX_ARGB argb; |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 582 | int iColorType = CFX_Color::kTransparent; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 583 | da.GetColor(argb, iColorType); |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 584 | color = ARGBToColorRef(argb); |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 585 | return iColorType != CFX_Color::kTransparent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 588 | float CPDFSDK_Widget::GetFontSize() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 589 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 591 | float fFontSize; |
| 592 | pDa.GetFont(&fFontSize); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | return fFontSize; |
| 594 | } |
| 595 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 596 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 597 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 598 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 599 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 600 | if (nIndex < pWidgetAcc->CountSelectedItems()) |
| 601 | return pWidgetAcc->GetSelectedItem(nIndex); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 602 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 604 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 605 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | return pFormField->GetSelectedIndex(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 609 | #ifdef PDF_ENABLE_XFA |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 610 | WideString CPDFSDK_Widget::GetValue(bool bDisplay) const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 611 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 612 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 613 | WideString sValue; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 614 | pWidgetAcc->GetValue( |
| 615 | sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit); |
| 616 | return sValue; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 617 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 619 | #else |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 620 | WideString CPDFSDK_Widget::GetValue() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 621 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | return pFormField->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 626 | WideString CPDFSDK_Widget::GetDefaultValue() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 627 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | return pFormField->GetDefaultValue(); |
| 629 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 630 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 631 | WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 632 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | return pFormField->GetOptionLabel(nIndex); |
| 634 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | int CPDFSDK_Widget::CountOptions() const { |
| 637 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | return pFormField->CountOptions(); |
| 639 | } |
| 640 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 641 | bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 642 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 643 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 644 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
Tom Sepez | 5c500ac | 2017-03-27 12:44:20 -0700 | [diff] [blame] | 645 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false)) |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 646 | return pWidgetAcc->GetItemState(nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 647 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 648 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 651 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 652 | CPDF_FormField* pFormField = GetFormField(); |
| 653 | return pFormField->IsItemSelected(nIndex); |
| 654 | } |
| 655 | |
| 656 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 657 | CPDF_FormField* pFormField = GetFormField(); |
| 658 | return pFormField->GetTopVisibleIndex(); |
| 659 | } |
| 660 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 661 | bool CPDFSDK_Widget::IsChecked() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 662 | #ifdef PDF_ENABLE_XFA |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 663 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 664 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) |
| 665 | return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 666 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 667 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 669 | return pFormCtrl->IsChecked(); |
| 670 | } |
| 671 | |
| 672 | int CPDFSDK_Widget::GetAlignment() const { |
| 673 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 674 | return pFormCtrl->GetControlAlignment(); |
| 675 | } |
| 676 | |
| 677 | int CPDFSDK_Widget::GetMaxLen() const { |
| 678 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | return pFormField->GetMaxLen(); |
| 680 | } |
| 681 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 682 | void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
| 686 | bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 687 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 689 | ResetAppearance(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 691 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 692 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 695 | void CPDFSDK_Widget::SetValue(const WideString& sValue, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 696 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | pFormField->SetValue(sValue, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 698 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 699 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 700 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 701 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 704 | void CPDFSDK_Widget::SetDefaultValue(const WideString& sValue) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 705 | void CPDFSDK_Widget::SetOptionSelection(int index, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 706 | bool bSelected, |
| 707 | bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | pFormField->SetItemSelection(index, bSelected, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 710 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 712 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 713 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 714 | } |
| 715 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 716 | void CPDFSDK_Widget::ClearSelection(bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 717 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | pFormField->ClearSelection(bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 719 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 720 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 721 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 722 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 726 | |
| 727 | void CPDFSDK_Widget::SetAppModified() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 728 | m_bAppModified = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | void CPDFSDK_Widget::ClearAppModified() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 732 | m_bAppModified = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 733 | } |
| 734 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 735 | bool CPDFSDK_Widget::IsAppModified() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | return m_bAppModified; |
| 737 | } |
| 738 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 739 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 740 | void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 741 | switch (GetFieldType()) { |
| 742 | case FIELDTYPE_TEXTFIELD: |
| 743 | case FIELDTYPE_COMBOBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 744 | bool bFormatted = false; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 745 | WideString sValue = OnFormat(bFormatted); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 746 | ResetAppearance(bFormatted ? &sValue : nullptr, true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 747 | break; |
| 748 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 750 | ResetAppearance(nullptr, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | break; |
| 752 | } |
| 753 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 754 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 755 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 756 | void CPDFSDK_Widget::ResetAppearance(const WideString* sValue, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 757 | bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | SetAppModified(); |
| 759 | |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 760 | m_nAppearanceAge++; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | if (bValueChanged) |
| 762 | m_nValueAge++; |
| 763 | |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 764 | CPWL_AppStream appStream(this, GetAPDict()); |
| 765 | switch (GetFieldType()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 766 | case FIELDTYPE_PUSHBUTTON: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 767 | appStream.SetAsPushButton(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 768 | break; |
| 769 | case FIELDTYPE_CHECKBOX: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 770 | appStream.SetAsCheckBox(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 771 | break; |
| 772 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 773 | appStream.SetAsRadioButton(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | break; |
| 775 | case FIELDTYPE_COMBOBOX: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 776 | appStream.SetAsComboBox(sValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | break; |
| 778 | case FIELDTYPE_LISTBOX: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 779 | appStream.SetAsListBox(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 780 | break; |
| 781 | case FIELDTYPE_TEXTFIELD: |
Dan Sinclair | cb2ea42 | 2017-07-19 15:24:49 -0400 | [diff] [blame] | 782 | appStream.SetAsTextField(sValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 783 | break; |
| 784 | } |
| 785 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 786 | m_pAnnot->ClearCachedAP(); |
| 787 | } |
| 788 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 789 | WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 790 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 791 | ASSERT(pFormField); |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 792 | return m_pInterForm->OnFormat(pFormField, bFormatted); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | } |
| 794 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 795 | void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 797 | ASSERT(pFormField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 798 | m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 802 | const CFX_Matrix& mtUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 803 | CPDF_Annot::AppearanceMode mode, |
| 804 | const CPDF_RenderOptions* pOptions) { |
| 805 | int nFieldType = GetFieldType(); |
| 806 | |
| 807 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 808 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 809 | mode == CPDF_Annot::Normal && |
| 810 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 811 | CFX_PathData pathData; |
| 812 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 813 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 814 | |
| 815 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 816 | rcAnnot.top); |
| 817 | |
| 818 | CFX_GraphStateData gsd; |
| 819 | gsd.m_LineWidth = 0.0f; |
| 820 | |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 821 | pDevice->DrawPath(&pathData, &mtUser2Device, &gsd, 0, 0xFFAAAAAA, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 822 | FXFILL_ALTERNATE); |
| 823 | } else { |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 824 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, mtUser2Device, mode, pOptions); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
| 828 | void CPDFSDK_Widget::UpdateField() { |
| 829 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 830 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 831 | m_pInterForm->UpdateField(pFormField); |
| 832 | } |
| 833 | |
| 834 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 835 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 836 | int nFieldType = GetFieldType(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 837 | if (!m_pInterForm->IsNeedHighLight(nFieldType)) |
| 838 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 840 | CFX_Matrix page2device; |
| 841 | pPageView->GetCurrentMatrix(page2device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 843 | CFX_FloatRect rcDevice = GetRect(); |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 844 | CFX_PointF tmp = |
| 845 | page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom)); |
| 846 | rcDevice.left = tmp.x; |
| 847 | rcDevice.bottom = tmp.y; |
| 848 | |
| 849 | tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top)); |
| 850 | rcDevice.right = tmp.x; |
| 851 | rcDevice.top = tmp.y; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 852 | rcDevice.Normalize(); |
| 853 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 854 | FX_RECT rcDev = rcDevice.ToFxRect(); |
| 855 | pDevice->FillRect( |
| 856 | &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()), |
| 857 | m_pInterForm->GetHighlightColor(nFieldType))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 860 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 861 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 862 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 863 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 864 | case BorderStyle::BEVELED: |
| 865 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | fBorderWidth *= 2.0f; |
| 867 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 868 | default: |
| 869 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 870 | } |
dan sinclair | d6aff2f | 2017-07-13 21:36:29 -0400 | [diff] [blame] | 871 | return rcWindow.GetDeflated(fBorderWidth, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 874 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 875 | CFX_FloatRect rectAnnot = GetRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 876 | float fWidth = rectAnnot.right - rectAnnot.left; |
| 877 | float fHeight = rectAnnot.top - rectAnnot.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | |
| 879 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 880 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 881 | switch (abs(pControl->GetRotation() % 360)) { |
| 882 | case 0: |
| 883 | case 180: |
| 884 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 885 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | break; |
| 887 | case 90: |
| 888 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 889 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | break; |
| 891 | } |
| 892 | |
| 893 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 896 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 897 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 898 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 899 | CFX_FloatRect rcAnnot = GetRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 900 | float fWidth = rcAnnot.right - rcAnnot.left; |
| 901 | float fHeight = rcAnnot.top - rcAnnot.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | |
| 903 | switch (abs(pControl->GetRotation() % 360)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | default: |
Lei Zhang | 0a91394 | 2017-06-01 01:37:51 -0700 | [diff] [blame] | 905 | case 0: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 906 | break; |
| 907 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 908 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 909 | break; |
| 910 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 911 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 912 | break; |
| 913 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 914 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | break; |
| 916 | } |
| 917 | |
| 918 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 921 | CFX_Color CPDFSDK_Widget::GetTextPWLColor() const { |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 922 | CFX_Color crText = CFX_Color(CFX_Color::kGray, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 923 | |
| 924 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 926 | if (da.HasColor()) { |
| 927 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 928 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 929 | da.GetColor(iColorType, fc); |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 930 | crText = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 936 | CFX_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 937 | CFX_Color crBorder; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 938 | |
| 939 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 940 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 941 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 942 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 943 | if (iColorType > 0) |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 944 | crBorder = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 945 | |
| 946 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 949 | CFX_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 950 | CFX_Color crFill; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | |
| 952 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 953 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 954 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 956 | if (iColorType > 0) |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 957 | crFill = CFX_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | |
| 959 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 960 | } |
| 961 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 962 | bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 963 | PDFSDK_FieldAction& data, |
| 964 | CPDFSDK_PageView* pPageView) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 965 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 967 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 968 | CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 969 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 970 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 971 | |
| 972 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 973 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | CXFA_EventParam param; |
| 975 | param.m_eType = eEventType; |
| 976 | param.m_wsChange = data.sChange; |
| 977 | param.m_iCommitKey = data.nCommitKey; |
| 978 | param.m_bShift = data.bShift; |
| 979 | param.m_iSelStart = data.nSelStart; |
| 980 | param.m_iSelEnd = data.nSelEnd; |
| 981 | param.m_wsFullText = data.sValue; |
| 982 | param.m_bKeyDown = data.bKeyDown; |
| 983 | param.m_bModifier = data.bModifier; |
| 984 | param.m_wsNewText = data.sValue; |
| 985 | if (data.nSelEnd > data.nSelStart) |
| 986 | param.m_wsNewText.Delete(data.nSelStart, |
| 987 | data.nSelEnd - data.nSelStart); |
| 988 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 989 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 990 | param.m_wsPrevText = data.sValue; |
| 991 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 992 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | param.m_pTarget = pAcc; |
| 994 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 995 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 996 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 997 | pDocView->UpdateDocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 998 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 999 | if (nRet == XFA_EVENTERROR_Success) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1000 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1004 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1005 | |
| 1006 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1007 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
Lei Zhang | cddc8ed | 2017-06-20 17:26:44 -0700 | [diff] [blame] | 1008 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); |
dsinclair | 19c198b | 2016-10-11 12:51:37 -0700 | [diff] [blame] | 1009 | return pActionHandler->DoAction_Field(action, type, pFormFillEnv, |
| 1010 | GetFormField(), data); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1012 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1016 | switch (eAAT) { |
| 1017 | case CPDF_AAction::CursorEnter: |
| 1018 | case CPDF_AAction::CursorExit: |
| 1019 | case CPDF_AAction::ButtonDown: |
| 1020 | case CPDF_AAction::ButtonUp: |
| 1021 | case CPDF_AAction::GetFocus: |
| 1022 | case CPDF_AAction::LoseFocus: |
| 1023 | case CPDF_AAction::PageOpen: |
| 1024 | case CPDF_AAction::PageClose: |
| 1025 | case CPDF_AAction::PageVisible: |
| 1026 | case CPDF_AAction::PageInvisible: |
| 1027 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1028 | |
| 1029 | case CPDF_AAction::KeyStroke: |
| 1030 | case CPDF_AAction::Format: |
| 1031 | case CPDF_AAction::Validate: |
| 1032 | case CPDF_AAction::Calculate: { |
| 1033 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1034 | if (pField->GetAdditionalAction().GetDict()) |
| 1035 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1036 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1037 | } |
| 1038 | default: |
| 1039 | break; |
| 1040 | } |
| 1041 | |
| 1042 | return CPDF_Action(); |
| 1043 | } |
| 1044 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 1045 | WideString CPDFSDK_Widget::GetAlternateName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1046 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1047 | return pFormField->GetAlternateName(); |
| 1048 | } |