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" |
| 38 | #include "xfa/fxfa/fxfa_widget.h" |
| 39 | #include "xfa/fxfa/xfa_ffdocview.h" |
| 40 | #include "xfa/fxfa/xfa_ffwidget.h" |
| 41 | #include "xfa/fxfa/xfa_ffwidgethandler.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(); |
| 75 | if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
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(); |
| 99 | if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 100 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | CFX_WideString sName = GetName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | if (!sName.IsEmpty()) |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 103 | return pDocView->GetWidgetByName(sName, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 107 | return 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(); |
| 112 | if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | if (!m_pWidgetHandler) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 114 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | } |
| 117 | return m_pWidgetHandler; |
| 118 | } |
| 119 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 120 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 124 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 125 | |
| 126 | switch (eXFAAAT) { |
| 127 | case PDFSDK_XFA_Click: |
| 128 | eEventType = XFA_EVENT_Click; |
| 129 | break; |
| 130 | case PDFSDK_XFA_Full: |
| 131 | eEventType = XFA_EVENT_Full; |
| 132 | break; |
| 133 | case PDFSDK_XFA_PreOpen: |
| 134 | eEventType = XFA_EVENT_PreOpen; |
| 135 | break; |
| 136 | case PDFSDK_XFA_PostOpen: |
| 137 | eEventType = XFA_EVENT_PostOpen; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | return eEventType; |
| 142 | } |
| 143 | |
| 144 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 145 | bool bWillCommit) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 147 | |
| 148 | switch (eAAT) { |
| 149 | case CPDF_AAction::CursorEnter: |
| 150 | eEventType = XFA_EVENT_MouseEnter; |
| 151 | break; |
| 152 | case CPDF_AAction::CursorExit: |
| 153 | eEventType = XFA_EVENT_MouseExit; |
| 154 | break; |
| 155 | case CPDF_AAction::ButtonDown: |
| 156 | eEventType = XFA_EVENT_MouseDown; |
| 157 | break; |
| 158 | case CPDF_AAction::ButtonUp: |
| 159 | eEventType = XFA_EVENT_MouseUp; |
| 160 | break; |
| 161 | case CPDF_AAction::GetFocus: |
| 162 | eEventType = XFA_EVENT_Enter; |
| 163 | break; |
| 164 | case CPDF_AAction::LoseFocus: |
| 165 | eEventType = XFA_EVENT_Exit; |
| 166 | break; |
| 167 | case CPDF_AAction::PageOpen: |
| 168 | break; |
| 169 | case CPDF_AAction::PageClose: |
| 170 | break; |
| 171 | case CPDF_AAction::PageVisible: |
| 172 | break; |
| 173 | case CPDF_AAction::PageInvisible: |
| 174 | break; |
| 175 | case CPDF_AAction::KeyStroke: |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 176 | if (!bWillCommit) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | eEventType = XFA_EVENT_Change; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | break; |
| 179 | case CPDF_AAction::Validate: |
| 180 | eEventType = XFA_EVENT_Validate; |
| 181 | break; |
| 182 | case CPDF_AAction::OpenPage: |
| 183 | case CPDF_AAction::ClosePage: |
| 184 | case CPDF_AAction::Format: |
| 185 | case CPDF_AAction::Calculate: |
| 186 | case CPDF_AAction::CloseDocument: |
| 187 | case CPDF_AAction::SaveDocument: |
| 188 | case CPDF_AAction::DocumentSaved: |
| 189 | case CPDF_AAction::PrintDocument: |
| 190 | case CPDF_AAction::DocumentPrinted: |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | return eEventType; |
| 195 | } |
| 196 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 197 | bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 198 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 199 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 200 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 202 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 203 | if (!pXFAWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 205 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 206 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 207 | |
| 208 | CXFA_WidgetAcc* pAcc; |
| 209 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 210 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 211 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 212 | pAcc = hGroupWidget->GetDataAcc(); |
| 213 | if (pXFAWidgetHandler->HasEvent(pAcc, eEventType)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 214 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 218 | pAcc = hWidget->GetDataAcc(); |
| 219 | return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | } |
| 221 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 222 | bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 223 | PDFSDK_FieldAction& data, |
| 224 | CPDFSDK_PageView* pPageView) { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 225 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 227 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 228 | if (!hWidget) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 229 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 231 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 232 | if (eEventType == XFA_EVENT_Unknown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 233 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 235 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 236 | if (!pXFAWidgetHandler) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 237 | return false; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 238 | |
| 239 | CXFA_EventParam param; |
| 240 | param.m_eType = eEventType; |
| 241 | param.m_wsChange = data.sChange; |
| 242 | param.m_iCommitKey = data.nCommitKey; |
| 243 | param.m_bShift = data.bShift; |
| 244 | param.m_iSelStart = data.nSelStart; |
| 245 | param.m_iSelEnd = data.nSelEnd; |
| 246 | param.m_wsFullText = data.sValue; |
| 247 | param.m_bKeyDown = data.bKeyDown; |
| 248 | param.m_bModifier = data.bModifier; |
| 249 | param.m_wsNewText = data.sValue; |
| 250 | if (data.nSelEnd > data.nSelStart) |
| 251 | param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart); |
| 252 | |
| 253 | for (int i = 0; i < data.sChange.GetLength(); i++) |
| 254 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 255 | param.m_wsPrevText = data.sValue; |
| 256 | |
| 257 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 258 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 259 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 260 | CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc(); |
| 261 | param.m_pTarget = pAcc; |
| 262 | if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
| 263 | XFA_EVENTERROR_Success) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 264 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 268 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
| 269 | param.m_pTarget = pAcc; |
| 270 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 271 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 272 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 273 | pDocView->UpdateDocView(); |
| 274 | |
| 275 | return nRet == XFA_EVENTERROR_Success; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | } |
| 277 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 278 | void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 279 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 280 | if (!hWidget) |
| 281 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 283 | CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
| 284 | if (!pWidgetAcc) |
| 285 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 287 | CPDF_FormField* pFormField = GetFormField(); |
| 288 | switch (GetFieldType()) { |
| 289 | case FIELDTYPE_CHECKBOX: |
| 290 | case FIELDTYPE_RADIOBUTTON: { |
| 291 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 292 | XFA_CHECKSTATE eCheckState = |
| 293 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
| 294 | pWidgetAcc->SetCheckState(eCheckState, true); |
| 295 | break; |
| 296 | } |
| 297 | case FIELDTYPE_TEXTFIELD: |
| 298 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 299 | break; |
| 300 | case FIELDTYPE_LISTBOX: { |
| 301 | pWidgetAcc->ClearAllSelections(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 303 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 304 | int nIndex = pFormField->GetSelectedIndex(i); |
| 305 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 306 | pWidgetAcc->SetItemState(nIndex, true, false, false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 308 | break; |
| 309 | } |
| 310 | case FIELDTYPE_COMBOBOX: { |
| 311 | pWidgetAcc->ClearAllSelections(); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 312 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 313 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 314 | int nIndex = pFormField->GetSelectedIndex(i); |
| 315 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 316 | pWidgetAcc->SetItemState(nIndex, true, false, false, true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 317 | } |
| 318 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 319 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 322 | |
| 323 | if (bSynchronizeElse) |
| 324 | pWidgetAcc->ProcessValueChanged(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void CPDFSDK_Widget::SynchronizeXFAValue() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 328 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
| 329 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | if (!pXFADocView) |
| 331 | return; |
| 332 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 333 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 334 | if (GetXFAWidgetHandler()) { |
| 335 | CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
| 336 | GetFormControl()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void CPDFSDK_Widget::SynchronizeXFAItems() { |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 342 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
| 343 | CXFA_FFDocView* pXFADocView = pContext->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | if (!pXFADocView) |
| 345 | return; |
| 346 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 347 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 348 | if (GetXFAWidgetHandler()) |
| 349 | SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 353 | void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
| 354 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 355 | CPDF_FormField* pFormField, |
| 356 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 357 | ASSERT(hWidget); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 358 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 360 | switch (pFormField->GetFieldType()) { |
| 361 | case FIELDTYPE_CHECKBOX: { |
| 362 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 363 | pFormField->CheckControl( |
| 364 | pFormField->GetControlIndex(pFormControl), |
| 365 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 366 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 367 | break; |
| 368 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 369 | case FIELDTYPE_RADIOBUTTON: { |
| 370 | // TODO(weili): Check whether we need to handle checkbox and radio |
| 371 | // button differently, otherwise, merge these two cases. |
| 372 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 373 | pFormField->CheckControl( |
| 374 | pFormField->GetControlIndex(pFormControl), |
| 375 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 376 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 377 | break; |
| 378 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 379 | case FIELDTYPE_TEXTFIELD: { |
| 380 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 381 | CFX_WideString sValue; |
| 382 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 383 | pFormField->SetValue(sValue, true); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 384 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 385 | break; |
| 386 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 387 | case FIELDTYPE_LISTBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 388 | pFormField->ClearSelection(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 390 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 391 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 392 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 394 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 395 | pFormField->SetItemSelection(nIndex, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 396 | } |
| 397 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 398 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 399 | break; |
| 400 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 401 | case FIELDTYPE_COMBOBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 402 | pFormField->ClearSelection(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 404 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 405 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 406 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 408 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 409 | pFormField->SetItemSelection(nIndex, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 412 | |
| 413 | CFX_WideString sValue; |
| 414 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 415 | pFormField->SetValue(sValue, true); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 416 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 417 | break; |
| 418 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 422 | void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, |
| 423 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | CPDF_FormField* pFormField, |
| 425 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 426 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 427 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 428 | switch (pFormField->GetFieldType()) { |
| 429 | case FIELDTYPE_LISTBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 430 | pFormField->ClearSelection(false); |
| 431 | pFormField->ClearOptions(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 432 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 433 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 434 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 435 | CFX_WideString swText; |
| 436 | pWidgetAcc->GetChoiceListItem(swText, i); |
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()) { |
| 448 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 449 | CFX_WideString swText; |
| 450 | pWidgetAcc->GetChoiceListItem(swText, i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 451 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 452 | pFormField->InsertOption(swText, i, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 454 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 456 | pFormField->SetValue(L"", true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 457 | break; |
| 458 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 461 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 462 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 463 | bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 464 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | if (!pAP) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 466 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 467 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | // Choose the right sub-ap |
| 469 | const FX_CHAR* ap_entry = "N"; |
| 470 | if (mode == CPDF_Annot::Down) |
| 471 | ap_entry = "D"; |
| 472 | else if (mode == CPDF_Annot::Rollover) |
| 473 | ap_entry = "R"; |
| 474 | if (!pAP->KeyExist(ap_entry)) |
| 475 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | // Get the AP stream or subdirectory |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 478 | CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | if (!psub) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 480 | return false; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 481 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | int nFieldType = GetFieldType(); |
| 483 | switch (nFieldType) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 484 | case FIELDTYPE_PUSHBUTTON: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 485 | case FIELDTYPE_COMBOBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 486 | case FIELDTYPE_LISTBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 487 | case FIELDTYPE_TEXTFIELD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 488 | case FIELDTYPE_SIGNATURE: |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 489 | return psub->IsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | case FIELDTYPE_CHECKBOX: |
| 491 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 492 | if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 493 | return !!pSubDict->GetStreamFor(GetAppState()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 495 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 497 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | int CPDFSDK_Widget::GetFieldType() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 501 | CPDF_FormField* pField = GetFormField(); |
| 502 | return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | } |
| 504 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 505 | bool CPDFSDK_Widget::IsAppearanceValid() { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 506 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 507 | CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext(); |
| 508 | int nDocType = pContext->GetDocType(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 509 | if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 510 | return true; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 511 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 512 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | } |
| 514 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 515 | int CPDFSDK_Widget::GetLayoutOrder() const { |
| 516 | return 2; |
| 517 | } |
| 518 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 519 | int CPDFSDK_Widget::GetFieldFlags() const { |
| 520 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 521 | CPDF_FormControl* pFormControl = |
| 522 | pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); |
| 523 | CPDF_FormField* pFormField = pFormControl->GetField(); |
| 524 | return pFormField->GetFieldFlags(); |
| 525 | } |
| 526 | |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 527 | bool CPDFSDK_Widget::IsSignatureWidget() const { |
| 528 | return GetFieldType() == FIELDTYPE_SIGNATURE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 532 | CPDF_FormControl* pControl = GetFormControl(); |
| 533 | return pControl ? pControl->GetField() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 538 | return pPDFInterForm->GetControlByDict(GetAnnotDict()); |
| 539 | } |
| 540 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 541 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl( |
| 542 | CPDF_InterForm* pInterForm, |
| 543 | const CPDF_Dictionary* pAnnotDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 544 | ASSERT(pAnnotDict); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 545 | return pInterForm->GetControlByDict(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | int CPDFSDK_Widget::GetRotate() const { |
| 549 | CPDF_FormControl* pCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | return pCtrl->GetRotation() % 360; |
| 551 | } |
| 552 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 553 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 554 | CFX_WideString CPDFSDK_Widget::GetName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | return pFormField->GetFullName(); |
| 557 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 558 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 560 | bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 562 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 563 | color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 564 | return iColorType != COLORTYPE_TRANSPARENT; |
| 565 | } |
| 566 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 567 | bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 570 | color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | return iColorType != COLORTYPE_TRANSPARENT; |
| 572 | } |
| 573 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 574 | bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 575 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 576 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 577 | if (!da.HasColor()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 578 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 579 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 580 | FX_ARGB argb; |
| 581 | int iColorType = COLORTYPE_TRANSPARENT; |
| 582 | da.GetColor(argb, iColorType); |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 583 | color = ARGBToColorRef(argb); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 584 | return iColorType != COLORTYPE_TRANSPARENT; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | FX_FLOAT CPDFSDK_Widget::GetFontSize() const { |
| 588 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 589 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
| 590 | CFX_ByteString csFont = ""; |
| 591 | FX_FLOAT fFontSize = 0.0f; |
| 592 | pDa.GetFont(csFont, fFontSize); |
| 593 | |
| 594 | return fFontSize; |
| 595 | } |
| 596 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 597 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 598 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 599 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 600 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 601 | if (nIndex < pWidgetAcc->CountSelectedItems()) |
| 602 | return pWidgetAcc->GetSelectedItem(nIndex); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 603 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 605 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 607 | return pFormField->GetSelectedIndex(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 610 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 611 | CFX_WideString CPDFSDK_Widget::GetValue(bool bDisplay) const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 612 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 613 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 614 | CFX_WideString sValue; |
| 615 | pWidgetAcc->GetValue( |
| 616 | sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit); |
| 617 | return sValue; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 618 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 619 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 620 | #else |
| 621 | CFX_WideString CPDFSDK_Widget::GetValue() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 622 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 624 | return pFormField->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 627 | CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { |
| 628 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | return pFormField->GetDefaultValue(); |
| 630 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 631 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 632 | CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
| 633 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 634 | return pFormField->GetOptionLabel(nIndex); |
| 635 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 636 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 637 | int CPDFSDK_Widget::CountOptions() const { |
| 638 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 639 | return pFormField->CountOptions(); |
| 640 | } |
| 641 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 642 | bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 643 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 644 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 645 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 646 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 647 | return pWidgetAcc->GetItemState(nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 649 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | } |
| 651 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 652 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 653 | CPDF_FormField* pFormField = GetFormField(); |
| 654 | return pFormField->IsItemSelected(nIndex); |
| 655 | } |
| 656 | |
| 657 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 658 | CPDF_FormField* pFormField = GetFormField(); |
| 659 | return pFormField->GetTopVisibleIndex(); |
| 660 | } |
| 661 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 662 | bool CPDFSDK_Widget::IsChecked() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 663 | #ifdef PDF_ENABLE_XFA |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 664 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 665 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) |
| 666 | return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 667 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 668 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 669 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | return pFormCtrl->IsChecked(); |
| 671 | } |
| 672 | |
| 673 | int CPDFSDK_Widget::GetAlignment() const { |
| 674 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | return pFormCtrl->GetControlAlignment(); |
| 676 | } |
| 677 | |
| 678 | int CPDFSDK_Widget::GetMaxLen() const { |
| 679 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 680 | return pFormField->GetMaxLen(); |
| 681 | } |
| 682 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 683 | void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
| 687 | bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 688 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 689 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 690 | ResetAppearance(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 692 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 693 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 694 | } |
| 695 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 696 | void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | pFormField->SetValue(sValue, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 699 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 701 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 702 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} |
| 706 | void CPDFSDK_Widget::SetOptionSelection(int index, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 707 | bool bSelected, |
| 708 | bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | pFormField->SetItemSelection(index, bSelected, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 711 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 712 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 713 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 714 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 715 | } |
| 716 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 717 | void CPDFSDK_Widget::ClearSelection(bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | pFormField->ClearSelection(bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 720 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | if (!bNotify) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 722 | Synchronize(true); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 723 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 727 | |
| 728 | void CPDFSDK_Widget::SetAppModified() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 729 | m_bAppModified = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void CPDFSDK_Widget::ClearAppModified() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 733 | m_bAppModified = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 734 | } |
| 735 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 736 | bool CPDFSDK_Widget::IsAppModified() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 737 | return m_bAppModified; |
| 738 | } |
| 739 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 740 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 741 | void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 742 | switch (GetFieldType()) { |
| 743 | case FIELDTYPE_TEXTFIELD: |
| 744 | case FIELDTYPE_COMBOBOX: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 745 | bool bFormatted = false; |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 746 | CFX_WideString sValue = OnFormat(bFormatted); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 747 | ResetAppearance(bFormatted ? &sValue : nullptr, true); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 748 | break; |
| 749 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 751 | ResetAppearance(nullptr, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 755 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 756 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 757 | void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 758 | bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 759 | SetAppModified(); |
| 760 | |
| 761 | m_nAppAge++; |
| 762 | if (m_nAppAge > 999999) |
| 763 | m_nAppAge = 0; |
| 764 | if (bValueChanged) |
| 765 | m_nValueAge++; |
| 766 | |
| 767 | int nFieldType = GetFieldType(); |
| 768 | |
| 769 | switch (nFieldType) { |
| 770 | case FIELDTYPE_PUSHBUTTON: |
| 771 | ResetAppearance_PushButton(); |
| 772 | break; |
| 773 | case FIELDTYPE_CHECKBOX: |
| 774 | ResetAppearance_CheckBox(); |
| 775 | break; |
| 776 | case FIELDTYPE_RADIOBUTTON: |
| 777 | ResetAppearance_RadioButton(); |
| 778 | break; |
| 779 | case FIELDTYPE_COMBOBOX: |
| 780 | ResetAppearance_ComboBox(sValue); |
| 781 | break; |
| 782 | case FIELDTYPE_LISTBOX: |
| 783 | ResetAppearance_ListBox(); |
| 784 | break; |
| 785 | case FIELDTYPE_TEXTFIELD: |
| 786 | ResetAppearance_TextField(sValue); |
| 787 | break; |
| 788 | } |
| 789 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 790 | m_pAnnot->ClearCachedAP(); |
| 791 | } |
| 792 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 793 | CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 794 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 795 | ASSERT(pFormField); |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 796 | return m_pInterForm->OnFormat(pFormField, bFormatted); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | } |
| 798 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 799 | void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 801 | ASSERT(pFormField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 802 | m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 806 | const CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 807 | CPDF_Annot::AppearanceMode mode, |
| 808 | const CPDF_RenderOptions* pOptions) { |
| 809 | int nFieldType = GetFieldType(); |
| 810 | |
| 811 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 812 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 813 | mode == CPDF_Annot::Normal && |
| 814 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 815 | CFX_PathData pathData; |
| 816 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 817 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 818 | |
| 819 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 820 | rcAnnot.top); |
| 821 | |
| 822 | CFX_GraphStateData gsd; |
| 823 | gsd.m_LineWidth = 0.0f; |
| 824 | |
| 825 | pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, |
| 826 | FXFILL_ALTERNATE); |
| 827 | } else { |
| 828 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions); |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | void CPDFSDK_Widget::UpdateField() { |
| 833 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 834 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 835 | m_pInterForm->UpdateField(pFormField); |
| 836 | } |
| 837 | |
| 838 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 839 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 840 | int nFieldType = GetFieldType(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 841 | if (!m_pInterForm->IsNeedHighLight(nFieldType)) |
| 842 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 843 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 844 | CFX_Matrix page2device; |
| 845 | pPageView->GetCurrentMatrix(page2device); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 847 | CFX_FloatRect rcDevice = GetRect(); |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 848 | CFX_PointF tmp = |
| 849 | page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom)); |
| 850 | rcDevice.left = tmp.x; |
| 851 | rcDevice.bottom = tmp.y; |
| 852 | |
| 853 | tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top)); |
| 854 | rcDevice.right = tmp.x; |
| 855 | rcDevice.top = tmp.y; |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 856 | rcDevice.Normalize(); |
| 857 | |
Dan Sinclair | afb4456 | 2017-02-09 13:07:43 -0500 | [diff] [blame] | 858 | FX_RECT rcDev = rcDevice.ToFxRect(); |
| 859 | pDevice->FillRect( |
| 860 | &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()), |
| 861 | m_pInterForm->GetHighlightColor(nFieldType))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | void CPDFSDK_Widget::ResetAppearance_PushButton() { |
| 865 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 866 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 867 | int32_t nLayout = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 868 | switch (pControl->GetTextPosition()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 869 | case TEXTPOS_ICON: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 870 | nLayout = PPBL_ICON; |
| 871 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 872 | case TEXTPOS_BELOW: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | nLayout = PPBL_ICONTOPLABELBOTTOM; |
| 874 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 875 | case TEXTPOS_ABOVE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | nLayout = PPBL_LABELTOPICONBOTTOM; |
| 877 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 878 | case TEXTPOS_RIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 879 | nLayout = PPBL_ICONLEFTLABELRIGHT; |
| 880 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 881 | case TEXTPOS_LEFT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | nLayout = PPBL_LABELLEFTICONRIGHT; |
| 883 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 884 | case TEXTPOS_OVERLAID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | nLayout = PPBL_LABELOVERICON; |
| 886 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 887 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | nLayout = PPBL_LABEL; |
| 889 | break; |
| 890 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 891 | |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 892 | CPWL_Color crBackground; |
| 893 | CPWL_Color crBorder; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 894 | int iColorType; |
| 895 | FX_FLOAT fc[4]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 896 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 897 | if (iColorType > 0) |
| 898 | 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] | 899 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 901 | if (iColorType > 0) |
| 902 | 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] | 903 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 905 | CPWL_Dash dsBorder(3, 0, 0); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 906 | CPWL_Color crLeftTop; |
| 907 | CPWL_Color crRightBottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 908 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 909 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 910 | switch (nBorderStyle) { |
| 911 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 912 | dsBorder = CPWL_Dash(3, 3, 0); |
| 913 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 914 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | fBorderWidth *= 2; |
| 916 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 917 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 918 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 919 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 920 | fBorderWidth *= 2; |
| 921 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 922 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 923 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 924 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | break; |
| 926 | } |
| 927 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 928 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 929 | |
| 930 | CPWL_Color crText(COLORTYPE_GRAY, 0); |
| 931 | |
| 932 | FX_FLOAT fFontSize = 12.0f; |
| 933 | CFX_ByteString csNameTag; |
| 934 | |
| 935 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 936 | if (da.HasColor()) { |
| 937 | da.GetColor(iColorType, fc); |
| 938 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 939 | } |
| 940 | |
| 941 | if (da.HasFont()) |
| 942 | da.GetFont(csNameTag, fFontSize); |
| 943 | |
| 944 | CFX_WideString csWCaption; |
| 945 | CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption; |
| 946 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 947 | if (pControl->HasMKEntry("CA")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 948 | csNormalCaption = pControl->GetNormalCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 949 | |
| 950 | if (pControl->HasMKEntry("RC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 951 | csRolloverCaption = pControl->GetRolloverCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 952 | |
| 953 | if (pControl->HasMKEntry("AC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 954 | csDownCaption = pControl->GetDownCaption(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 955 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 956 | CPDF_Stream* pNormalIcon = nullptr; |
| 957 | CPDF_Stream* pRolloverIcon = nullptr; |
| 958 | CPDF_Stream* pDownIcon = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 959 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 960 | if (pControl->HasMKEntry("I")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 961 | pNormalIcon = pControl->GetNormalIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 962 | |
| 963 | if (pControl->HasMKEntry("RI")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 964 | pRolloverIcon = pControl->GetRolloverIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 965 | |
| 966 | if (pControl->HasMKEntry("IX")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 967 | pDownIcon = pControl->GetDownIcon(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 968 | |
| 969 | if (pNormalIcon) { |
| 970 | if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 971 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 972 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
| 976 | if (pRolloverIcon) { |
| 977 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 978 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 979 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
| 983 | if (pDownIcon) { |
| 984 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 985 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 986 | pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
| 990 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 991 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 992 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 993 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 994 | |
| 995 | CFX_ByteString csAP = |
| 996 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 997 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 998 | crLeftTop, crRightBottom, nBorderStyle, |
| 999 | dsBorder) + |
| 1000 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1001 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1002 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 1003 | |
| 1004 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 1005 | if (pNormalIcon) |
| 1006 | AddImageToAppearance("N", pNormalIcon); |
| 1007 | |
| 1008 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 1009 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 1010 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1011 | csRolloverCaption = csNormalCaption; |
| 1012 | pRolloverIcon = pNormalIcon; |
| 1013 | } |
| 1014 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1015 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1016 | |
| 1017 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1018 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1019 | crLeftTop, crRightBottom, |
| 1020 | nBorderStyle, dsBorder) + |
| 1021 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1022 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1023 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1024 | nLayout); |
| 1025 | |
| 1026 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1027 | if (pRolloverIcon) |
| 1028 | AddImageToAppearance("R", pRolloverIcon); |
| 1029 | |
| 1030 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1031 | csDownCaption = csNormalCaption; |
| 1032 | pDownIcon = pNormalIcon; |
| 1033 | } |
| 1034 | |
| 1035 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1036 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1037 | CPWL_Color crTemp = crLeftTop; |
| 1038 | crLeftTop = crRightBottom; |
| 1039 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1040 | break; |
| 1041 | } |
| 1042 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1043 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1044 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1045 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1046 | } |
| 1047 | default: |
| 1048 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1049 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1050 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1051 | font_map.SetAPType("D"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1052 | |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1053 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1054 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1055 | crLeftTop, crRightBottom, |
| 1056 | nBorderStyle, dsBorder) + |
| 1057 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1058 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1060 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1061 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1062 | if (pDownIcon) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1063 | AddImageToAppearance("D", pDownIcon); |
| 1064 | } else { |
| 1065 | RemoveAppearance("D"); |
| 1066 | RemoveAppearance("R"); |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | void CPDFSDK_Widget::ResetAppearance_CheckBox() { |
| 1071 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1072 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1073 | int iColorType; |
| 1074 | FX_FLOAT fc[4]; |
| 1075 | |
| 1076 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1077 | if (iColorType > 0) |
| 1078 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1079 | |
| 1080 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1081 | if (iColorType > 0) |
| 1082 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1083 | |
| 1084 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1085 | CPWL_Dash dsBorder(3, 0, 0); |
| 1086 | CPWL_Color crLeftTop, crRightBottom; |
| 1087 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1088 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1089 | switch (nBorderStyle) { |
| 1090 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1091 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1092 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1093 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1094 | fBorderWidth *= 2; |
| 1095 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1096 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1097 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1098 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1099 | fBorderWidth *= 2; |
| 1100 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1101 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1102 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1103 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1104 | break; |
| 1105 | } |
| 1106 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1107 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1108 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1109 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1110 | if (da.HasColor()) { |
| 1111 | da.GetColor(iColorType, fc); |
| 1112 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1113 | } |
| 1114 | |
| 1115 | int32_t nStyle = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1116 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1117 | if (csWCaption.GetLength() > 0) { |
| 1118 | switch (csWCaption[0]) { |
| 1119 | case L'l': |
| 1120 | nStyle = PCS_CIRCLE; |
| 1121 | break; |
| 1122 | case L'8': |
| 1123 | nStyle = PCS_CROSS; |
| 1124 | break; |
| 1125 | case L'u': |
| 1126 | nStyle = PCS_DIAMOND; |
| 1127 | break; |
| 1128 | case L'n': |
| 1129 | nStyle = PCS_SQUARE; |
| 1130 | break; |
| 1131 | case L'H': |
| 1132 | nStyle = PCS_STAR; |
| 1133 | break; |
| 1134 | default: // L'4' |
| 1135 | nStyle = PCS_CHECK; |
| 1136 | break; |
| 1137 | } |
| 1138 | } else { |
| 1139 | nStyle = PCS_CHECK; |
| 1140 | } |
| 1141 | |
| 1142 | CFX_ByteString csAP_N_ON = |
| 1143 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1144 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1145 | crLeftTop, crRightBottom, nBorderStyle, |
| 1146 | dsBorder); |
| 1147 | |
| 1148 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1149 | |
| 1150 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1151 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1152 | CPWL_Color crTemp = crLeftTop; |
| 1153 | crLeftTop = crRightBottom; |
| 1154 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1155 | break; |
| 1156 | } |
| 1157 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1158 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1159 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1160 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1161 | } |
| 1162 | default: |
| 1163 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | CFX_ByteString csAP_D_ON = |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1167 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1168 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1169 | crLeftTop, crRightBottom, nBorderStyle, |
| 1170 | dsBorder); |
| 1171 | |
| 1172 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1173 | |
| 1174 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1175 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1176 | |
| 1177 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1178 | pControl->GetCheckedAPState()); |
| 1179 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1180 | |
| 1181 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1182 | pControl->GetCheckedAPState()); |
| 1183 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1184 | |
| 1185 | CFX_ByteString csAS = GetAppState(); |
| 1186 | if (csAS.IsEmpty()) |
| 1187 | SetAppState("Off"); |
| 1188 | } |
| 1189 | |
| 1190 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1191 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1192 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1193 | int iColorType; |
| 1194 | FX_FLOAT fc[4]; |
| 1195 | |
| 1196 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1197 | if (iColorType > 0) |
| 1198 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1199 | |
| 1200 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1201 | if (iColorType > 0) |
| 1202 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1203 | |
| 1204 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1205 | CPWL_Dash dsBorder(3, 0, 0); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1206 | CPWL_Color crLeftTop; |
| 1207 | CPWL_Color crRightBottom; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1208 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1209 | switch (nBorderStyle) { |
| 1210 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1211 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1212 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1213 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1214 | fBorderWidth *= 2; |
| 1215 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1216 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1217 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1218 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1219 | fBorderWidth *= 2; |
| 1220 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1221 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1222 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1223 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1224 | break; |
| 1225 | } |
| 1226 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1227 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1228 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1229 | |
| 1230 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1231 | if (da.HasColor()) { |
| 1232 | da.GetColor(iColorType, fc); |
| 1233 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1234 | } |
| 1235 | |
| 1236 | int32_t nStyle = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1237 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1238 | if (csWCaption.GetLength() > 0) { |
| 1239 | switch (csWCaption[0]) { |
| 1240 | default: // L'l': |
| 1241 | nStyle = PCS_CIRCLE; |
| 1242 | break; |
| 1243 | case L'8': |
| 1244 | nStyle = PCS_CROSS; |
| 1245 | break; |
| 1246 | case L'u': |
| 1247 | nStyle = PCS_DIAMOND; |
| 1248 | break; |
| 1249 | case L'n': |
| 1250 | nStyle = PCS_SQUARE; |
| 1251 | break; |
| 1252 | case L'H': |
| 1253 | nStyle = PCS_STAR; |
| 1254 | break; |
| 1255 | case L'4': |
| 1256 | nStyle = PCS_CHECK; |
| 1257 | break; |
| 1258 | } |
| 1259 | } else { |
| 1260 | nStyle = PCS_CIRCLE; |
| 1261 | } |
| 1262 | |
| 1263 | CFX_ByteString csAP_N_ON; |
| 1264 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1265 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1266 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1267 | |
| 1268 | if (nStyle == PCS_CIRCLE) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1269 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1270 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1271 | crRightBottom = crBackground - 0.25f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1272 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1273 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1274 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1275 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1277 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1278 | CPWL_Utils::GetCircleBorderAppStream( |
| 1279 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1280 | nBorderStyle, dsBorder); |
| 1281 | } else { |
| 1282 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1283 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1284 | crLeftTop, crRightBottom, |
| 1285 | nBorderStyle, dsBorder); |
| 1286 | } |
| 1287 | |
| 1288 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1289 | |
| 1290 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1291 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1292 | CPWL_Color crTemp = crLeftTop; |
| 1293 | crLeftTop = crRightBottom; |
| 1294 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1295 | break; |
| 1296 | } |
| 1297 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1298 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1299 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1300 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1301 | } |
| 1302 | default: |
| 1303 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | CFX_ByteString csAP_D_ON; |
| 1307 | |
| 1308 | if (nStyle == PCS_CIRCLE) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1309 | CPWL_Color crBK = crBackground - 0.25f; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1310 | if (nBorderStyle == BorderStyle::BEVELED) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1311 | crLeftTop = crBackground - 0.25f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1312 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1313 | crBK = crBackground; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1314 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1315 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1316 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1317 | } |
| 1318 | |
| 1319 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1320 | CPWL_Utils::GetCircleBorderAppStream( |
| 1321 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1322 | nBorderStyle, dsBorder); |
| 1323 | } else { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1324 | csAP_D_ON = |
| 1325 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) + |
| 1326 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1327 | crLeftTop, crRightBottom, nBorderStyle, |
| 1328 | dsBorder); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1332 | |
| 1333 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1334 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1335 | |
| 1336 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1337 | pControl->GetCheckedAPState()); |
| 1338 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1339 | |
| 1340 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1341 | pControl->GetCheckedAPState()); |
| 1342 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1343 | |
| 1344 | CFX_ByteString csAS = GetAppState(); |
| 1345 | if (csAS.IsEmpty()) |
| 1346 | SetAppState("Off"); |
| 1347 | } |
| 1348 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1349 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1350 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1351 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1352 | CFX_ByteTextBuf sBody, sLines; |
| 1353 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1354 | CFX_FloatRect rcClient = GetClientRect(); |
| 1355 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1356 | rcButton.left = rcButton.right - 13; |
| 1357 | rcButton.Normalize(); |
| 1358 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1359 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1360 | pEdit->EnableRefresh(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1361 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1362 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1363 | pEdit->SetFontMap(&font_map); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1364 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1365 | CFX_FloatRect rcEdit = rcClient; |
| 1366 | rcEdit.right = rcButton.left; |
| 1367 | rcEdit.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1368 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1369 | pEdit->SetPlateRect(rcEdit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1370 | pEdit->SetAlignmentV(1, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1371 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1372 | FX_FLOAT fFontSize = GetFontSize(); |
| 1373 | if (IsFloatZero(fFontSize)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1374 | pEdit->SetAutoFontSize(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1375 | else |
| 1376 | pEdit->SetFontSize(fFontSize); |
| 1377 | |
| 1378 | pEdit->Initialize(); |
| 1379 | |
| 1380 | if (sValue) { |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1381 | pEdit->SetText(*sValue); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1382 | } else { |
| 1383 | int32_t nCurSel = pField->GetSelectedIndex(0); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1384 | if (nCurSel < 0) |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1385 | pEdit->SetText(pField->GetValue()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1386 | else |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1387 | pEdit->SetText(pField->GetOptionLabel(nCurSel)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1390 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1391 | |
| 1392 | CFX_ByteString sEdit = |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1393 | CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1394 | if (sEdit.GetLength() > 0) { |
| 1395 | sBody << "/Tx BMC\n" |
| 1396 | << "q\n"; |
| 1397 | if (rcContent.Width() > rcEdit.Width() || |
| 1398 | rcContent.Height() > rcEdit.Height()) { |
| 1399 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1400 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1401 | } |
| 1402 | |
| 1403 | CPWL_Color crText = GetTextPWLColor(); |
| 1404 | sBody << "BT\n" |
| 1405 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1406 | << "Q\nEMC\n"; |
| 1407 | } |
| 1408 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1409 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1410 | |
| 1411 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1412 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1413 | |
| 1414 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1415 | } |
| 1416 | |
| 1417 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1418 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1419 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1420 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1421 | CFX_ByteTextBuf sBody, sLines; |
| 1422 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1423 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1424 | pEdit->EnableRefresh(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1425 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1426 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1427 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1428 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1429 | 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] | 1430 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1431 | FX_FLOAT fFontSize = GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1432 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1433 | pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1434 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1435 | pEdit->Initialize(); |
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 | CFX_ByteTextBuf sList; |
| 1438 | FX_FLOAT fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1439 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1440 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1441 | int32_t nCount = pField->CountOptions(); |
| 1442 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1443 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1444 | for (int32_t i = nTop; i < nCount; ++i) { |
| 1445 | bool bSelected = false; |
| 1446 | for (int32_t j = 0; j < nSelCount; ++j) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1447 | if (pField->GetSelectedIndex(j) == i) { |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1448 | bSelected = true; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1449 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1450 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1451 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1452 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1453 | pEdit->SetText(pField->GetOptionLabel(i)); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1454 | |
| 1455 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1456 | FX_FLOAT fItemHeight = rcContent.Height(); |
| 1457 | |
| 1458 | if (bSelected) { |
| 1459 | CFX_FloatRect rcItem = |
| 1460 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
| 1461 | sList << "q\n" |
| 1462 | << CPWL_Utils::GetColorAppStream( |
| 1463 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1464 | 113.0f / 255.0f), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1465 | true) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1466 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1467 | << " " << rcItem.Height() << " re f\n" |
| 1468 | << "Q\n"; |
| 1469 | |
| 1470 | sList << "BT\n" |
| 1471 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1472 | true) |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1473 | << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1474 | << "ET\n"; |
| 1475 | } else { |
| 1476 | CPWL_Color crText = GetTextPWLColor(); |
| 1477 | sList << "BT\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1478 | << CPWL_Utils::GetColorAppStream(crText, true) |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1479 | << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1480 | << "ET\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -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 | fy -= fItemHeight; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1484 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1485 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1486 | if (sList.GetSize() > 0) { |
| 1487 | sBody << "/Tx BMC\n" |
| 1488 | << "q\n" |
| 1489 | << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1490 | << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1491 | sBody << sList << "Q\nEMC\n"; |
| 1492 | } |
| 1493 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1494 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1495 | sLines.AsStringC() + sBody.AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1496 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1497 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1500 | void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1501 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1502 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1503 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1504 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1505 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1506 | pEdit->EnableRefresh(false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1507 | |
dsinclair | 690c033 | 2016-10-11 09:13:01 -0700 | [diff] [blame] | 1508 | CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1509 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1510 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1511 | CFX_FloatRect rcClient = GetClientRect(); |
| 1512 | pEdit->SetPlateRect(rcClient); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1513 | pEdit->SetAlignmentH(pControl->GetControlAlignment(), true); |
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 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1516 | bool bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1517 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1518 | if (bMultiLine) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1519 | pEdit->SetMultiLine(true, true); |
| 1520 | pEdit->SetAutoReturn(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1521 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1522 | pEdit->SetAlignmentV(1, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1523 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1524 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1525 | uint16_t subWord = 0; |
| 1526 | if ((dwFieldFlags >> 13) & 1) { |
| 1527 | subWord = '*'; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1528 | pEdit->SetPasswordChar(subWord, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1529 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1530 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1531 | int nMaxLen = pField->GetMaxLen(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1532 | bool bCharArray = (dwFieldFlags >> 24) & 1; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1533 | FX_FLOAT fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1534 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1535 | #ifdef PDF_ENABLE_XFA |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1536 | CFX_WideString sValueTmp; |
| 1537 | if (!sValue && GetMixXFAWidget()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1538 | sValueTmp = GetValue(true); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1539 | sValue = &sValueTmp; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1540 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1541 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1542 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1543 | if (nMaxLen > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1544 | if (bCharArray) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1545 | pEdit->SetCharArray(nMaxLen); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1546 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1547 | if (IsFloatZero(fFontSize)) { |
| 1548 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
| 1549 | rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1550 | } |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1551 | } else { |
| 1552 | if (sValue) |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1553 | nMaxLen = sValue->GetLength(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1554 | pEdit->SetLimitChar(nMaxLen); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1555 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1558 | if (IsFloatZero(fFontSize)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1559 | pEdit->SetAutoFontSize(true, true); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1560 | else |
| 1561 | pEdit->SetFontSize(fFontSize); |
| 1562 | |
| 1563 | pEdit->Initialize(); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1564 | pEdit->SetText(sValue ? *sValue : pField->GetValue()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1565 | |
| 1566 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1567 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 1568 | pEdit.get(), CFX_PointF(), nullptr, !bCharArray, subWord); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1569 | |
| 1570 | if (sEdit.GetLength() > 0) { |
| 1571 | sBody << "/Tx BMC\n" |
| 1572 | << "q\n"; |
| 1573 | if (rcContent.Width() > rcClient.Width() || |
| 1574 | rcContent.Height() > rcClient.Height()) { |
| 1575 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1576 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1577 | } |
| 1578 | CPWL_Color crText = GetTextPWLColor(); |
| 1579 | sBody << "BT\n" |
| 1580 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1581 | << "Q\nEMC\n"; |
| 1582 | } |
| 1583 | |
| 1584 | if (bCharArray) { |
| 1585 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1586 | case BorderStyle::SOLID: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1587 | CFX_ByteString sColor = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1588 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1589 | if (sColor.GetLength() > 0) { |
| 1590 | sLines << "q\n" |
| 1591 | << GetBorderWidth() << " w\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1592 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1593 | << " 2 J 0 j\n"; |
| 1594 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1595 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1596 | sLines << rcClient.left + |
| 1597 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1598 | << " " << rcClient.bottom << " m\n" |
| 1599 | << rcClient.left + |
| 1600 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1601 | << " " << rcClient.top << " l S\n"; |
| 1602 | } |
| 1603 | |
| 1604 | sLines << "Q\n"; |
| 1605 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1606 | break; |
| 1607 | } |
| 1608 | case BorderStyle::DASH: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1609 | CFX_ByteString sColor = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1610 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1611 | if (sColor.GetLength() > 0) { |
| 1612 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1613 | |
| 1614 | sLines << "q\n" |
| 1615 | << GetBorderWidth() << " w\n" |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1616 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1617 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1618 | << dsBorder.nPhase << " d\n"; |
| 1619 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1620 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1621 | sLines << rcClient.left + |
| 1622 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1623 | << " " << rcClient.bottom << " m\n" |
| 1624 | << rcClient.left + |
| 1625 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1626 | << " " << rcClient.top << " l S\n"; |
| 1627 | } |
| 1628 | |
| 1629 | sLines << "Q\n"; |
| 1630 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1631 | break; |
| 1632 | } |
| 1633 | default: |
| 1634 | break; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1635 | } |
| 1636 | } |
| 1637 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1638 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1639 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1640 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1643 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1644 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1645 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1646 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1647 | case BorderStyle::BEVELED: |
| 1648 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1649 | fBorderWidth *= 2.0f; |
| 1650 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1651 | default: |
| 1652 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1658 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1659 | CFX_FloatRect rectAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1660 | FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; |
| 1661 | FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; |
| 1662 | |
| 1663 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1664 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1665 | switch (abs(pControl->GetRotation() % 360)) { |
| 1666 | case 0: |
| 1667 | case 180: |
| 1668 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1669 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1670 | break; |
| 1671 | case 90: |
| 1672 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1673 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1674 | break; |
| 1675 | } |
| 1676 | |
| 1677 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1680 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1681 | CPWL_Color crBackground = GetFillPWLColor(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1682 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1683 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1684 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1685 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1688 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1689 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1690 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1691 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1692 | CPWL_Color crLeftTop, crRightBottom; |
| 1693 | |
| 1694 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1695 | CPWL_Dash dsBorder(3, 0, 0); |
| 1696 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1697 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1698 | switch (nBorderStyle) { |
| 1699 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1700 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1701 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1702 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1703 | fBorderWidth *= 2; |
| 1704 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame^] | 1705 | crRightBottom = crBackground / 2.0f; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1706 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1707 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1708 | fBorderWidth *= 2; |
| 1709 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1710 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1711 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1712 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1713 | break; |
| 1714 | } |
| 1715 | |
| 1716 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1717 | crLeftTop, crRightBottom, nBorderStyle, |
| 1718 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1721 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1722 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1723 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1724 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1725 | FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; |
| 1726 | FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; |
| 1727 | |
| 1728 | switch (abs(pControl->GetRotation() % 360)) { |
| 1729 | case 0: |
| 1730 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1731 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1732 | break; |
| 1733 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1734 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1735 | break; |
| 1736 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1737 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1738 | break; |
| 1739 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1740 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1741 | break; |
| 1742 | } |
| 1743 | |
| 1744 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1747 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1748 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1749 | |
| 1750 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1751 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1752 | if (da.HasColor()) { |
| 1753 | int32_t iColorType; |
| 1754 | FX_FLOAT fc[4]; |
| 1755 | da.GetColor(iColorType, fc); |
| 1756 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1757 | } |
| 1758 | |
| 1759 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1762 | CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 1763 | CPWL_Color crBorder; |
| 1764 | |
| 1765 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1766 | int32_t iColorType; |
| 1767 | FX_FLOAT fc[4]; |
| 1768 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 1769 | if (iColorType > 0) |
| 1770 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1771 | |
| 1772 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1775 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1776 | CPWL_Color crFill; |
| 1777 | |
| 1778 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1779 | int32_t iColorType; |
| 1780 | FX_FLOAT fc[4]; |
| 1781 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1782 | if (iColorType > 0) |
| 1783 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1784 | |
| 1785 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1788 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1789 | CPDF_Stream* pImage) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1790 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 1791 | CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1792 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1793 | CFX_ByteString sImageAlias = "IMG"; |
| 1794 | |
| 1795 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1796 | sImageAlias = pImageDict->GetStringFor("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1797 | if (sImageAlias.IsEmpty()) |
| 1798 | sImageAlias = "IMG"; |
| 1799 | } |
| 1800 | |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 1801 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1802 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 1803 | if (!pStreamResList) |
| 1804 | pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1805 | |
tsepez | 0e606b5 | 2016-11-18 16:22:41 -0800 | [diff] [blame] | 1806 | CPDF_Dictionary* pXObject = |
| 1807 | pStreamResList->SetNewFor<CPDF_Dictionary>("XObject"); |
| 1808 | pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum()); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1809 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1810 | |
| 1811 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1812 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) |
| 1813 | pAPDict->RemoveFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1816 | bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1817 | PDFSDK_FieldAction& data, |
| 1818 | CPDFSDK_PageView* pPageView) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 1819 | CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1820 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1821 | #ifdef PDF_ENABLE_XFA |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1822 | CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1823 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1824 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1825 | |
| 1826 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1827 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1828 | CXFA_EventParam param; |
| 1829 | param.m_eType = eEventType; |
| 1830 | param.m_wsChange = data.sChange; |
| 1831 | param.m_iCommitKey = data.nCommitKey; |
| 1832 | param.m_bShift = data.bShift; |
| 1833 | param.m_iSelStart = data.nSelStart; |
| 1834 | param.m_iSelEnd = data.nSelEnd; |
| 1835 | param.m_wsFullText = data.sValue; |
| 1836 | param.m_bKeyDown = data.bKeyDown; |
| 1837 | param.m_bModifier = data.bModifier; |
| 1838 | param.m_wsNewText = data.sValue; |
| 1839 | if (data.nSelEnd > data.nSelStart) |
| 1840 | param.m_wsNewText.Delete(data.nSelStart, |
| 1841 | data.nSelEnd - data.nSelStart); |
| 1842 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1843 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1844 | param.m_wsPrevText = data.sValue; |
| 1845 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1846 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1847 | param.m_pTarget = pAcc; |
| 1848 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1849 | |
dsinclair | 521b750 | 2016-11-02 13:02:28 -0700 | [diff] [blame] | 1850 | if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1851 | pDocView->UpdateDocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1852 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1853 | if (nRet == XFA_EVENTERROR_Success) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1854 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1858 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1859 | |
| 1860 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1861 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
dsinclair | b402b17 | 2016-10-11 09:26:32 -0700 | [diff] [blame] | 1862 | CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); |
dsinclair | 19c198b | 2016-10-11 12:51:37 -0700 | [diff] [blame] | 1863 | return pActionHandler->DoAction_Field(action, type, pFormFillEnv, |
| 1864 | GetFormField(), data); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1865 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 1866 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1870 | switch (eAAT) { |
| 1871 | case CPDF_AAction::CursorEnter: |
| 1872 | case CPDF_AAction::CursorExit: |
| 1873 | case CPDF_AAction::ButtonDown: |
| 1874 | case CPDF_AAction::ButtonUp: |
| 1875 | case CPDF_AAction::GetFocus: |
| 1876 | case CPDF_AAction::LoseFocus: |
| 1877 | case CPDF_AAction::PageOpen: |
| 1878 | case CPDF_AAction::PageClose: |
| 1879 | case CPDF_AAction::PageVisible: |
| 1880 | case CPDF_AAction::PageInvisible: |
| 1881 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1882 | |
| 1883 | case CPDF_AAction::KeyStroke: |
| 1884 | case CPDF_AAction::Format: |
| 1885 | case CPDF_AAction::Validate: |
| 1886 | case CPDF_AAction::Calculate: { |
| 1887 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1888 | if (pField->GetAdditionalAction().GetDict()) |
| 1889 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1890 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1891 | } |
| 1892 | default: |
| 1893 | break; |
| 1894 | } |
| 1895 | |
| 1896 | return CPDF_Action(); |
| 1897 | } |
| 1898 | |
| 1899 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1900 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1901 | return pFormField->GetAlternateName(); |
| 1902 | } |
| 1903 | |
| 1904 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1905 | return m_nAppAge; |
| 1906 | } |
| 1907 | |
| 1908 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1909 | return m_nValueAge; |
| 1910 | } |