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> |
| 10 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 11 | #include "core/fpdfapi/parser/cpdf_array.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 12 | #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 13 | #include "core/fpdfapi/parser/cpdf_document.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 14 | #include "core/fpdfapi/parser/cpdf_reference.h" |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/parser/cpdf_stream.h" |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 16 | #include "core/fpdfapi/parser/cpdf_string.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 17 | #include "core/fpdfdoc/cpdf_defaultappearance.h" |
| 18 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 19 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 20 | #include "core/fpdfdoc/cpdf_iconfit.h" |
| 21 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 22 | #include "core/fxge/cfx_graphstatedata.h" |
| 23 | #include "core/fxge/cfx_pathdata.h" |
| 24 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 26 | #include "fpdfsdk/cpdfsdk_interform.h" |
| 27 | #include "fpdfsdk/cpdfsdk_pageview.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 28 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 29 | #include "fpdfsdk/fsdk_actionhandler.h" |
| 30 | #include "fpdfsdk/fsdk_define.h" |
dsinclair | 0bb385b | 2016-09-29 17:03:59 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/fxedit/fxet_edit.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 32 | #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 33 | #include "fpdfsdk/pdfwindow/PWL_Utils.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), |
| 60 | m_nAppAge(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(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 75 | if (pContext->GetDocType() == XFA_DocType::Static) { |
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()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | CFX_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 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | return m_hMixXFAWidget; |
| 92 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 93 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 94 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | } |
| 96 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 97 | CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 98 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 99 | if (pContext->GetDocType() != XFA_DocType::Static) |
| 100 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 102 | CXFA_FFDocView* pDocView = pContext->GetXFADocView(); |
| 103 | if (!pDocView) |
| 104 | return nullptr; |
| 105 | |
| 106 | CFX_WideString sName = GetName(); |
| 107 | return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | } |
| 109 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 110 | CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 111 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 112 | if (pContext->GetDocType() != XFA_DocType::Static) |
| 113 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 115 | if (!m_pWidgetHandler) { |
| 116 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
| 117 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
| 118 | } |
| 119 | return m_pWidgetHandler; |
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: |
| 167 | break; |
| 168 | case CPDF_AAction::PageClose: |
| 169 | break; |
| 170 | case CPDF_AAction::PageVisible: |
| 171 | break; |
| 172 | case CPDF_AAction::PageInvisible: |
| 173 | break; |
| 174 | case CPDF_AAction::KeyStroke: |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 175 | if (!bWillCommit) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | eEventType = XFA_EVENT_Change; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | break; |
| 178 | case CPDF_AAction::Validate: |
| 179 | eEventType = XFA_EVENT_Validate; |
| 180 | break; |
| 181 | case CPDF_AAction::OpenPage: |
| 182 | case CPDF_AAction::ClosePage: |
| 183 | case CPDF_AAction::Format: |
| 184 | case CPDF_AAction::Calculate: |
| 185 | case CPDF_AAction::CloseDocument: |
| 186 | case CPDF_AAction::SaveDocument: |
| 187 | case CPDF_AAction::DocumentSaved: |
| 188 | case CPDF_AAction::PrintDocument: |
| 189 | case CPDF_AAction::DocumentPrinted: |
| 190 | break; |
| 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()) { |
| 380 | CFX_WideString sValue; |
| 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 | |
| 412 | CFX_WideString sValue; |
| 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++) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 435 | CFX_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++) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 450 | CFX_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(); |
Dan Sinclair | cdba747 | 2017-03-23 09:17:10 -0400 | [diff] [blame] | 509 | XFA_DocType nDocType = pContext->GetDocType(); |
| 510 | if (nDocType != XFA_DocType::PDF && nDocType != XFA_DocType::Static) |
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 |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 555 | CFX_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)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | return iColorType != COLORTYPE_TRANSPARENT; |
| 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)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 572 | return iColorType != COLORTYPE_TRANSPARENT; |
| 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; |
| 582 | int iColorType = COLORTYPE_TRANSPARENT; |
| 583 | da.GetColor(argb, iColorType); |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 584 | color = ARGBToColorRef(argb); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 585 | return iColorType != COLORTYPE_TRANSPARENT; |
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 |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 610 | CFX_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()) { |
| 613 | CFX_WideString sValue; |
| 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 |
| 620 | CFX_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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { |
| 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
| 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 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 695 | void CPDFSDK_Widget::SetValue(const CFX_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 | |
| 704 | void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} |
| 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; |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 745 | CFX_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 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 756 | void CPDFSDK_Widget::ResetAppearance(const CFX_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 | |
| 760 | m_nAppAge++; |
| 761 | if (m_nAppAge > 999999) |
| 762 | m_nAppAge = 0; |
| 763 | if (bValueChanged) |
| 764 | m_nValueAge++; |
| 765 | |
| 766 | int nFieldType = GetFieldType(); |
| 767 | |
| 768 | switch (nFieldType) { |
| 769 | case FIELDTYPE_PUSHBUTTON: |
| 770 | ResetAppearance_PushButton(); |
| 771 | break; |
| 772 | case FIELDTYPE_CHECKBOX: |
| 773 | ResetAppearance_CheckBox(); |
| 774 | break; |
| 775 | case FIELDTYPE_RADIOBUTTON: |
| 776 | ResetAppearance_RadioButton(); |
| 777 | break; |
| 778 | case FIELDTYPE_COMBOBOX: |
| 779 | ResetAppearance_ComboBox(sValue); |
| 780 | break; |
| 781 | case FIELDTYPE_LISTBOX: |
| 782 | ResetAppearance_ListBox(); |
| 783 | break; |
| 784 | case FIELDTYPE_TEXTFIELD: |
| 785 | ResetAppearance_TextField(sValue); |
| 786 | break; |
| 787 | } |
| 788 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 789 | m_pAnnot->ClearCachedAP(); |
| 790 | } |
| 791 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 792 | CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 794 | ASSERT(pFormField); |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 795 | return m_pInterForm->OnFormat(pFormField, bFormatted); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | } |
| 797 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 798 | void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 799 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 800 | ASSERT(pFormField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 801 | m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 805 | const CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 806 | CPDF_Annot::AppearanceMode mode, |
| 807 | const CPDF_RenderOptions* pOptions) { |
| 808 | int nFieldType = GetFieldType(); |
| 809 | |
| 810 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 811 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 812 | mode == CPDF_Annot::Normal && |
| 813 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 814 | CFX_PathData pathData; |
| 815 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 816 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 817 | |
| 818 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 819 | rcAnnot.top); |
| 820 | |
| 821 | CFX_GraphStateData gsd; |
| 822 | gsd.m_LineWidth = 0.0f; |
| 823 | |
| 824 | pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, |
| 825 | FXFILL_ALTERNATE); |
| 826 | } else { |
| 827 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions); |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | void CPDFSDK_Widget::UpdateField() { |
| 832 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 833 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | m_pInterForm->UpdateField(pFormField); |
| 835 | } |
| 836 | |
| 837 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 838 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | int nFieldType = GetFieldType(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 840 | if (!m_pInterForm->IsNeedHighLight(nFieldType)) |
| 841 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 843 | CFX_Matrix page2device; |
| 844 | pPageView->GetCurrentMatrix(page2device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 846 | CFX_FloatRect rcDevice = GetRect(); |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 847 | CFX_PointF tmp = |
| 848 | page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom)); |
| 849 | rcDevice.left = tmp.x; |
| 850 | rcDevice.bottom = tmp.y; |
| 851 | |
| 852 | tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top)); |
| 853 | rcDevice.right = tmp.x; |
| 854 | rcDevice.top = tmp.y; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 855 | rcDevice.Normalize(); |
| 856 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 857 | FX_RECT rcDev = rcDevice.ToFxRect(); |
| 858 | pDevice->FillRect( |
| 859 | &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()), |
| 860 | m_pInterForm->GetHighlightColor(nFieldType))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | void CPDFSDK_Widget::ResetAppearance_PushButton() { |
| 864 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 865 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | int32_t nLayout = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | switch (pControl->GetTextPosition()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 868 | case TEXTPOS_ICON: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 869 | nLayout = PPBL_ICON; |
| 870 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 871 | case TEXTPOS_BELOW: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | nLayout = PPBL_ICONTOPLABELBOTTOM; |
| 873 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 874 | case TEXTPOS_ABOVE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 875 | nLayout = PPBL_LABELTOPICONBOTTOM; |
| 876 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 877 | case TEXTPOS_RIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | nLayout = PPBL_ICONLEFTLABELRIGHT; |
| 879 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 880 | case TEXTPOS_LEFT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 881 | nLayout = PPBL_LABELLEFTICONRIGHT; |
| 882 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 883 | case TEXTPOS_OVERLAID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | nLayout = PPBL_LABELOVERICON; |
| 885 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 886 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 887 | nLayout = PPBL_LABEL; |
| 888 | break; |
| 889 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 890 | |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 891 | CPWL_Color crBackground; |
| 892 | CPWL_Color crBorder; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | int iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 894 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 896 | if (iColorType > 0) |
| 897 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 898 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 900 | if (iColorType > 0) |
| 901 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 902 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 903 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | CPWL_Dash dsBorder(3, 0, 0); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 905 | CPWL_Color crLeftTop; |
| 906 | CPWL_Color crRightBottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 907 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 908 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 909 | switch (nBorderStyle) { |
| 910 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | dsBorder = CPWL_Dash(3, 3, 0); |
| 912 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 913 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 914 | fBorderWidth *= 2; |
| 915 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 916 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 918 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | fBorderWidth *= 2; |
| 920 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 921 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 922 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 923 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 927 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 928 | |
| 929 | CPWL_Color crText(COLORTYPE_GRAY, 0); |
| 930 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 931 | CFX_ByteString csNameTag; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 932 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 933 | if (da.HasColor()) { |
| 934 | da.GetColor(iColorType, fc); |
| 935 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 936 | } |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 937 | float fFontSize = 12.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 938 | if (da.HasFont()) |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 939 | csNameTag = da.GetFont(&fFontSize); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 940 | |
| 941 | CFX_WideString csWCaption; |
Tom Sepez | c4a2b75 | 2017-04-07 13:56:13 -0700 | [diff] [blame] | 942 | CFX_WideString csNormalCaption; |
| 943 | CFX_WideString csRolloverCaption; |
| 944 | CFX_WideString csDownCaption; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 945 | if (pControl->HasMKEntry("CA")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 946 | csNormalCaption = pControl->GetNormalCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 947 | |
| 948 | if (pControl->HasMKEntry("RC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 949 | csRolloverCaption = pControl->GetRolloverCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 950 | |
| 951 | if (pControl->HasMKEntry("AC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 952 | csDownCaption = pControl->GetDownCaption(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 953 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 954 | CPDF_Stream* pNormalIcon = nullptr; |
| 955 | CPDF_Stream* pRolloverIcon = nullptr; |
| 956 | CPDF_Stream* pDownIcon = nullptr; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 957 | if (pControl->HasMKEntry("I")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | pNormalIcon = pControl->GetNormalIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 959 | |
| 960 | if (pControl->HasMKEntry("RI")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 961 | pRolloverIcon = pControl->GetRolloverIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 962 | |
| 963 | if (pControl->HasMKEntry("IX")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 964 | pDownIcon = pControl->GetDownIcon(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | |
| 966 | if (pNormalIcon) { |
| 967 | if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 968 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 969 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
| 973 | if (pRolloverIcon) { |
| 974 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 975 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 976 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
| 980 | if (pDownIcon) { |
| 981 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 982 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 983 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 988 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 989 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 990 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 991 | |
| 992 | CFX_ByteString csAP = |
| 993 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 994 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 995 | crLeftTop, crRightBottom, nBorderStyle, |
| 996 | dsBorder) + |
| 997 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 998 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 999 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 1000 | |
| 1001 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 1002 | if (pNormalIcon) |
| 1003 | AddImageToAppearance("N", pNormalIcon); |
| 1004 | |
| 1005 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 1006 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 1007 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1008 | csRolloverCaption = csNormalCaption; |
| 1009 | pRolloverIcon = pNormalIcon; |
| 1010 | } |
| 1011 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1012 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1013 | |
| 1014 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1015 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1016 | crLeftTop, crRightBottom, |
| 1017 | nBorderStyle, dsBorder) + |
| 1018 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1019 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1020 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1021 | nLayout); |
| 1022 | |
| 1023 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1024 | if (pRolloverIcon) |
| 1025 | AddImageToAppearance("R", pRolloverIcon); |
| 1026 | |
| 1027 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1028 | csDownCaption = csNormalCaption; |
| 1029 | pDownIcon = pNormalIcon; |
| 1030 | } |
| 1031 | |
| 1032 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1033 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1034 | CPWL_Color crTemp = crLeftTop; |
| 1035 | crLeftTop = crRightBottom; |
| 1036 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1037 | break; |
| 1038 | } |
| 1039 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1040 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1041 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1042 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1043 | } |
| 1044 | default: |
| 1045 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1046 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1047 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1048 | font_map.SetAPType("D"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1049 | |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1050 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1051 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1052 | crLeftTop, crRightBottom, |
| 1053 | nBorderStyle, dsBorder) + |
| 1054 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1055 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1056 | pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1057 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1058 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1059 | if (pDownIcon) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1060 | AddImageToAppearance("D", pDownIcon); |
| 1061 | } else { |
| 1062 | RemoveAppearance("D"); |
| 1063 | RemoveAppearance("R"); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | void CPDFSDK_Widget::ResetAppearance_CheckBox() { |
| 1068 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1069 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1070 | int iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1071 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | |
| 1073 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1074 | if (iColorType > 0) |
| 1075 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1076 | |
| 1077 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1078 | if (iColorType > 0) |
| 1079 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1080 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1081 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1082 | CPWL_Dash dsBorder(3, 0, 0); |
| 1083 | CPWL_Color crLeftTop, crRightBottom; |
| 1084 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1085 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1086 | switch (nBorderStyle) { |
| 1087 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1088 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1089 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1090 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1091 | fBorderWidth *= 2; |
| 1092 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1093 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1094 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1095 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1096 | fBorderWidth *= 2; |
| 1097 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1098 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1099 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1100 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1101 | break; |
| 1102 | } |
| 1103 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1104 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1105 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1106 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1107 | if (da.HasColor()) { |
| 1108 | da.GetColor(iColorType, fc); |
| 1109 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1110 | } |
| 1111 | |
| 1112 | int32_t nStyle = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1114 | if (csWCaption.GetLength() > 0) { |
| 1115 | switch (csWCaption[0]) { |
| 1116 | case L'l': |
| 1117 | nStyle = PCS_CIRCLE; |
| 1118 | break; |
| 1119 | case L'8': |
| 1120 | nStyle = PCS_CROSS; |
| 1121 | break; |
| 1122 | case L'u': |
| 1123 | nStyle = PCS_DIAMOND; |
| 1124 | break; |
| 1125 | case L'n': |
| 1126 | nStyle = PCS_SQUARE; |
| 1127 | break; |
| 1128 | case L'H': |
| 1129 | nStyle = PCS_STAR; |
| 1130 | break; |
| 1131 | default: // L'4' |
| 1132 | nStyle = PCS_CHECK; |
| 1133 | break; |
| 1134 | } |
| 1135 | } else { |
| 1136 | nStyle = PCS_CHECK; |
| 1137 | } |
| 1138 | |
| 1139 | CFX_ByteString csAP_N_ON = |
| 1140 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1141 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1142 | crLeftTop, crRightBottom, nBorderStyle, |
| 1143 | dsBorder); |
| 1144 | |
| 1145 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1146 | |
| 1147 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1148 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1149 | CPWL_Color crTemp = crLeftTop; |
| 1150 | crLeftTop = crRightBottom; |
| 1151 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1155 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1156 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1157 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1158 | } |
| 1159 | default: |
| 1160 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | CFX_ByteString csAP_D_ON = |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1164 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1165 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1166 | crLeftTop, crRightBottom, nBorderStyle, |
| 1167 | dsBorder); |
| 1168 | |
| 1169 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1170 | |
| 1171 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1172 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1173 | |
| 1174 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1175 | pControl->GetCheckedAPState()); |
| 1176 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1177 | |
| 1178 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1179 | pControl->GetCheckedAPState()); |
| 1180 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1181 | |
| 1182 | CFX_ByteString csAS = GetAppState(); |
| 1183 | if (csAS.IsEmpty()) |
| 1184 | SetAppState("Off"); |
| 1185 | } |
| 1186 | |
| 1187 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1188 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1189 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1190 | int iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1191 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1192 | |
| 1193 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1194 | if (iColorType > 0) |
| 1195 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1196 | |
| 1197 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1198 | if (iColorType > 0) |
| 1199 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1200 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1201 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1202 | CPWL_Dash dsBorder(3, 0, 0); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1203 | CPWL_Color crLeftTop; |
| 1204 | CPWL_Color crRightBottom; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1205 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1206 | switch (nBorderStyle) { |
| 1207 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1208 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1209 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1210 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1211 | fBorderWidth *= 2; |
| 1212 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1213 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1214 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1215 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1216 | fBorderWidth *= 2; |
| 1217 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1218 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1219 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1220 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1221 | break; |
| 1222 | } |
| 1223 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1224 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1225 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1226 | |
| 1227 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1228 | if (da.HasColor()) { |
| 1229 | da.GetColor(iColorType, fc); |
| 1230 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1231 | } |
| 1232 | |
| 1233 | int32_t nStyle = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1234 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1235 | if (csWCaption.GetLength() > 0) { |
| 1236 | switch (csWCaption[0]) { |
| 1237 | default: // L'l': |
| 1238 | nStyle = PCS_CIRCLE; |
| 1239 | break; |
| 1240 | case L'8': |
| 1241 | nStyle = PCS_CROSS; |
| 1242 | break; |
| 1243 | case L'u': |
| 1244 | nStyle = PCS_DIAMOND; |
| 1245 | break; |
| 1246 | case L'n': |
| 1247 | nStyle = PCS_SQUARE; |
| 1248 | break; |
| 1249 | case L'H': |
| 1250 | nStyle = PCS_STAR; |
| 1251 | break; |
| 1252 | case L'4': |
| 1253 | nStyle = PCS_CHECK; |
| 1254 | break; |
| 1255 | } |
| 1256 | } else { |
| 1257 | nStyle = PCS_CIRCLE; |
| 1258 | } |
| 1259 | |
| 1260 | CFX_ByteString csAP_N_ON; |
| 1261 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1262 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1263 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1264 | |
| 1265 | if (nStyle == PCS_CIRCLE) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1266 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1267 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1268 | crRightBottom = crBackground - 0.25f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1269 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1270 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1271 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1272 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1273 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1274 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1275 | CPWL_Utils::GetCircleBorderAppStream( |
| 1276 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1277 | nBorderStyle, dsBorder); |
| 1278 | } else { |
| 1279 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1280 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1281 | crLeftTop, crRightBottom, |
| 1282 | nBorderStyle, dsBorder); |
| 1283 | } |
| 1284 | |
| 1285 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1286 | |
| 1287 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1288 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1289 | CPWL_Color crTemp = crLeftTop; |
| 1290 | crLeftTop = crRightBottom; |
| 1291 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | } |
| 1294 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1295 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1296 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1297 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1298 | } |
| 1299 | default: |
| 1300 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | CFX_ByteString csAP_D_ON; |
| 1304 | |
| 1305 | if (nStyle == PCS_CIRCLE) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1306 | CPWL_Color crBK = crBackground - 0.25f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1307 | if (nBorderStyle == BorderStyle::BEVELED) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1308 | crLeftTop = crBackground - 0.25f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1309 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1310 | crBK = crBackground; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1311 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1312 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1313 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1314 | } |
| 1315 | |
| 1316 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1317 | CPWL_Utils::GetCircleBorderAppStream( |
| 1318 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1319 | nBorderStyle, dsBorder); |
| 1320 | } else { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1321 | csAP_D_ON = |
| 1322 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
| 1323 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1324 | crLeftTop, crRightBottom, nBorderStyle, |
| 1325 | dsBorder); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1329 | |
| 1330 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1331 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1332 | |
| 1333 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1334 | pControl->GetCheckedAPState()); |
| 1335 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1336 | |
| 1337 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1338 | pControl->GetCheckedAPState()); |
| 1339 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1340 | |
| 1341 | CFX_ByteString csAS = GetAppState(); |
| 1342 | if (csAS.IsEmpty()) |
| 1343 | SetAppState("Off"); |
| 1344 | } |
| 1345 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1346 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1347 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1348 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1349 | CFX_ByteTextBuf sBody, sLines; |
| 1350 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1351 | CFX_FloatRect rcClient = GetClientRect(); |
| 1352 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1353 | rcButton.left = rcButton.right - 13; |
| 1354 | rcButton.Normalize(); |
| 1355 | |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 1356 | auto pEdit = pdfium::MakeUnique<CFX_Edit>(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1357 | pEdit->EnableRefresh(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1358 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1359 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1360 | pEdit->SetFontMap(&font_map); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1361 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1362 | CFX_FloatRect rcEdit = rcClient; |
| 1363 | rcEdit.right = rcButton.left; |
| 1364 | rcEdit.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1365 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1366 | pEdit->SetPlateRect(rcEdit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1367 | pEdit->SetAlignmentV(1, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1368 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1369 | float fFontSize = GetFontSize(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1370 | if (IsFloatZero(fFontSize)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1371 | pEdit->SetAutoFontSize(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1372 | else |
| 1373 | pEdit->SetFontSize(fFontSize); |
| 1374 | |
| 1375 | pEdit->Initialize(); |
| 1376 | |
| 1377 | if (sValue) { |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1378 | pEdit->SetText(*sValue); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | int32_t nCurSel = pField->GetSelectedIndex(0); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1381 | if (nCurSel < 0) |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1382 | pEdit->SetText(pField->GetValue()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1383 | else |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1384 | pEdit->SetText(pField->GetOptionLabel(nCurSel)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1387 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1388 | |
| 1389 | CFX_ByteString sEdit = |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1390 | CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1391 | if (sEdit.GetLength() > 0) { |
| 1392 | sBody << "/Tx BMC\n" |
| 1393 | << "q\n"; |
| 1394 | if (rcContent.Width() > rcEdit.Width() || |
| 1395 | rcContent.Height() > rcEdit.Height()) { |
| 1396 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1397 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1398 | } |
| 1399 | |
| 1400 | CPWL_Color crText = GetTextPWLColor(); |
| 1401 | sBody << "BT\n" |
| 1402 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1403 | << "Q\nEMC\n"; |
| 1404 | } |
| 1405 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1406 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1407 | |
| 1408 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1409 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1410 | |
| 1411 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1412 | } |
| 1413 | |
| 1414 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1415 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1416 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1417 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1418 | CFX_ByteTextBuf sBody, sLines; |
| 1419 | |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 1420 | auto pEdit = pdfium::MakeUnique<CFX_Edit>(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1421 | pEdit->EnableRefresh(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1422 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1423 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1424 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1425 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1426 | pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1427 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1428 | float fFontSize = GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1429 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1430 | pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1431 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1432 | pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1433 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1434 | CFX_ByteTextBuf sList; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1435 | float fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1436 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1437 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1438 | int32_t nCount = pField->CountOptions(); |
| 1439 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1440 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1441 | for (int32_t i = nTop; i < nCount; ++i) { |
| 1442 | bool bSelected = false; |
| 1443 | for (int32_t j = 0; j < nSelCount; ++j) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1444 | if (pField->GetSelectedIndex(j) == i) { |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1445 | bSelected = true; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1446 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1447 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1448 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1449 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1450 | pEdit->SetText(pField->GetOptionLabel(i)); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1451 | |
| 1452 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1453 | float fItemHeight = rcContent.Height(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1454 | |
| 1455 | if (bSelected) { |
| 1456 | CFX_FloatRect rcItem = |
| 1457 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
| 1458 | sList << "q\n" |
| 1459 | << CPWL_Utils::GetColorAppStream( |
| 1460 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1461 | 113.0f / 255.0f), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1462 | true) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1463 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1464 | << " " << rcItem.Height() << " re f\n" |
| 1465 | << "Q\n"; |
| 1466 | |
| 1467 | sList << "BT\n" |
| 1468 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1469 | true) |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1470 | << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1471 | << "ET\n"; |
| 1472 | } else { |
| 1473 | CPWL_Color crText = GetTextPWLColor(); |
| 1474 | sList << "BT\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1475 | << CPWL_Utils::GetColorAppStream(crText, true) |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1476 | << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1477 | << "ET\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1478 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1479 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1480 | fy -= fItemHeight; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1481 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1482 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1483 | if (sList.GetSize() > 0) { |
| 1484 | sBody << "/Tx BMC\n" |
| 1485 | << "q\n" |
| 1486 | << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1487 | << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1488 | sBody << sList << "Q\nEMC\n"; |
| 1489 | } |
| 1490 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1491 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1492 | sLines.AsStringC() + sBody.AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1493 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1494 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1497 | void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1498 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1499 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1500 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1501 | |
Dan Sinclair | 0bb1333 | 2017-03-30 16:12:02 -0400 | [diff] [blame] | 1502 | auto pEdit = pdfium::MakeUnique<CFX_Edit>(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1503 | pEdit->EnableRefresh(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1504 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1505 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1506 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1507 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1508 | CFX_FloatRect rcClient = GetClientRect(); |
| 1509 | pEdit->SetPlateRect(rcClient); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1510 | pEdit->SetAlignmentH(pControl->GetControlAlignment(), true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1511 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1512 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1513 | bool bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1514 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1515 | if (bMultiLine) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1516 | pEdit->SetMultiLine(true, true); |
| 1517 | pEdit->SetAutoReturn(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1518 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1519 | pEdit->SetAlignmentV(1, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1520 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1521 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1522 | uint16_t subWord = 0; |
| 1523 | if ((dwFieldFlags >> 13) & 1) { |
| 1524 | subWord = '*'; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1525 | pEdit->SetPasswordChar(subWord, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1526 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1527 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1528 | int nMaxLen = pField->GetMaxLen(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1529 | bool bCharArray = (dwFieldFlags >> 24) & 1; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1530 | float fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1531 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1532 | #ifdef PDF_ENABLE_XFA |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1533 | CFX_WideString sValueTmp; |
| 1534 | if (!sValue && GetMixXFAWidget()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1535 | sValueTmp = GetValue(true); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1536 | sValue = &sValueTmp; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1537 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1538 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1539 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1540 | if (nMaxLen > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1541 | if (bCharArray) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1542 | pEdit->SetCharArray(nMaxLen); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1543 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1544 | if (IsFloatZero(fFontSize)) { |
| 1545 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
| 1546 | rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1547 | } |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1548 | } else { |
| 1549 | if (sValue) |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1550 | nMaxLen = sValue->GetLength(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1551 | pEdit->SetLimitChar(nMaxLen); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1552 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1555 | if (IsFloatZero(fFontSize)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1556 | pEdit->SetAutoFontSize(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1557 | else |
| 1558 | pEdit->SetFontSize(fFontSize); |
| 1559 | |
| 1560 | pEdit->Initialize(); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1561 | pEdit->SetText(sValue ? *sValue : pField->GetValue()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1562 | |
| 1563 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1564 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1565 | pEdit.get(), CFX_PointF(), nullptr, !bCharArray, subWord); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1566 | |
| 1567 | if (sEdit.GetLength() > 0) { |
| 1568 | sBody << "/Tx BMC\n" |
| 1569 | << "q\n"; |
| 1570 | if (rcContent.Width() > rcClient.Width() || |
| 1571 | rcContent.Height() > rcClient.Height()) { |
| 1572 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1573 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1574 | } |
| 1575 | CPWL_Color crText = GetTextPWLColor(); |
| 1576 | sBody << "BT\n" |
| 1577 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1578 | << "Q\nEMC\n"; |
| 1579 | } |
| 1580 | |
| 1581 | if (bCharArray) { |
| 1582 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1583 | case BorderStyle::SOLID: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1584 | CFX_ByteString sColor = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1585 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1586 | if (sColor.GetLength() > 0) { |
| 1587 | sLines << "q\n" |
| 1588 | << GetBorderWidth() << " w\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1589 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1590 | << " 2 J 0 j\n"; |
| 1591 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1592 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1593 | sLines << rcClient.left + |
| 1594 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1595 | << " " << rcClient.bottom << " m\n" |
| 1596 | << rcClient.left + |
| 1597 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1598 | << " " << rcClient.top << " l S\n"; |
| 1599 | } |
| 1600 | |
| 1601 | sLines << "Q\n"; |
| 1602 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1603 | break; |
| 1604 | } |
| 1605 | case BorderStyle::DASH: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1606 | CFX_ByteString sColor = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1607 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1608 | if (sColor.GetLength() > 0) { |
| 1609 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1610 | |
| 1611 | sLines << "q\n" |
| 1612 | << GetBorderWidth() << " w\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1613 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1614 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1615 | << dsBorder.nPhase << " d\n"; |
| 1616 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1617 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1618 | sLines << rcClient.left + |
| 1619 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1620 | << " " << rcClient.bottom << " m\n" |
| 1621 | << rcClient.left + |
| 1622 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1623 | << " " << rcClient.top << " l S\n"; |
| 1624 | } |
| 1625 | |
| 1626 | sLines << "Q\n"; |
| 1627 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1628 | break; |
| 1629 | } |
| 1630 | default: |
| 1631 | break; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1635 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1636 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1637 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1640 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1641 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1642 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1643 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1644 | case BorderStyle::BEVELED: |
| 1645 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1646 | fBorderWidth *= 2.0f; |
| 1647 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1648 | default: |
| 1649 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1655 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1656 | CFX_FloatRect rectAnnot = GetRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1657 | float fWidth = rectAnnot.right - rectAnnot.left; |
| 1658 | float fHeight = rectAnnot.top - rectAnnot.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1659 | |
| 1660 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1661 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1662 | switch (abs(pControl->GetRotation() % 360)) { |
| 1663 | case 0: |
| 1664 | case 180: |
| 1665 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1666 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1667 | break; |
| 1668 | case 90: |
| 1669 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1670 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1671 | break; |
| 1672 | } |
| 1673 | |
| 1674 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1677 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1678 | CPWL_Color crBackground = GetFillPWLColor(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1679 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1680 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1681 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1682 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1683 | } |
| 1684 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1685 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1686 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1687 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1688 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1689 | CPWL_Color crLeftTop, crRightBottom; |
| 1690 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1691 | float fBorderWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1692 | CPWL_Dash dsBorder(3, 0, 0); |
| 1693 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1694 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1695 | switch (nBorderStyle) { |
| 1696 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1697 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1698 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1699 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1700 | fBorderWidth *= 2; |
| 1701 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 1702 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1703 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1704 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1705 | fBorderWidth *= 2; |
| 1706 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1707 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1708 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1709 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1710 | break; |
| 1711 | } |
| 1712 | |
| 1713 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1714 | crLeftTop, crRightBottom, nBorderStyle, |
| 1715 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1718 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1719 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1720 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1721 | CFX_FloatRect rcAnnot = GetRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1722 | float fWidth = rcAnnot.right - rcAnnot.left; |
| 1723 | float fHeight = rcAnnot.top - rcAnnot.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1724 | |
| 1725 | switch (abs(pControl->GetRotation() % 360)) { |
| 1726 | case 0: |
| 1727 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1728 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1729 | break; |
| 1730 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1731 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1732 | break; |
| 1733 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1734 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1735 | break; |
| 1736 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1737 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1738 | break; |
| 1739 | } |
| 1740 | |
| 1741 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1744 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1745 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1746 | |
| 1747 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1748 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1749 | if (da.HasColor()) { |
| 1750 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1751 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1752 | da.GetColor(iColorType, fc); |
| 1753 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1754 | } |
| 1755 | |
| 1756 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1759 | CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 1760 | CPWL_Color crBorder; |
| 1761 | |
| 1762 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1763 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1764 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1765 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 1766 | if (iColorType > 0) |
| 1767 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1768 | |
| 1769 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1772 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1773 | CPWL_Color crFill; |
| 1774 | |
| 1775 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1776 | int32_t iColorType; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 1777 | float fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1778 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1779 | if (iColorType > 0) |
| 1780 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1781 | |
| 1782 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1785 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1786 | CPDF_Stream* pImage) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1787 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 1788 | CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1789 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1790 | CFX_ByteString sImageAlias = "IMG"; |
| 1791 | |
| 1792 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1793 | sImageAlias = pImageDict->GetStringFor("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1794 | if (sImageAlias.IsEmpty()) |
| 1795 | sImageAlias = "IMG"; |
| 1796 | } |
| 1797 | |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 1798 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1799 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 1800 | if (!pStreamResList) |
| 1801 | pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1802 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 1803 | CPDF_Dictionary* pXObject = |
| 1804 | pStreamResList->SetNewFor<CPDF_Dictionary>("XObject"); |
| 1805 | pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum()); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1806 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1807 | |
| 1808 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1809 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) |
| 1810 | pAPDict->RemoveFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1813 | bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1814 | PDFSDK_FieldAction& data, |
| 1815 | CPDFSDK_PageView* pPageView) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 1816 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1817 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1818 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1819 | CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1820 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1821 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1822 | |
| 1823 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1824 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1825 | CXFA_EventParam param; |
| 1826 | param.m_eType = eEventType; |
| 1827 | param.m_wsChange = data.sChange; |
| 1828 | param.m_iCommitKey = data.nCommitKey; |
| 1829 | param.m_bShift = data.bShift; |
| 1830 | param.m_iSelStart = data.nSelStart; |
| 1831 | param.m_iSelEnd = data.nSelEnd; |
| 1832 | param.m_wsFullText = data.sValue; |
| 1833 | param.m_bKeyDown = data.bKeyDown; |
| 1834 | param.m_bModifier = data.bModifier; |
| 1835 | param.m_wsNewText = data.sValue; |
| 1836 | if (data.nSelEnd > data.nSelStart) |
| 1837 | param.m_wsNewText.Delete(data.nSelStart, |
| 1838 | data.nSelEnd - data.nSelStart); |
| 1839 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1840 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1841 | param.m_wsPrevText = data.sValue; |
| 1842 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1843 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1844 | param.m_pTarget = pAcc; |
| 1845 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1846 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1847 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1848 | pDocView->UpdateDocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1849 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1850 | if (nRet == XFA_EVENTERROR_Success) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1851 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1852 | } |
| 1853 | } |
| 1854 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1855 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1856 | |
| 1857 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1858 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 1859 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
dsinclair | 19c198b | 2016-10-11 12:51:37 -0700 | [diff] [blame] | 1860 | return pActionHandler->DoAction_Field(action, type, pFormFillEnv, |
| 1861 | GetFormField(), data); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1862 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1863 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1867 | switch (eAAT) { |
| 1868 | case CPDF_AAction::CursorEnter: |
| 1869 | case CPDF_AAction::CursorExit: |
| 1870 | case CPDF_AAction::ButtonDown: |
| 1871 | case CPDF_AAction::ButtonUp: |
| 1872 | case CPDF_AAction::GetFocus: |
| 1873 | case CPDF_AAction::LoseFocus: |
| 1874 | case CPDF_AAction::PageOpen: |
| 1875 | case CPDF_AAction::PageClose: |
| 1876 | case CPDF_AAction::PageVisible: |
| 1877 | case CPDF_AAction::PageInvisible: |
| 1878 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1879 | |
| 1880 | case CPDF_AAction::KeyStroke: |
| 1881 | case CPDF_AAction::Format: |
| 1882 | case CPDF_AAction::Validate: |
| 1883 | case CPDF_AAction::Calculate: { |
| 1884 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1885 | if (pField->GetAdditionalAction().GetDict()) |
| 1886 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1887 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1888 | } |
| 1889 | default: |
| 1890 | break; |
| 1891 | } |
| 1892 | |
| 1893 | return CPDF_Action(); |
| 1894 | } |
| 1895 | |
| 1896 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1897 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1898 | return pFormField->GetAlternateName(); |
| 1899 | } |
| 1900 | |
| 1901 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1902 | return m_nAppAge; |
| 1903 | } |
| 1904 | |
| 1905 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1906 | return m_nValueAge; |
| 1907 | } |