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