John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 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 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 7 | #include "fpdfsdk/include/fsdk_baseform.h" |
| 8 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 9 | #include <algorithm> |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 10 | #include <map> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 11 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 12 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 13 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 15 | #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
| 16 | #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 17 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 18 | #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
thestig | 25fa42f | 2016-05-25 21:39:46 -0700 | [diff] [blame] | 19 | #include "core/fxge/include/fx_ge.h" |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 20 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fxedit/include/fxet_edit.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 22 | #include "fpdfsdk/include/fsdk_actionhandler.h" |
| 23 | #include "fpdfsdk/include/fsdk_baseannot.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 24 | #include "fpdfsdk/include/fsdk_define.h" |
| 25 | #include "fpdfsdk/include/fsdk_mgr.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 26 | #include "fpdfsdk/javascript/ijs_context.h" |
| 27 | #include "fpdfsdk/javascript/ijs_runtime.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 28 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 29 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 30 | #ifdef PDF_ENABLE_XFA |
dsinclair | 89bdd08 | 2016-04-06 10:47:54 -0700 | [diff] [blame] | 31 | #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 32 | #include "fpdfsdk/fpdfxfa/include/fpdfxfa_util.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 33 | #include "xfa/fxfa/include/cxfa_eventparam.h" |
| 34 | #include "xfa/fxfa/include/xfa_ffdocview.h" |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 35 | #include "xfa/fxfa/include/xfa_ffwidget.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 36 | #include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 37 | #endif // PDF_ENABLE_XFA |
| 38 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 39 | PDFSDK_FieldAction::PDFSDK_FieldAction() |
| 40 | : bModifier(FALSE), |
| 41 | bShift(FALSE), |
| 42 | nCommitKey(0), |
| 43 | bKeyDown(FALSE), |
| 44 | nSelEnd(0), |
| 45 | nSelStart(0), |
| 46 | bWillCommit(FALSE), |
| 47 | bFieldFull(FALSE), |
| 48 | bRC(TRUE) {} |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 51 | CPDFSDK_PageView* pPageView, |
| 52 | CPDFSDK_InterForm* pInterForm) |
| 53 | : CPDFSDK_BAAnnot(pAnnot, pPageView), |
| 54 | m_pInterForm(pInterForm), |
| 55 | m_nAppAge(0), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 56 | m_nValueAge(0) |
| 57 | #ifdef PDF_ENABLE_XFA |
| 58 | , |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 59 | m_hMixXFAWidget(nullptr), |
| 60 | m_pWidgetHandler(nullptr) |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 61 | #endif // PDF_ENABLE_XFA |
| 62 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | CPDFSDK_Widget::~CPDFSDK_Widget() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 67 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 68 | CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 70 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 72 | if (!m_hMixXFAWidget) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 73 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | CFX_WideString sName; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 75 | if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 76 | sName = GetAnnotName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | if (sName.IsEmpty()) |
| 78 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 79 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 81 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 82 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | if (!sName.IsEmpty()) |
tsepez | 70c5520 | 2016-04-14 15:32:35 -0700 | [diff] [blame] | 84 | m_hMixXFAWidget = pDocView->GetWidgetByName(sName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 86 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | return m_hMixXFAWidget; |
| 88 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 89 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 90 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | } |
| 92 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 93 | CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 95 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 97 | if (CXFA_FFDocView* pDocView = pDoc->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()) |
tsepez | 70c5520 | 2016-04-14 15:32:35 -0700 | [diff] [blame] | 100 | return pDocView->GetWidgetByName(sName); |
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 { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 109 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 111 | if (!m_pWidgetHandler) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 112 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
| 114 | } |
| 115 | } |
| 116 | return m_pWidgetHandler; |
| 117 | } |
| 118 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 119 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 123 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 124 | |
| 125 | switch (eXFAAAT) { |
| 126 | case PDFSDK_XFA_Click: |
| 127 | eEventType = XFA_EVENT_Click; |
| 128 | break; |
| 129 | case PDFSDK_XFA_Full: |
| 130 | eEventType = XFA_EVENT_Full; |
| 131 | break; |
| 132 | case PDFSDK_XFA_PreOpen: |
| 133 | eEventType = XFA_EVENT_PreOpen; |
| 134 | break; |
| 135 | case PDFSDK_XFA_PostOpen: |
| 136 | eEventType = XFA_EVENT_PostOpen; |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | return eEventType; |
| 141 | } |
| 142 | |
| 143 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
| 144 | FX_BOOL bWillCommit) { |
| 145 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 146 | |
| 147 | switch (eAAT) { |
| 148 | case CPDF_AAction::CursorEnter: |
| 149 | eEventType = XFA_EVENT_MouseEnter; |
| 150 | break; |
| 151 | case CPDF_AAction::CursorExit: |
| 152 | eEventType = XFA_EVENT_MouseExit; |
| 153 | break; |
| 154 | case CPDF_AAction::ButtonDown: |
| 155 | eEventType = XFA_EVENT_MouseDown; |
| 156 | break; |
| 157 | case CPDF_AAction::ButtonUp: |
| 158 | eEventType = XFA_EVENT_MouseUp; |
| 159 | break; |
| 160 | case CPDF_AAction::GetFocus: |
| 161 | eEventType = XFA_EVENT_Enter; |
| 162 | break; |
| 163 | case CPDF_AAction::LoseFocus: |
| 164 | eEventType = XFA_EVENT_Exit; |
| 165 | break; |
| 166 | case CPDF_AAction::PageOpen: |
| 167 | break; |
| 168 | case CPDF_AAction::PageClose: |
| 169 | break; |
| 170 | case CPDF_AAction::PageVisible: |
| 171 | break; |
| 172 | case CPDF_AAction::PageInvisible: |
| 173 | break; |
| 174 | case CPDF_AAction::KeyStroke: |
| 175 | if (!bWillCommit) { |
| 176 | eEventType = XFA_EVENT_Change; |
| 177 | } |
| 178 | break; |
| 179 | case CPDF_AAction::Validate: |
| 180 | eEventType = XFA_EVENT_Validate; |
| 181 | break; |
| 182 | case CPDF_AAction::OpenPage: |
| 183 | case CPDF_AAction::ClosePage: |
| 184 | case CPDF_AAction::Format: |
| 185 | case CPDF_AAction::Calculate: |
| 186 | case CPDF_AAction::CloseDocument: |
| 187 | case CPDF_AAction::SaveDocument: |
| 188 | case CPDF_AAction::DocumentSaved: |
| 189 | case CPDF_AAction::PrintDocument: |
| 190 | case CPDF_AAction::DocumentPrinted: |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | return eEventType; |
| 195 | } |
| 196 | |
| 197 | FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 198 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 199 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 201 | |
| 202 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 203 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 204 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 205 | CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | if (pXFAWidgetHandler->HasEvent(pAcc, eEventType)) |
| 207 | return TRUE; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 212 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return FALSE; |
| 219 | } |
| 220 | |
| 221 | FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 222 | PDFSDK_FieldAction& data, |
| 223 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 224 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 225 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 226 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 228 | |
| 229 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 230 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | CXFA_EventParam param; |
| 232 | param.m_eType = eEventType; |
| 233 | param.m_wsChange = data.sChange; |
| 234 | param.m_iCommitKey = data.nCommitKey; |
| 235 | param.m_bShift = data.bShift; |
| 236 | param.m_iSelStart = data.nSelStart; |
| 237 | param.m_iSelEnd = data.nSelEnd; |
| 238 | param.m_wsFullText = data.sValue; |
| 239 | param.m_bKeyDown = data.bKeyDown; |
| 240 | param.m_bModifier = data.bModifier; |
| 241 | param.m_wsNewText = data.sValue; |
| 242 | if (data.nSelEnd > data.nSelStart) |
| 243 | param.m_wsNewText.Delete(data.nSelStart, |
| 244 | data.nSelEnd - data.nSelStart); |
| 245 | for (int i = 0; i < data.sChange.GetLength(); i++) |
| 246 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 247 | param.m_wsPrevText = data.sValue; |
| 248 | |
| 249 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 250 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 251 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 252 | CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | param.m_pTarget = pAcc; |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 254 | if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
| 255 | XFA_EVENTERROR_Success) { |
| 256 | return FALSE; |
| 257 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 260 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 261 | param.m_pTarget = pAcc; |
| 262 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 263 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 264 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | pDocView->UpdateDocView(); |
| 266 | } |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 267 | return nRet == XFA_EVENTERROR_Success; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return FALSE; |
| 273 | } |
| 274 | |
| 275 | void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 276 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 277 | CPDF_FormField* pFormField = GetFormField(); |
| 278 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 279 | switch (GetFieldType()) { |
| 280 | case FIELDTYPE_CHECKBOX: |
| 281 | case FIELDTYPE_RADIOBUTTON: { |
| 282 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 283 | XFA_CHECKSTATE eCheckState = |
| 284 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 285 | pWidgetAcc->SetCheckState(eCheckState, true); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 286 | } break; |
| 287 | case FIELDTYPE_TEXTFIELD: |
| 288 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 289 | break; |
| 290 | case FIELDTYPE_LISTBOX: { |
| 291 | pWidgetAcc->ClearAllSelections(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 292 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 293 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 294 | int nIndex = pFormField->GetSelectedIndex(i); |
| 295 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 296 | pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 298 | } break; |
| 299 | case FIELDTYPE_COMBOBOX: { |
| 300 | pWidgetAcc->ClearAllSelections(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 302 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 303 | int nIndex = pFormField->GetSelectedIndex(i); |
| 304 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
thestig | 800222e | 2016-05-26 22:00:29 -0700 | [diff] [blame] | 305 | pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 306 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 307 | } |
| 308 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 309 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 310 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 311 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 312 | |
| 313 | if (bSynchronizeElse) |
| 314 | pWidgetAcc->ProcessValueChanged(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void CPDFSDK_Widget::SynchronizeXFAValue() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 321 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 322 | CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 323 | if (!pXFADocView) |
| 324 | return; |
| 325 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 326 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 327 | if (GetXFAWidgetHandler()) { |
| 328 | CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
| 329 | GetFormControl()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void CPDFSDK_Widget::SynchronizeXFAItems() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 336 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 337 | CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | if (!pXFADocView) |
| 339 | return; |
| 340 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 341 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 342 | if (GetXFAWidgetHandler()) |
| 343 | SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 347 | void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
| 348 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | CPDF_FormField* pFormField, |
| 350 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 351 | ASSERT(hWidget); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 352 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 353 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 354 | switch (pFormField->GetFieldType()) { |
| 355 | case FIELDTYPE_CHECKBOX: { |
| 356 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 357 | pFormField->CheckControl( |
| 358 | pFormField->GetControlIndex(pFormControl), |
| 359 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 360 | } |
| 361 | } break; |
| 362 | case FIELDTYPE_RADIOBUTTON: { |
| 363 | // TODO(weili): Check whether we need to handle checkbox and radio |
| 364 | // button differently, otherwise, merge these two cases. |
| 365 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 366 | pFormField->CheckControl( |
| 367 | pFormField->GetControlIndex(pFormControl), |
| 368 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 369 | } |
| 370 | } break; |
| 371 | case FIELDTYPE_TEXTFIELD: { |
| 372 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 373 | CFX_WideString sValue; |
| 374 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 375 | pFormField->SetValue(sValue, TRUE); |
| 376 | } |
| 377 | } break; |
| 378 | case FIELDTYPE_LISTBOX: { |
| 379 | pFormField->ClearSelection(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 381 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 382 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 383 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 384 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 385 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 386 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 389 | } |
| 390 | } break; |
| 391 | case FIELDTYPE_COMBOBOX: { |
| 392 | pFormField->ClearSelection(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 394 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 395 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 396 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 397 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 398 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 399 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 401 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 402 | |
| 403 | CFX_WideString sValue; |
| 404 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 405 | pFormField->SetValue(sValue, TRUE); |
| 406 | } |
| 407 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 411 | void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, |
| 412 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | CPDF_FormField* pFormField, |
| 414 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 415 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 416 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 417 | switch (pFormField->GetFieldType()) { |
| 418 | case FIELDTYPE_LISTBOX: { |
| 419 | pFormField->ClearSelection(FALSE); |
| 420 | pFormField->ClearOptions(TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 422 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 423 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 424 | CFX_WideString swText; |
| 425 | pWidgetAcc->GetChoiceListItem(swText, i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 426 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 427 | pFormField->InsertOption(swText, i, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 429 | } |
| 430 | } break; |
| 431 | case FIELDTYPE_COMBOBOX: { |
| 432 | pFormField->ClearSelection(FALSE); |
| 433 | pFormField->ClearOptions(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 434 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 435 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 436 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 437 | CFX_WideString swText; |
| 438 | pWidgetAcc->GetChoiceListItem(swText, i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 440 | pFormField->InsertOption(swText, i, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 442 | } |
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 | pFormField->SetValue(L"", TRUE); |
| 445 | } break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 448 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 449 | |
| 450 | FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( |
| 451 | CPDF_Annot::AppearanceMode mode) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 452 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | if (!pAP) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 454 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 455 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | // Choose the right sub-ap |
| 457 | const FX_CHAR* ap_entry = "N"; |
| 458 | if (mode == CPDF_Annot::Down) |
| 459 | ap_entry = "D"; |
| 460 | else if (mode == CPDF_Annot::Rollover) |
| 461 | ap_entry = "R"; |
| 462 | if (!pAP->KeyExist(ap_entry)) |
| 463 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 464 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | // Get the AP stream or subdirectory |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 466 | CPDF_Object* psub = pAP->GetDirectObjectBy(ap_entry); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 467 | if (!psub) |
| 468 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 469 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | int nFieldType = GetFieldType(); |
| 471 | switch (nFieldType) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 472 | case FIELDTYPE_PUSHBUTTON: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 473 | case FIELDTYPE_COMBOBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 474 | case FIELDTYPE_LISTBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 475 | case FIELDTYPE_TEXTFIELD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 476 | case FIELDTYPE_SIGNATURE: |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 477 | return psub->IsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | case FIELDTYPE_CHECKBOX: |
| 479 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 480 | if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 481 | return !!pSubDict->GetStreamBy(GetAppState()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | } |
| 483 | return FALSE; |
| 484 | } |
| 485 | return TRUE; |
| 486 | } |
| 487 | |
| 488 | int CPDFSDK_Widget::GetFieldType() const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 489 | return GetFormField()->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 493 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 495 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 496 | int nDocType = pDoc->GetDocType(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 497 | if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
| 498 | return TRUE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 499 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 500 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 501 | } |
| 502 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 503 | int CPDFSDK_Widget::GetLayoutOrder() const { |
| 504 | return 2; |
| 505 | } |
| 506 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | int CPDFSDK_Widget::GetFieldFlags() const { |
| 508 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | CPDF_FormControl* pFormControl = |
| 510 | pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); |
| 511 | CPDF_FormField* pFormField = pFormControl->GetField(); |
| 512 | return pFormField->GetFieldFlags(); |
| 513 | } |
| 514 | |
| 515 | CFX_ByteString CPDFSDK_Widget::GetSubType() const { |
| 516 | int nType = GetFieldType(); |
| 517 | |
| 518 | if (nType == FIELDTYPE_SIGNATURE) |
| 519 | return BFFT_SIGNATURE; |
| 520 | return CPDFSDK_Annot::GetSubType(); |
| 521 | } |
| 522 | |
| 523 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 524 | return GetFormControl()->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | return pPDFInterForm->GetControlByDict(GetAnnotDict()); |
| 530 | } |
| 531 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 532 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl( |
| 533 | CPDF_InterForm* pInterForm, |
| 534 | const CPDF_Dictionary* pAnnotDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 535 | ASSERT(pAnnotDict); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 536 | return pInterForm->GetControlByDict(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | int CPDFSDK_Widget::GetRotate() const { |
| 540 | CPDF_FormControl* pCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | return pCtrl->GetRotation() % 360; |
| 542 | } |
| 543 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 544 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 545 | CFX_WideString CPDFSDK_Widget::GetName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 547 | return pFormField->GetFullName(); |
| 548 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 549 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | |
| 551 | FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { |
| 552 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | int iColorType = 0; |
| 554 | color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType)); |
| 555 | |
| 556 | return iColorType != COLORTYPE_TRANSPARENT; |
| 557 | } |
| 558 | |
| 559 | FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { |
| 560 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | int iColorType = 0; |
| 562 | color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType)); |
| 563 | |
| 564 | return iColorType != COLORTYPE_TRANSPARENT; |
| 565 | } |
| 566 | |
| 567 | FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { |
| 568 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 570 | if (da.HasColor()) { |
| 571 | FX_ARGB argb; |
| 572 | int iColorType = COLORTYPE_TRANSPARENT; |
| 573 | da.GetColor(argb, iColorType); |
| 574 | color = FX_ARGBTOCOLORREF(argb); |
| 575 | |
| 576 | return iColorType != COLORTYPE_TRANSPARENT; |
| 577 | } |
| 578 | |
| 579 | return FALSE; |
| 580 | } |
| 581 | |
| 582 | FX_FLOAT CPDFSDK_Widget::GetFontSize() const { |
| 583 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
| 585 | CFX_ByteString csFont = ""; |
| 586 | FX_FLOAT fFontSize = 0.0f; |
| 587 | pDa.GetFont(csFont, fFontSize); |
| 588 | |
| 589 | return fFontSize; |
| 590 | } |
| 591 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 592 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 593 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 594 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 595 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 596 | if (nIndex < pWidgetAcc->CountSelectedItems()) |
| 597 | return pWidgetAcc->GetSelectedItem(nIndex); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 598 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 600 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 602 | return pFormField->GetSelectedIndex(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 605 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 606 | CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 607 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 608 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 609 | CFX_WideString sValue; |
| 610 | pWidgetAcc->GetValue( |
| 611 | sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit); |
| 612 | return sValue; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 613 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 615 | #else |
| 616 | CFX_WideString CPDFSDK_Widget::GetValue() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 617 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 619 | return pFormField->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { |
| 623 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 624 | return pFormField->GetDefaultValue(); |
| 625 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 626 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 627 | CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
| 628 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | return pFormField->GetOptionLabel(nIndex); |
| 630 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 631 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 632 | int CPDFSDK_Widget::CountOptions() const { |
| 633 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 634 | return pFormField->CountOptions(); |
| 635 | } |
| 636 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 637 | FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 638 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 639 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 640 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 641 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 642 | return pWidgetAcc->GetItemState(nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 644 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 647 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | CPDF_FormField* pFormField = GetFormField(); |
| 649 | return pFormField->IsItemSelected(nIndex); |
| 650 | } |
| 651 | |
| 652 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 653 | CPDF_FormField* pFormField = GetFormField(); |
| 654 | return pFormField->GetTopVisibleIndex(); |
| 655 | } |
| 656 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 657 | bool CPDFSDK_Widget::IsChecked() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 658 | #ifdef PDF_ENABLE_XFA |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 659 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 660 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) |
| 661 | return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 662 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 663 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 664 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 665 | return pFormCtrl->IsChecked(); |
| 666 | } |
| 667 | |
| 668 | int CPDFSDK_Widget::GetAlignment() const { |
| 669 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | return pFormCtrl->GetControlAlignment(); |
| 671 | } |
| 672 | |
| 673 | int CPDFSDK_Widget::GetMaxLen() const { |
| 674 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | return pFormField->GetMaxLen(); |
| 676 | } |
| 677 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 678 | void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 679 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 680 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 681 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
| 682 | bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 683 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 684 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
| 685 | ResetAppearance(TRUE); |
| 686 | if (!bNotify) |
| 687 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 688 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { |
| 692 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 693 | pFormField->SetValue(sValue, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 694 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 695 | if (!bNotify) |
| 696 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 697 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} |
| 701 | void CPDFSDK_Widget::SetOptionSelection(int index, |
| 702 | FX_BOOL bSelected, |
| 703 | FX_BOOL bNotify) { |
| 704 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 705 | pFormField->SetItemSelection(index, bSelected, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 706 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 707 | if (!bNotify) |
| 708 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 709 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { |
| 713 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 714 | pFormField->ClearSelection(bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 715 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 716 | if (!bNotify) |
| 717 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 718 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 722 | |
| 723 | void CPDFSDK_Widget::SetAppModified() { |
| 724 | m_bAppModified = TRUE; |
| 725 | } |
| 726 | |
| 727 | void CPDFSDK_Widget::ClearAppModified() { |
| 728 | m_bAppModified = FALSE; |
| 729 | } |
| 730 | |
| 731 | FX_BOOL CPDFSDK_Widget::IsAppModified() const { |
| 732 | return m_bAppModified; |
| 733 | } |
| 734 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 735 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { |
| 737 | switch (GetFieldType()) { |
| 738 | case FIELDTYPE_TEXTFIELD: |
| 739 | case FIELDTYPE_COMBOBOX: { |
| 740 | FX_BOOL bFormated = FALSE; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 741 | CFX_WideString sValue = OnFormat(bFormated); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 742 | ResetAppearance(bFormated ? sValue.c_str() : nullptr, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 743 | } break; |
| 744 | default: |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 745 | ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 746 | break; |
| 747 | } |
| 748 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 749 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 750 | |
| 751 | void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, |
| 752 | FX_BOOL bValueChanged) { |
| 753 | SetAppModified(); |
| 754 | |
| 755 | m_nAppAge++; |
| 756 | if (m_nAppAge > 999999) |
| 757 | m_nAppAge = 0; |
| 758 | if (bValueChanged) |
| 759 | m_nValueAge++; |
| 760 | |
| 761 | int nFieldType = GetFieldType(); |
| 762 | |
| 763 | switch (nFieldType) { |
| 764 | case FIELDTYPE_PUSHBUTTON: |
| 765 | ResetAppearance_PushButton(); |
| 766 | break; |
| 767 | case FIELDTYPE_CHECKBOX: |
| 768 | ResetAppearance_CheckBox(); |
| 769 | break; |
| 770 | case FIELDTYPE_RADIOBUTTON: |
| 771 | ResetAppearance_RadioButton(); |
| 772 | break; |
| 773 | case FIELDTYPE_COMBOBOX: |
| 774 | ResetAppearance_ComboBox(sValue); |
| 775 | break; |
| 776 | case FIELDTYPE_LISTBOX: |
| 777 | ResetAppearance_ListBox(); |
| 778 | break; |
| 779 | case FIELDTYPE_TEXTFIELD: |
| 780 | ResetAppearance_TextField(sValue); |
| 781 | break; |
| 782 | } |
| 783 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | m_pAnnot->ClearCachedAP(); |
| 785 | } |
| 786 | |
| 787 | CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormated) { |
| 788 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 789 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 790 | return m_pInterForm->OnFormat(pFormField, bFormated); |
| 791 | } |
| 792 | |
| 793 | void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) { |
| 794 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 795 | ASSERT(pFormField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 796 | m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 800 | const CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 801 | CPDF_Annot::AppearanceMode mode, |
| 802 | const CPDF_RenderOptions* pOptions) { |
| 803 | int nFieldType = GetFieldType(); |
| 804 | |
| 805 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 806 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 807 | mode == CPDF_Annot::Normal && |
| 808 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 809 | CFX_PathData pathData; |
| 810 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 811 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 812 | |
| 813 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 814 | rcAnnot.top); |
| 815 | |
| 816 | CFX_GraphStateData gsd; |
| 817 | gsd.m_LineWidth = 0.0f; |
| 818 | |
| 819 | pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, |
| 820 | FXFILL_ALTERNATE); |
| 821 | } else { |
| 822 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | void CPDFSDK_Widget::UpdateField() { |
| 827 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 828 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 829 | m_pInterForm->UpdateField(pFormField); |
| 830 | } |
| 831 | |
| 832 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 833 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | int nFieldType = GetFieldType(); |
| 835 | if (m_pInterForm->IsNeedHighLight(nFieldType)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 836 | CFX_FloatRect rc = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 837 | FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType); |
| 838 | uint8_t alpha = m_pInterForm->GetHighlightAlpha(); |
| 839 | |
| 840 | CFX_FloatRect rcDevice; |
| 841 | ASSERT(m_pInterForm->GetDocument()); |
| 842 | CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv(); |
| 843 | if (!pEnv) |
| 844 | return; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 845 | CFX_Matrix page2device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | pPageView->GetCurrentMatrix(page2device); |
| 847 | page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), |
| 848 | rcDevice.left, rcDevice.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 849 | page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), |
| 850 | rcDevice.right, rcDevice.top); |
| 851 | |
| 852 | rcDevice.Normalize(); |
| 853 | |
| 854 | FX_ARGB argb = ArgbEncode((int)alpha, color); |
| 855 | FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right, |
| 856 | (int)rcDevice.bottom); |
| 857 | pDevice->FillRect(&rcDev, argb); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | } |
| 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 | |
| 944 | if (pControl->HasMKEntry("CA")) { |
| 945 | csNormalCaption = pControl->GetNormalCaption(); |
| 946 | } |
| 947 | if (pControl->HasMKEntry("RC")) { |
| 948 | csRolloverCaption = pControl->GetRolloverCaption(); |
| 949 | } |
| 950 | if (pControl->HasMKEntry("AC")) { |
| 951 | csDownCaption = pControl->GetDownCaption(); |
| 952 | } |
| 953 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 954 | CPDF_Stream* pNormalIcon = nullptr; |
| 955 | CPDF_Stream* pRolloverIcon = nullptr; |
| 956 | CPDF_Stream* pDownIcon = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | |
| 958 | if (pControl->HasMKEntry("I")) { |
| 959 | pNormalIcon = pControl->GetNormalIcon(); |
| 960 | } |
| 961 | if (pControl->HasMKEntry("RI")) { |
| 962 | pRolloverIcon = pControl->GetRolloverIcon(); |
| 963 | } |
| 964 | if (pControl->HasMKEntry("IX")) { |
| 965 | pDownIcon = pControl->GetDownIcon(); |
| 966 | } |
| 967 | |
| 968 | if (pNormalIcon) { |
| 969 | if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 970 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | pImageDict->SetAtString("Name", "ImgA"); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | if (pRolloverIcon) { |
| 976 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 977 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | pImageDict->SetAtString("Name", "ImgB"); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | if (pDownIcon) { |
| 983 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 984 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 985 | pImageDict->SetAtString("Name", "ImgC"); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 990 | |
| 991 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 992 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 993 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 994 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 995 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 996 | |
| 997 | CFX_ByteString csAP = |
| 998 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 999 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1000 | crLeftTop, crRightBottom, nBorderStyle, |
| 1001 | dsBorder) + |
| 1002 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1003 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1004 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 1005 | |
| 1006 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 1007 | if (pNormalIcon) |
| 1008 | AddImageToAppearance("N", pNormalIcon); |
| 1009 | |
| 1010 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 1011 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 1012 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1013 | csRolloverCaption = csNormalCaption; |
| 1014 | pRolloverIcon = pNormalIcon; |
| 1015 | } |
| 1016 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1017 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | |
| 1019 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1020 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1021 | crLeftTop, crRightBottom, |
| 1022 | nBorderStyle, dsBorder) + |
| 1023 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1024 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1025 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1026 | nLayout); |
| 1027 | |
| 1028 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1029 | if (pRolloverIcon) |
| 1030 | AddImageToAppearance("R", pRolloverIcon); |
| 1031 | |
| 1032 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1033 | csDownCaption = csNormalCaption; |
| 1034 | pDownIcon = pNormalIcon; |
| 1035 | } |
| 1036 | |
| 1037 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1038 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1039 | CPWL_Color crTemp = crLeftTop; |
| 1040 | crLeftTop = crRightBottom; |
| 1041 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | } |
| 1044 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1045 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1046 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1047 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1048 | } |
| 1049 | default: |
| 1050 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1051 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1052 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1053 | font_map.SetAPType("D"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1054 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1055 | csAP = CPWL_Utils::GetRectFillAppStream( |
| 1056 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1057 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1058 | crLeftTop, crRightBottom, |
| 1059 | nBorderStyle, dsBorder) + |
| 1060 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1061 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1062 | pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1063 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1064 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1065 | if (pDownIcon) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | AddImageToAppearance("D", pDownIcon); |
| 1067 | } else { |
| 1068 | RemoveAppearance("D"); |
| 1069 | RemoveAppearance("R"); |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | void CPDFSDK_Widget::ResetAppearance_CheckBox() { |
| 1074 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1075 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1076 | int iColorType; |
| 1077 | FX_FLOAT fc[4]; |
| 1078 | |
| 1079 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1080 | if (iColorType > 0) |
| 1081 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1082 | |
| 1083 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1084 | if (iColorType > 0) |
| 1085 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1086 | |
| 1087 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1088 | CPWL_Dash dsBorder(3, 0, 0); |
| 1089 | CPWL_Color crLeftTop, crRightBottom; |
| 1090 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1091 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1092 | switch (nBorderStyle) { |
| 1093 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1094 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1095 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1096 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1097 | fBorderWidth *= 2; |
| 1098 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1099 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1100 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1101 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1102 | fBorderWidth *= 2; |
| 1103 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1104 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1105 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1106 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1110 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1111 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1112 | |
| 1113 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1114 | if (da.HasColor()) { |
| 1115 | da.GetColor(iColorType, fc); |
| 1116 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1117 | } |
| 1118 | |
| 1119 | int32_t nStyle = 0; |
| 1120 | |
| 1121 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1122 | if (csWCaption.GetLength() > 0) { |
| 1123 | switch (csWCaption[0]) { |
| 1124 | case L'l': |
| 1125 | nStyle = PCS_CIRCLE; |
| 1126 | break; |
| 1127 | case L'8': |
| 1128 | nStyle = PCS_CROSS; |
| 1129 | break; |
| 1130 | case L'u': |
| 1131 | nStyle = PCS_DIAMOND; |
| 1132 | break; |
| 1133 | case L'n': |
| 1134 | nStyle = PCS_SQUARE; |
| 1135 | break; |
| 1136 | case L'H': |
| 1137 | nStyle = PCS_STAR; |
| 1138 | break; |
| 1139 | default: // L'4' |
| 1140 | nStyle = PCS_CHECK; |
| 1141 | break; |
| 1142 | } |
| 1143 | } else { |
| 1144 | nStyle = PCS_CHECK; |
| 1145 | } |
| 1146 | |
| 1147 | CFX_ByteString csAP_N_ON = |
| 1148 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1149 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1150 | crLeftTop, crRightBottom, nBorderStyle, |
| 1151 | dsBorder); |
| 1152 | |
| 1153 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1154 | |
| 1155 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1156 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1157 | CPWL_Color crTemp = crLeftTop; |
| 1158 | crLeftTop = crRightBottom; |
| 1159 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1160 | break; |
| 1161 | } |
| 1162 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1163 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1164 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1165 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1166 | } |
| 1167 | default: |
| 1168 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | CFX_ByteString csAP_D_ON = |
| 1172 | CPWL_Utils::GetRectFillAppStream( |
| 1173 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1174 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1175 | crLeftTop, crRightBottom, nBorderStyle, |
| 1176 | dsBorder); |
| 1177 | |
| 1178 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1179 | |
| 1180 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1181 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1182 | |
| 1183 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1184 | pControl->GetCheckedAPState()); |
| 1185 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1186 | |
| 1187 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1188 | pControl->GetCheckedAPState()); |
| 1189 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1190 | |
| 1191 | CFX_ByteString csAS = GetAppState(); |
| 1192 | if (csAS.IsEmpty()) |
| 1193 | SetAppState("Off"); |
| 1194 | } |
| 1195 | |
| 1196 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1197 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1198 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1199 | int iColorType; |
| 1200 | FX_FLOAT fc[4]; |
| 1201 | |
| 1202 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1203 | if (iColorType > 0) |
| 1204 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1205 | |
| 1206 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1207 | if (iColorType > 0) |
| 1208 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1209 | |
| 1210 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1211 | CPWL_Dash dsBorder(3, 0, 0); |
| 1212 | CPWL_Color crLeftTop, crRightBottom; |
| 1213 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1214 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1215 | switch (nBorderStyle) { |
| 1216 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1217 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1218 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1219 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1220 | fBorderWidth *= 2; |
| 1221 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1222 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1223 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1224 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1225 | fBorderWidth *= 2; |
| 1226 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1227 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1228 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1229 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1230 | break; |
| 1231 | } |
| 1232 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1233 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1234 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1235 | |
| 1236 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1237 | if (da.HasColor()) { |
| 1238 | da.GetColor(iColorType, fc); |
| 1239 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1240 | } |
| 1241 | |
| 1242 | int32_t nStyle = 0; |
| 1243 | |
| 1244 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1245 | if (csWCaption.GetLength() > 0) { |
| 1246 | switch (csWCaption[0]) { |
| 1247 | default: // L'l': |
| 1248 | nStyle = PCS_CIRCLE; |
| 1249 | break; |
| 1250 | case L'8': |
| 1251 | nStyle = PCS_CROSS; |
| 1252 | break; |
| 1253 | case L'u': |
| 1254 | nStyle = PCS_DIAMOND; |
| 1255 | break; |
| 1256 | case L'n': |
| 1257 | nStyle = PCS_SQUARE; |
| 1258 | break; |
| 1259 | case L'H': |
| 1260 | nStyle = PCS_STAR; |
| 1261 | break; |
| 1262 | case L'4': |
| 1263 | nStyle = PCS_CHECK; |
| 1264 | break; |
| 1265 | } |
| 1266 | } else { |
| 1267 | nStyle = PCS_CIRCLE; |
| 1268 | } |
| 1269 | |
| 1270 | CFX_ByteString csAP_N_ON; |
| 1271 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1272 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1273 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1274 | |
| 1275 | if (nStyle == PCS_CIRCLE) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1276 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1277 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1278 | crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1279 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1280 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1281 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1282 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1283 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1284 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1285 | CPWL_Utils::GetCircleBorderAppStream( |
| 1286 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1287 | nBorderStyle, dsBorder); |
| 1288 | } else { |
| 1289 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1290 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1291 | crLeftTop, crRightBottom, |
| 1292 | nBorderStyle, dsBorder); |
| 1293 | } |
| 1294 | |
| 1295 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1296 | |
| 1297 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1298 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1299 | CPWL_Color crTemp = crLeftTop; |
| 1300 | crLeftTop = crRightBottom; |
| 1301 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1302 | break; |
| 1303 | } |
| 1304 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1305 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1306 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1307 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1308 | } |
| 1309 | default: |
| 1310 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | CFX_ByteString csAP_D_ON; |
| 1314 | |
| 1315 | if (nStyle == PCS_CIRCLE) { |
| 1316 | CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1317 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1318 | crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1319 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1320 | crBK = crBackground; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1321 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1322 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1323 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1324 | } |
| 1325 | |
| 1326 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1327 | CPWL_Utils::GetCircleBorderAppStream( |
| 1328 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1329 | nBorderStyle, dsBorder); |
| 1330 | } else { |
| 1331 | csAP_D_ON = CPWL_Utils::GetRectFillAppStream( |
| 1332 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1333 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1334 | crLeftTop, crRightBottom, |
| 1335 | nBorderStyle, dsBorder); |
| 1336 | } |
| 1337 | |
| 1338 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1339 | |
| 1340 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1341 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1342 | |
| 1343 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1344 | pControl->GetCheckedAPState()); |
| 1345 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1346 | |
| 1347 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1348 | pControl->GetCheckedAPState()); |
| 1349 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1350 | |
| 1351 | CFX_ByteString csAS = GetAppState(); |
| 1352 | if (csAS.IsEmpty()) |
| 1353 | SetAppState("Off"); |
| 1354 | } |
| 1355 | |
| 1356 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { |
| 1357 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1358 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1359 | CFX_ByteTextBuf sBody, sLines; |
| 1360 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1361 | CFX_FloatRect rcClient = GetClientRect(); |
| 1362 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1363 | rcButton.left = rcButton.right - 13; |
| 1364 | rcButton.Normalize(); |
| 1365 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1366 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1367 | pEdit->EnableRefresh(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1368 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1369 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1370 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1371 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1372 | pEdit->SetFontMap(&font_map); |
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 | CFX_FloatRect rcEdit = rcClient; |
| 1375 | rcEdit.right = rcButton.left; |
| 1376 | rcEdit.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1377 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1378 | pEdit->SetPlateRect(rcEdit); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1379 | pEdit->SetAlignmentV(1, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1380 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1381 | FX_FLOAT fFontSize = GetFontSize(); |
| 1382 | if (IsFloatZero(fFontSize)) |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1383 | pEdit->SetAutoFontSize(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1384 | else |
| 1385 | pEdit->SetFontSize(fFontSize); |
| 1386 | |
| 1387 | pEdit->Initialize(); |
| 1388 | |
| 1389 | if (sValue) { |
| 1390 | pEdit->SetText(sValue); |
| 1391 | } else { |
| 1392 | int32_t nCurSel = pField->GetSelectedIndex(0); |
| 1393 | |
| 1394 | if (nCurSel < 0) |
| 1395 | pEdit->SetText(pField->GetValue().c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1396 | else |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1397 | pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1400 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1401 | |
| 1402 | CFX_ByteString sEdit = |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1403 | CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint(0.0f, 0.0f)); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1404 | if (sEdit.GetLength() > 0) { |
| 1405 | sBody << "/Tx BMC\n" |
| 1406 | << "q\n"; |
| 1407 | if (rcContent.Width() > rcEdit.Width() || |
| 1408 | rcContent.Height() > rcEdit.Height()) { |
| 1409 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1410 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1411 | } |
| 1412 | |
| 1413 | CPWL_Color crText = GetTextPWLColor(); |
| 1414 | sBody << "BT\n" |
| 1415 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1416 | << "Q\nEMC\n"; |
| 1417 | } |
| 1418 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1419 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1420 | |
| 1421 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1422 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1423 | |
| 1424 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1425 | } |
| 1426 | |
| 1427 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1428 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1429 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1430 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1431 | CFX_ByteTextBuf sBody, sLines; |
| 1432 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1433 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1434 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1435 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1436 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1437 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
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 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1440 | pEdit->SetFontMap(&font_map); |
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 | 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] | 1443 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1444 | FX_FLOAT fFontSize = GetFontSize(); |
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 | pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1447 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1448 | pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1449 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1450 | CFX_ByteTextBuf sList; |
| 1451 | FX_FLOAT fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1452 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1453 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1454 | int32_t nCount = pField->CountOptions(); |
| 1455 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1456 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1457 | for (int32_t i = nTop; i < nCount; ++i) { |
| 1458 | bool bSelected = false; |
| 1459 | for (int32_t j = 0; j < nSelCount; ++j) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1460 | if (pField->GetSelectedIndex(j) == i) { |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1461 | bSelected = true; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1462 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1463 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1464 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1465 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1466 | pEdit->SetText(pField->GetOptionLabel(i).c_str()); |
| 1467 | |
| 1468 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1469 | FX_FLOAT fItemHeight = rcContent.Height(); |
| 1470 | |
| 1471 | if (bSelected) { |
| 1472 | CFX_FloatRect rcItem = |
| 1473 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
| 1474 | sList << "q\n" |
| 1475 | << CPWL_Utils::GetColorAppStream( |
| 1476 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1477 | 113.0f / 255.0f), |
| 1478 | TRUE) |
| 1479 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1480 | << " " << rcItem.Height() << " re f\n" |
| 1481 | << "Q\n"; |
| 1482 | |
| 1483 | sList << "BT\n" |
| 1484 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
| 1485 | TRUE) |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1486 | << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1487 | CFX_FloatPoint(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1488 | << "ET\n"; |
| 1489 | } else { |
| 1490 | CPWL_Color crText = GetTextPWLColor(); |
| 1491 | sList << "BT\n" |
| 1492 | << CPWL_Utils::GetColorAppStream(crText, TRUE) |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1493 | << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1494 | CFX_FloatPoint(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1495 | << "ET\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1496 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1497 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1498 | fy -= fItemHeight; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1499 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1500 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1501 | if (sList.GetSize() > 0) { |
| 1502 | sBody << "/Tx BMC\n" |
| 1503 | << "q\n" |
| 1504 | << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1505 | << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1506 | sBody << sList << "Q\nEMC\n"; |
| 1507 | } |
| 1508 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1509 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1510 | sLines.AsStringC() + sBody.AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1511 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1512 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1515 | void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { |
| 1516 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1517 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1518 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1519 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1520 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1521 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1522 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1523 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1524 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1525 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1526 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1527 | pEdit->SetFontMap(&font_map); |
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 | CFX_FloatRect rcClient = GetClientRect(); |
| 1530 | pEdit->SetPlateRect(rcClient); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1531 | pEdit->SetAlignmentH(pControl->GetControlAlignment(), TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1532 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1533 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
| 1534 | FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1535 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1536 | if (bMultiLine) { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1537 | pEdit->SetMultiLine(TRUE, TRUE); |
| 1538 | pEdit->SetAutoReturn(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1539 | } else { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1540 | pEdit->SetAlignmentV(1, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1541 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1542 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1543 | uint16_t subWord = 0; |
| 1544 | if ((dwFieldFlags >> 13) & 1) { |
| 1545 | subWord = '*'; |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1546 | pEdit->SetPasswordChar(subWord, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1547 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1548 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1549 | int nMaxLen = pField->GetMaxLen(); |
| 1550 | FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; |
| 1551 | FX_FLOAT fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1552 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1553 | #ifdef PDF_ENABLE_XFA |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1554 | CFX_WideString sValueTmp; |
| 1555 | if (!sValue && GetMixXFAWidget()) { |
| 1556 | sValueTmp = GetValue(TRUE); |
| 1557 | sValue = sValueTmp.c_str(); |
| 1558 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1559 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1560 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1561 | if (nMaxLen > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1562 | if (bCharArray) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1563 | pEdit->SetCharArray(nMaxLen); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1564 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1565 | if (IsFloatZero(fFontSize)) { |
| 1566 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
| 1567 | rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1568 | } |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1569 | } else { |
| 1570 | if (sValue) |
| 1571 | nMaxLen = wcslen((const wchar_t*)sValue); |
| 1572 | pEdit->SetLimitChar(nMaxLen); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1573 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1576 | if (IsFloatZero(fFontSize)) |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1577 | pEdit->SetAutoFontSize(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1578 | else |
| 1579 | pEdit->SetFontSize(fFontSize); |
| 1580 | |
| 1581 | pEdit->Initialize(); |
| 1582 | |
| 1583 | if (sValue) |
| 1584 | pEdit->SetText(sValue); |
| 1585 | else |
| 1586 | pEdit->SetText(pField->GetValue().c_str()); |
| 1587 | |
| 1588 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1589 | |
| 1590 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1591 | pEdit.get(), CFX_FloatPoint(0.0f, 0.0f), nullptr, !bCharArray, subWord); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1592 | |
| 1593 | if (sEdit.GetLength() > 0) { |
| 1594 | sBody << "/Tx BMC\n" |
| 1595 | << "q\n"; |
| 1596 | if (rcContent.Width() > rcClient.Width() || |
| 1597 | rcContent.Height() > rcClient.Height()) { |
| 1598 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1599 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1600 | } |
| 1601 | CPWL_Color crText = GetTextPWLColor(); |
| 1602 | sBody << "BT\n" |
| 1603 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1604 | << "Q\nEMC\n"; |
| 1605 | } |
| 1606 | |
| 1607 | if (bCharArray) { |
| 1608 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1609 | case BorderStyle::SOLID: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1610 | CFX_ByteString sColor = |
| 1611 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1612 | if (sColor.GetLength() > 0) { |
| 1613 | sLines << "q\n" |
| 1614 | << GetBorderWidth() << " w\n" |
| 1615 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1616 | << " 2 J 0 j\n"; |
| 1617 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1618 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1619 | sLines << rcClient.left + |
| 1620 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1621 | << " " << rcClient.bottom << " m\n" |
| 1622 | << rcClient.left + |
| 1623 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1624 | << " " << rcClient.top << " l S\n"; |
| 1625 | } |
| 1626 | |
| 1627 | sLines << "Q\n"; |
| 1628 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1629 | break; |
| 1630 | } |
| 1631 | case BorderStyle::DASH: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1632 | CFX_ByteString sColor = |
| 1633 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1634 | if (sColor.GetLength() > 0) { |
| 1635 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1636 | |
| 1637 | sLines << "q\n" |
| 1638 | << GetBorderWidth() << " w\n" |
| 1639 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1640 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1641 | << dsBorder.nPhase << " d\n"; |
| 1642 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1643 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1644 | sLines << rcClient.left + |
| 1645 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1646 | << " " << rcClient.bottom << " m\n" |
| 1647 | << rcClient.left + |
| 1648 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1649 | << " " << rcClient.top << " l S\n"; |
| 1650 | } |
| 1651 | |
| 1652 | sLines << "Q\n"; |
| 1653 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1654 | break; |
| 1655 | } |
| 1656 | default: |
| 1657 | break; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1661 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1662 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1663 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1666 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1667 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1668 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1669 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1670 | case BorderStyle::BEVELED: |
| 1671 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1672 | fBorderWidth *= 2.0f; |
| 1673 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1674 | default: |
| 1675 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1681 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1682 | CFX_FloatRect rectAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1683 | FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; |
| 1684 | FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; |
| 1685 | |
| 1686 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1687 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1688 | switch (abs(pControl->GetRotation() % 360)) { |
| 1689 | case 0: |
| 1690 | case 180: |
| 1691 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1692 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1693 | break; |
| 1694 | case 90: |
| 1695 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1696 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1697 | break; |
| 1698 | } |
| 1699 | |
| 1700 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1703 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1704 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1705 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) { |
| 1706 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
| 1707 | } |
| 1708 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1711 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1712 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1713 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1714 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1715 | CPWL_Color crLeftTop, crRightBottom; |
| 1716 | |
| 1717 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1718 | CPWL_Dash dsBorder(3, 0, 0); |
| 1719 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1720 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1721 | switch (nBorderStyle) { |
| 1722 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1723 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1724 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1725 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1726 | fBorderWidth *= 2; |
| 1727 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1728 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1729 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1730 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1731 | fBorderWidth *= 2; |
| 1732 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1733 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1734 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1735 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1736 | break; |
| 1737 | } |
| 1738 | |
| 1739 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1740 | crLeftTop, crRightBottom, nBorderStyle, |
| 1741 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1744 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1745 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1746 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1747 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1748 | FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; |
| 1749 | FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; |
| 1750 | |
| 1751 | switch (abs(pControl->GetRotation() % 360)) { |
| 1752 | case 0: |
| 1753 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1754 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1755 | break; |
| 1756 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1757 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1758 | break; |
| 1759 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1760 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1761 | break; |
| 1762 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1763 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1764 | break; |
| 1765 | } |
| 1766 | |
| 1767 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1770 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1771 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1772 | |
| 1773 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1774 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1775 | if (da.HasColor()) { |
| 1776 | int32_t iColorType; |
| 1777 | FX_FLOAT fc[4]; |
| 1778 | da.GetColor(iColorType, fc); |
| 1779 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1780 | } |
| 1781 | |
| 1782 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1785 | CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 1786 | CPWL_Color crBorder; |
| 1787 | |
| 1788 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1789 | int32_t iColorType; |
| 1790 | FX_FLOAT fc[4]; |
| 1791 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 1792 | if (iColorType > 0) |
| 1793 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1794 | |
| 1795 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1798 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1799 | CPWL_Color crFill; |
| 1800 | |
| 1801 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1802 | int32_t iColorType; |
| 1803 | FX_FLOAT fc[4]; |
| 1804 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1805 | if (iColorType > 0) |
| 1806 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1807 | |
| 1808 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1811 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1812 | CPDF_Stream* pImage) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1813 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1814 | ASSERT(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1815 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1816 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1817 | CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1818 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1819 | CFX_ByteString sImageAlias = "IMG"; |
| 1820 | |
| 1821 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1822 | sImageAlias = pImageDict->GetStringBy("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1823 | if (sImageAlias.IsEmpty()) |
| 1824 | sImageAlias = "IMG"; |
| 1825 | } |
| 1826 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1827 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1828 | if (!pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1829 | pStreamResList = new CPDF_Dictionary(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1830 | pStreamDict->SetAt("Resources", pStreamResList); |
| 1831 | } |
| 1832 | |
| 1833 | if (pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1834 | CPDF_Dictionary* pXObject = new CPDF_Dictionary; |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1835 | pXObject->SetAtReference(sImageAlias, pDoc, pImage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1836 | pStreamResList->SetAt("XObject", pXObject); |
| 1837 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1838 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1839 | |
| 1840 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1841 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) |
| 1842 | pAPDict->RemoveAt(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1846 | PDFSDK_FieldAction& data, |
| 1847 | CPDFSDK_PageView* pPageView) { |
| 1848 | CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1849 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1850 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1851 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1852 | CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1853 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1854 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1855 | |
| 1856 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1857 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1858 | CXFA_EventParam param; |
| 1859 | param.m_eType = eEventType; |
| 1860 | param.m_wsChange = data.sChange; |
| 1861 | param.m_iCommitKey = data.nCommitKey; |
| 1862 | param.m_bShift = data.bShift; |
| 1863 | param.m_iSelStart = data.nSelStart; |
| 1864 | param.m_iSelEnd = data.nSelEnd; |
| 1865 | param.m_wsFullText = data.sValue; |
| 1866 | param.m_bKeyDown = data.bKeyDown; |
| 1867 | param.m_bModifier = data.bModifier; |
| 1868 | param.m_wsNewText = data.sValue; |
| 1869 | if (data.nSelEnd > data.nSelStart) |
| 1870 | param.m_wsNewText.Delete(data.nSelStart, |
| 1871 | data.nSelEnd - data.nSelStart); |
| 1872 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1873 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1874 | param.m_wsPrevText = data.sValue; |
| 1875 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1876 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1877 | param.m_pTarget = pAcc; |
| 1878 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1879 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1880 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1881 | pDocView->UpdateDocView(); |
| 1882 | } |
| 1883 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1884 | if (nRet == XFA_EVENTERROR_Success) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1885 | return TRUE; |
| 1886 | } |
| 1887 | } |
| 1888 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1889 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1890 | |
| 1891 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1892 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1893 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 1894 | return pActionHandler->DoAction_Field(action, type, pDocument, |
| 1895 | GetFormField(), data); |
| 1896 | } |
| 1897 | return FALSE; |
| 1898 | } |
| 1899 | |
| 1900 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1901 | switch (eAAT) { |
| 1902 | case CPDF_AAction::CursorEnter: |
| 1903 | case CPDF_AAction::CursorExit: |
| 1904 | case CPDF_AAction::ButtonDown: |
| 1905 | case CPDF_AAction::ButtonUp: |
| 1906 | case CPDF_AAction::GetFocus: |
| 1907 | case CPDF_AAction::LoseFocus: |
| 1908 | case CPDF_AAction::PageOpen: |
| 1909 | case CPDF_AAction::PageClose: |
| 1910 | case CPDF_AAction::PageVisible: |
| 1911 | case CPDF_AAction::PageInvisible: |
| 1912 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1913 | |
| 1914 | case CPDF_AAction::KeyStroke: |
| 1915 | case CPDF_AAction::Format: |
| 1916 | case CPDF_AAction::Validate: |
| 1917 | case CPDF_AAction::Calculate: { |
| 1918 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1919 | if (pField->GetAdditionalAction().GetDict()) |
| 1920 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1921 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1922 | } |
| 1923 | default: |
| 1924 | break; |
| 1925 | } |
| 1926 | |
| 1927 | return CPDF_Action(); |
| 1928 | } |
| 1929 | |
| 1930 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1931 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1932 | return pFormField->GetAlternateName(); |
| 1933 | } |
| 1934 | |
| 1935 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1936 | return m_nAppAge; |
| 1937 | } |
| 1938 | |
| 1939 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1940 | return m_nValueAge; |
| 1941 | } |
| 1942 | |
| 1943 | FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) { |
| 1944 | CPDF_Annot* pAnnot = GetPDFAnnot(); |
| 1945 | CFX_FloatRect annotRect; |
| 1946 | pAnnot->GetRect(annotRect); |
| 1947 | if (annotRect.Contains(pageX, pageY)) { |
| 1948 | if (!IsVisible()) |
| 1949 | return FALSE; |
| 1950 | |
| 1951 | int nFieldFlags = GetFieldFlags(); |
| 1952 | if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
| 1953 | return FALSE; |
| 1954 | |
| 1955 | return TRUE; |
| 1956 | } |
| 1957 | return FALSE; |
| 1958 | } |
| 1959 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1960 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1961 | CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1962 | CPDFSDK_PageView* pPageView, |
| 1963 | CPDFSDK_InterForm* pInterForm) |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 1964 | : CPDFSDK_Annot(pPageView), |
| 1965 | m_pInterForm(pInterForm), |
| 1966 | m_hXFAWidget(pAnnot) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1967 | |
| 1968 | FX_BOOL CPDFSDK_XFAWidget::IsXFAField() { |
| 1969 | return TRUE; |
| 1970 | } |
| 1971 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1972 | CXFA_FFWidget* CPDFSDK_XFAWidget::GetXFAWidget() const { |
| 1973 | return m_hXFAWidget; |
| 1974 | } |
| 1975 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1976 | CFX_ByteString CPDFSDK_XFAWidget::GetType() const { |
| 1977 | return FSDK_XFAWIDGET_TYPENAME; |
| 1978 | } |
| 1979 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 1980 | CFX_ByteString CPDFSDK_XFAWidget::GetSubType() const { |
| 1981 | return ""; |
| 1982 | } |
| 1983 | |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 1984 | CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1985 | CFX_RectF rcBBox; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1986 | GetXFAWidget()->GetRect(rcBBox); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1987 | return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 1988 | rcBBox.top + rcBBox.height); |
| 1989 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1990 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1991 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1992 | CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) |
| 1993 | : m_pDocument(pDocument), |
thestig | db1a24e | 2016-05-23 16:55:09 -0700 | [diff] [blame] | 1994 | m_pInterForm(new CPDF_InterForm(m_pDocument->GetPDFDocument())), |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1995 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1996 | m_bXfaCalculate(TRUE), |
| 1997 | m_bXfaValidationsEnabled(TRUE), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1998 | #endif // PDF_ENABLE_XFA |
| 1999 | m_bCalculate(TRUE), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2000 | m_bBusy(FALSE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2001 | m_pInterForm->SetFormNotify(this); |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2002 | for (int i = 0; i < kNumFieldTypes; ++i) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2003 | m_bNeedHightlight[i] = FALSE; |
| 2004 | m_iHighlightAlpha = 0; |
| 2005 | } |
| 2006 | |
| 2007 | CPDFSDK_InterForm::~CPDFSDK_InterForm() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2008 | m_Map.clear(); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2009 | #ifdef PDF_ENABLE_XFA |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2010 | m_XFAMap.clear(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2011 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | FX_BOOL CPDFSDK_InterForm::HighlightWidgets() { |
| 2015 | return FALSE; |
| 2016 | } |
| 2017 | |
| 2018 | CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, |
| 2019 | FX_BOOL bNext) const { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2020 | std::unique_ptr<CBA_AnnotIterator> pIterator( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2021 | new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); |
| 2022 | |
| 2023 | if (bNext) { |
| 2024 | return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget); |
| 2025 | } |
| 2026 | return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget); |
| 2027 | } |
| 2028 | |
| 2029 | CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { |
| 2030 | if (!pControl || !m_pInterForm) |
| 2031 | return nullptr; |
| 2032 | |
| 2033 | CPDFSDK_Widget* pWidget = nullptr; |
| 2034 | const auto it = m_Map.find(pControl); |
| 2035 | if (it != m_Map.end()) |
| 2036 | pWidget = it->second; |
| 2037 | |
| 2038 | if (pWidget) |
| 2039 | return pWidget; |
| 2040 | |
| 2041 | CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 2042 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2043 | CPDFSDK_PageView* pPage = nullptr; |
| 2044 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2045 | if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2046 | int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
| 2047 | if (nPageIndex >= 0) { |
| 2048 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | if (!pPage) { |
| 2053 | int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
| 2054 | if (nPageIndex >= 0) { |
| 2055 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | if (!pPage) |
| 2060 | return nullptr; |
| 2061 | return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); |
| 2062 | } |
| 2063 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2064 | void CPDFSDK_InterForm::GetWidgets( |
| 2065 | const CFX_WideString& sFieldName, |
| 2066 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2067 | for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2068 | CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2069 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2070 | GetWidgets(pFormField, widgets); |
| 2071 | } |
| 2072 | } |
| 2073 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2074 | void CPDFSDK_InterForm::GetWidgets( |
| 2075 | CPDF_FormField* pField, |
| 2076 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2077 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2078 | CPDF_FormControl* pFormCtrl = pField->GetControl(i); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2079 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2080 | CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2081 | if (pWidget) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2082 | widgets->push_back(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
| 2087 | CPDF_Document* pDocument, |
| 2088 | CPDF_Dictionary* pAnnotDict) const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2089 | ASSERT(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2090 | |
| 2091 | for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { |
| 2092 | if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2093 | if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2094 | for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 2095 | CPDF_Object* pDict = pAnnots->GetDirectObjectAt(j); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2096 | if (pAnnotDict == pDict) { |
| 2097 | return i; |
| 2098 | } |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | return -1; |
| 2105 | } |
| 2106 | |
| 2107 | void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, |
| 2108 | CPDFSDK_Widget* pWidget) { |
| 2109 | m_Map[pControl] = pWidget; |
| 2110 | } |
| 2111 | |
| 2112 | void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) { |
| 2113 | m_Map.erase(pControl); |
| 2114 | } |
| 2115 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2116 | void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) { |
| 2117 | m_bCalculate = bEnabled; |
| 2118 | } |
| 2119 | |
| 2120 | FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { |
| 2121 | return m_bCalculate; |
| 2122 | } |
| 2123 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2124 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2125 | void CPDFSDK_InterForm::AddXFAMap(CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2126 | CPDFSDK_XFAWidget* pWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2127 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2128 | m_XFAMap[hWidget] = pWidget; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2131 | void CPDFSDK_InterForm::RemoveXFAMap(CXFA_FFWidget* hWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2132 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2133 | m_XFAMap.erase(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2136 | CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(CXFA_FFWidget* hWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2137 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2138 | auto it = m_XFAMap.find(hWidget); |
| 2139 | return it != m_XFAMap.end() ? it->second : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2140 | } |
| 2141 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2142 | void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) { |
| 2143 | m_bXfaCalculate = bEnabled; |
| 2144 | } |
| 2145 | FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const { |
| 2146 | return m_bXfaCalculate; |
| 2147 | } |
| 2148 | |
| 2149 | FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() { |
| 2150 | return m_bXfaValidationsEnabled; |
| 2151 | } |
| 2152 | void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) { |
| 2153 | m_bXfaValidationsEnabled = bEnabled; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2154 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2155 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2156 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2157 | void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2158 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2159 | ASSERT(pEnv); |
| 2160 | if (!pEnv->IsJSInitiated()) |
| 2161 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2162 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2163 | if (m_bBusy) |
| 2164 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2165 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2166 | m_bBusy = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2167 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2168 | if (IsCalculateEnabled()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2169 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2170 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2171 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2172 | int nSize = m_pInterForm->CountFieldsInCalculationOrder(); |
| 2173 | for (int i = 0; i < nSize; i++) { |
| 2174 | if (CPDF_FormField* pField = |
| 2175 | m_pInterForm->GetFieldInCalculationOrder(i)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2176 | int nType = pField->GetFieldType(); |
| 2177 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2178 | CPDF_AAction aAction = pField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2179 | if (aAction.GetDict() && |
| 2180 | aAction.ActionExist(CPDF_AAction::Calculate)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2181 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2182 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2183 | CFX_WideString csJS = action.GetJavaScript(); |
| 2184 | if (!csJS.IsEmpty()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2185 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2186 | CFX_WideString sOldValue = pField->GetValue(); |
| 2187 | CFX_WideString sValue = sOldValue; |
| 2188 | FX_BOOL bRC = TRUE; |
| 2189 | pContext->OnField_Calculate(pFormField, pField, sValue, bRC); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2190 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2191 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2192 | FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2193 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2194 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2195 | if (bRet) { |
| 2196 | if (bRC) { |
| 2197 | if (sValue.Compare(sOldValue) != 0) |
| 2198 | pField->SetValue(sValue, TRUE); |
| 2199 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2200 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2201 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2202 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2203 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2204 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2205 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2206 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2207 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2208 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2209 | m_bBusy = FALSE; |
| 2210 | } |
| 2211 | |
| 2212 | CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, |
| 2213 | FX_BOOL& bFormated) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2214 | CFX_WideString sValue = pFormField->GetValue(); |
| 2215 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2216 | ASSERT(pEnv); |
| 2217 | if (!pEnv->IsJSInitiated()) { |
| 2218 | bFormated = FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2219 | return sValue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2220 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2221 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2222 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2223 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2224 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2225 | if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) { |
| 2226 | if (pFormField->CountSelectedItems() > 0) { |
| 2227 | int index = pFormField->GetSelectedIndex(0); |
| 2228 | if (index >= 0) |
| 2229 | sValue = pFormField->GetOptionLabel(index); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2230 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2231 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2232 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2233 | bFormated = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2234 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2235 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2236 | if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2237 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2238 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2239 | CFX_WideString script = action.GetJavaScript(); |
| 2240 | if (!script.IsEmpty()) { |
| 2241 | CFX_WideString Value = sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2242 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2243 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2244 | pContext->OnField_Format(pFormField, Value, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2246 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2247 | FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2248 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2249 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2250 | if (bRet) { |
| 2251 | sValue = Value; |
| 2252 | bFormated = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2253 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2254 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2255 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | return sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2261 | void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, |
| 2262 | const FX_WCHAR* sValue, |
| 2263 | FX_BOOL bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2264 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2265 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2266 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2267 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) |
| 2268 | pWidget->ResetAppearance(sValue, bValueChanged); |
| 2269 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2272 | void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2273 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2274 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2275 | ASSERT(pFormCtrl); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2277 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2278 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2279 | CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 2280 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2281 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2282 | FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2283 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2284 | pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 2285 | rcBBox.bottom); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2286 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2287 | } |
| 2288 | } |
| 2289 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2290 | FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| 2291 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2292 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2293 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2294 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2295 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2296 | CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2297 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2298 | return TRUE; |
| 2299 | |
| 2300 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2301 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2302 | PDFSDK_FieldAction fa; |
| 2303 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2304 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2305 | fa.sValue = csValue; |
| 2306 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
| 2307 | m_pDocument, pFormField, fa); |
| 2308 | return fa.bRC; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2311 | FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
| 2312 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2313 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2314 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2315 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2316 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2317 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2318 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2319 | return TRUE; |
| 2320 | |
| 2321 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2322 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2323 | PDFSDK_FieldAction fa; |
| 2324 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2325 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2326 | fa.sValue = csValue; |
| 2327 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
| 2328 | m_pDocument, pFormField, fa); |
| 2329 | return fa.bRC; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2332 | FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2333 | ASSERT(action.GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2334 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2335 | CPDF_ActionFields af(&action); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2336 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2337 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2338 | |
thestig | ded3634 | 2016-05-23 17:54:02 -0700 | [diff] [blame] | 2339 | bool bHide = action.GetHideStatus(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2340 | FX_BOOL bChanged = FALSE; |
| 2341 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2342 | for (CPDF_FormField* pField : fields) { |
| 2343 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| 2344 | CPDF_FormControl* pControl = pField->GetControl(i); |
| 2345 | ASSERT(pControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2346 | |
| 2347 | if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2348 | uint32_t nFlags = pWidget->GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2349 | nFlags &= ~ANNOTFLAG_INVISIBLE; |
| 2350 | nFlags &= ~ANNOTFLAG_NOVIEW; |
| 2351 | if (bHide) |
| 2352 | nFlags |= ANNOTFLAG_HIDDEN; |
| 2353 | else |
| 2354 | nFlags &= ~ANNOTFLAG_HIDDEN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2355 | pWidget->SetFlags(nFlags); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2356 | pWidget->GetPageView()->UpdateView(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2357 | bChanged = TRUE; |
| 2358 | } |
| 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | return bChanged; |
| 2363 | } |
| 2364 | |
| 2365 | FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2366 | CFX_WideString sDestination = action.GetFilePath(); |
| 2367 | if (sDestination.IsEmpty()) |
| 2368 | return FALSE; |
| 2369 | |
| 2370 | CPDF_Dictionary* pActionDict = action.GetDict(); |
| 2371 | if (pActionDict->KeyExist("Fields")) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2372 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2373 | uint32_t dwFlags = action.GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2374 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2375 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2376 | if (!fields.empty()) { |
| 2377 | bool bIncludeOrExclude = !(dwFlags & 0x01); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2378 | if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2379 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2380 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2381 | return SubmitFields(sDestination, fields, bIncludeOrExclude, false); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2382 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2383 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2384 | if (m_pInterForm->CheckRequiredFields(nullptr, true)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2385 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2386 | |
| 2387 | return SubmitForm(sDestination, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2390 | FX_BOOL CPDFSDK_InterForm::SubmitFields( |
| 2391 | const CFX_WideString& csDestination, |
| 2392 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2393 | bool bIncludeOrExclude, |
| 2394 | bool bUrlEncoded) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2395 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2396 | |
| 2397 | CFX_ByteTextBuf textBuf; |
| 2398 | ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); |
| 2399 | |
| 2400 | uint8_t* pBuffer = textBuf.GetBuffer(); |
| 2401 | FX_STRSIZE nBufSize = textBuf.GetLength(); |
| 2402 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2403 | if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2404 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2405 | |
| 2406 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2407 | return TRUE; |
| 2408 | } |
| 2409 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2410 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
| 2411 | CFX_WideString csTxtFile) { |
| 2412 | return TRUE; |
| 2413 | } |
| 2414 | |
| 2415 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
| 2416 | FX_STRSIZE& nBufSize) { |
| 2417 | CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
| 2418 | if (pFDF) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2419 | CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2420 | if (!pMainDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2421 | return FALSE; |
| 2422 | |
| 2423 | // Get fields |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2424 | CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2425 | if (!pFields) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2426 | return FALSE; |
| 2427 | |
| 2428 | CFX_ByteTextBuf fdfEncodedData; |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2429 | for (uint32_t i = 0; i < pFields->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2430 | CPDF_Dictionary* pField = pFields->GetDictAt(i); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2431 | if (!pField) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2432 | continue; |
| 2433 | CFX_WideString name; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2434 | name = pField->GetUnicodeTextBy("T"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2435 | CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2436 | CFX_ByteString csBValue = pField->GetStringBy("V"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2437 | CFX_WideString csWValue = PDF_DecodeText(csBValue); |
| 2438 | CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
| 2439 | |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2440 | fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2441 | name_b.ReleaseBuffer(); |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2442 | fdfEncodedData << "="; |
| 2443 | fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2444 | csValue_b.ReleaseBuffer(); |
| 2445 | if (i != pFields->GetCount() - 1) |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2446 | fdfEncodedData << "&"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | nBufSize = fdfEncodedData.GetLength(); |
| 2450 | pBuf = FX_Alloc(uint8_t, nBufSize); |
| 2451 | FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
| 2452 | } |
| 2453 | return TRUE; |
| 2454 | } |
| 2455 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2456 | FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| 2457 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2458 | bool bIncludeOrExclude, |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2459 | CFX_ByteTextBuf& textBuf) { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2460 | std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2461 | m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2462 | return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2465 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2466 | void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, |
| 2467 | FX_BOOL bSynchronizeElse) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2468 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2469 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2470 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2471 | pWidget->Synchronize(bSynchronizeElse); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2472 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2473 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2474 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2475 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2477 | CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 2478 | const CFX_WideString& sFileExt) { |
| 2479 | CFX_WideString sFileName; |
| 2480 | return L""; |
| 2481 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2482 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2483 | FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
| 2484 | FX_BOOL bUrlEncoded) { |
| 2485 | if (sDestination.IsEmpty()) |
| 2486 | return FALSE; |
| 2487 | |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2488 | if (!m_pDocument || !m_pInterForm) |
| 2489 | return FALSE; |
| 2490 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2491 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2492 | CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2493 | CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC()); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2494 | if (!pFDFDoc) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2495 | return FALSE; |
| 2496 | |
| 2497 | CFX_ByteTextBuf FdfBuffer; |
| 2498 | FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
| 2499 | delete pFDFDoc; |
| 2500 | if (!bRet) |
| 2501 | return FALSE; |
| 2502 | |
| 2503 | uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
| 2504 | FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
| 2505 | |
| 2506 | if (bUrlEncoded) { |
| 2507 | if (!FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2508 | return FALSE; |
| 2509 | } |
| 2510 | |
| 2511 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
| 2512 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2513 | if (bUrlEncoded) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2514 | FX_Free(pBuffer); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2515 | |
| 2516 | return TRUE; |
| 2517 | } |
| 2518 | |
| 2519 | FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 2520 | CFDF_Document* pFDF = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2521 | m_pInterForm->ExportToFDF(m_pDocument->GetPath().AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2522 | if (!pFDF) |
| 2523 | return FALSE; |
| 2524 | |
| 2525 | FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
| 2526 | delete pFDF; |
| 2527 | |
| 2528 | return bRet; |
| 2529 | } |
| 2530 | |
| 2531 | FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2532 | ASSERT(action.GetDict()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2533 | |
| 2534 | CPDF_Dictionary* pActionDict = action.GetDict(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2535 | if (!pActionDict->KeyExist("Fields")) |
| 2536 | return m_pInterForm->ResetForm(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2537 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2538 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2539 | uint32_t dwFlags = action.GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2540 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2541 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2542 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2543 | return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { |
| 2547 | return FALSE; |
| 2548 | } |
| 2549 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2550 | std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( |
| 2551 | const std::vector<CPDF_Object*>& objects) const { |
| 2552 | std::vector<CPDF_FormField*> fields; |
| 2553 | for (CPDF_Object* pObject : objects) { |
| 2554 | if (pObject && pObject->IsString()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2555 | CFX_WideString csName = pObject->GetUnicodeText(); |
| 2556 | CPDF_FormField* pField = m_pInterForm->GetField(0, csName); |
Dan Sinclair | d43ebdd | 2015-10-27 15:37:54 -0400 | [diff] [blame] | 2557 | if (pField) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2558 | fields.push_back(pField); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2559 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2560 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2561 | return fields; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2564 | int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField, |
| 2565 | const CFX_WideString& csValue) { |
| 2566 | int nType = pField->GetFieldType(); |
| 2567 | if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2568 | return 0; |
| 2569 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2570 | if (!OnKeyStrokeCommit(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2571 | return -1; |
| 2572 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2573 | if (!OnValidate(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2574 | return -1; |
| 2575 | |
| 2576 | return 1; |
| 2577 | } |
| 2578 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2579 | void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { |
| 2580 | #ifdef PDF_ENABLE_XFA |
| 2581 | SynchronizeField(pField, FALSE); |
| 2582 | #endif // PDF_ENABLE_XFA |
| 2583 | int nType = pField->GetFieldType(); |
| 2584 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2585 | OnCalculate(pField); |
| 2586 | FX_BOOL bFormated = FALSE; |
| 2587 | CFX_WideString sValue = OnFormat(pField, bFormated); |
| 2588 | ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); |
| 2589 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2590 | } |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, |
| 2594 | const CFX_WideString& csValue) { |
| 2595 | if (pField->GetFieldType() != FIELDTYPE_LISTBOX) |
| 2596 | return 0; |
| 2597 | |
| 2598 | if (!OnKeyStrokeCommit(pField, csValue)) |
| 2599 | return -1; |
| 2600 | |
| 2601 | if (!OnValidate(pField, csValue)) |
| 2602 | return -1; |
| 2603 | |
| 2604 | return 1; |
| 2605 | } |
| 2606 | |
| 2607 | void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) { |
| 2608 | if (pField->GetFieldType() == FIELDTYPE_LISTBOX) { |
| 2609 | OnCalculate(pField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2610 | ResetFieldAppearance(pField, nullptr, TRUE); |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2611 | UpdateField(pField); |
| 2612 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2615 | void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { |
| 2616 | int nType = pField->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2617 | if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) { |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2618 | OnCalculate(pField); |
| 2619 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2620 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2623 | int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2624 | return 0; |
| 2625 | } |
| 2626 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2627 | void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2628 | OnCalculate(nullptr); |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2632 | return 0; |
| 2633 | } |
| 2634 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2635 | void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2636 | OnCalculate(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
| 2639 | FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2640 | if (nFieldType < 1 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2641 | return FALSE; |
| 2642 | return m_bNeedHightlight[nFieldType - 1]; |
| 2643 | } |
| 2644 | |
| 2645 | void CPDFSDK_InterForm::RemoveAllHighLight() { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2646 | for (int i = 0; i < kNumFieldTypes; ++i) |
| 2647 | m_bNeedHightlight[i] = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2648 | } |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2649 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2650 | void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2651 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2652 | return; |
| 2653 | switch (nFieldType) { |
| 2654 | case 0: { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2655 | for (int i = 0; i < kNumFieldTypes; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2656 | m_aHighlightColor[i] = clr; |
| 2657 | m_bNeedHightlight[i] = TRUE; |
| 2658 | } |
| 2659 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2660 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2661 | default: { |
| 2662 | m_aHighlightColor[nFieldType - 1] = clr; |
| 2663 | m_bNeedHightlight[nFieldType - 1] = TRUE; |
| 2664 | break; |
| 2665 | } |
| 2666 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2667 | } |
| 2668 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2669 | FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2670 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2671 | return FXSYS_RGB(255, 255, 255); |
| 2672 | if (nFieldType == 0) |
| 2673 | return m_aHighlightColor[0]; |
| 2674 | return m_aHighlightColor[nFieldType - 1]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2677 | CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, |
| 2678 | const CFX_ByteString& sType, |
| 2679 | const CFX_ByteString& sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2680 | : m_eTabOrder(STRUCTURE), |
| 2681 | m_pPageView(pPageView), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2682 | m_sType(sType), |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2683 | m_sSubType(sSubType) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2684 | CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2685 | CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2686 | if (sTabs == "R") |
| 2687 | m_eTabOrder = ROW; |
| 2688 | else if (sTabs == "C") |
| 2689 | m_eTabOrder = COLUMN; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2690 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2691 | GenerateResults(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 2694 | CBA_AnnotIterator::~CBA_AnnotIterator() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2695 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2696 | CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2697 | return m_Annots.empty() ? nullptr : m_Annots.front(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2700 | CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2701 | return m_Annots.empty() ? nullptr : m_Annots.back(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2704 | CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2705 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2706 | if (iter == m_Annots.end()) |
| 2707 | return nullptr; |
| 2708 | ++iter; |
| 2709 | if (iter == m_Annots.end()) |
| 2710 | iter = m_Annots.begin(); |
| 2711 | return *iter; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2714 | CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2715 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2716 | if (iter == m_Annots.end()) |
| 2717 | return nullptr; |
| 2718 | if (iter == m_Annots.begin()) |
| 2719 | iter = m_Annots.end(); |
| 2720 | return *(--iter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2723 | // static |
| 2724 | bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1, |
| 2725 | const CPDFSDK_Annot* p2) { |
| 2726 | return GetAnnotRect(p1).left < GetAnnotRect(p2).left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2729 | // static |
| 2730 | bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1, |
| 2731 | const CPDFSDK_Annot* p2) { |
| 2732 | return GetAnnotRect(p1).top > GetAnnotRect(p2).top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2735 | void CBA_AnnotIterator::GenerateResults() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2736 | switch (m_eTabOrder) { |
| 2737 | case STRUCTURE: { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 2738 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2739 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2740 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2741 | m_Annots.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2742 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2743 | } break; |
| 2744 | case ROW: { |
| 2745 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2746 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2747 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2748 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2749 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2752 | std::sort(sa.begin(), sa.end(), CompareByLeftAscending); |
| 2753 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2754 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2755 | FX_FLOAT fTop = 0.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2756 | for (int i = sa.size() - 1; i >= 0; i--) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2757 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2758 | if (rcAnnot.top > fTop) { |
| 2759 | nLeftTopIndex = i; |
| 2760 | fTop = rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2761 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2762 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2763 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2764 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2765 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2766 | m_Annots.push_back(pLeftTopAnnot); |
| 2767 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2768 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2769 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2770 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2771 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2772 | FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; |
| 2773 | if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2774 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2775 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2776 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2777 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2778 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2779 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2780 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2781 | } |
| 2782 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2783 | } break; |
| 2784 | case COLUMN: { |
| 2785 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2786 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2787 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2788 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2789 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2792 | std::sort(sa.begin(), sa.end(), CompareByTopDescending); |
| 2793 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2794 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2795 | FX_FLOAT fLeft = -1.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2796 | for (int i = sa.size() - 1; i >= 0; --i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2797 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2798 | if (fLeft < 0) { |
| 2799 | nLeftTopIndex = 0; |
| 2800 | fLeft = rcAnnot.left; |
| 2801 | } else if (rcAnnot.left < fLeft) { |
| 2802 | nLeftTopIndex = i; |
| 2803 | fLeft = rcAnnot.left; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2804 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2805 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2806 | |
| 2807 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2808 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2809 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2810 | m_Annots.push_back(pLeftTopAnnot); |
| 2811 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2812 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2813 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2814 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2815 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2816 | FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; |
| 2817 | if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2818 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2819 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2820 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2821 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2822 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2823 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2824 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2825 | } |
| 2826 | } |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2827 | break; |
| 2828 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2829 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2832 | CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2833 | CFX_FloatRect rcAnnot; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2834 | pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2835 | return rcAnnot; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2836 | } |