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