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