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(); |
| 883 | int32_t nBorderStyle = 0; |
| 884 | CPWL_Dash dsBorder(3, 0, 0); |
| 885 | CPWL_Color crLeftTop, crRightBottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 886 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 887 | switch (GetBorderStyle()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 888 | case BBS_DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 889 | nBorderStyle = PBS_DASH; |
| 890 | dsBorder = CPWL_Dash(3, 3, 0); |
| 891 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 892 | case BBS_BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | nBorderStyle = PBS_BEVELED; |
| 894 | fBorderWidth *= 2; |
| 895 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 896 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 897 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 898 | case BBS_INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | nBorderStyle = PBS_INSET; |
| 900 | fBorderWidth *= 2; |
| 901 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 902 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 903 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 904 | case BBS_UNDERLINE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 905 | nBorderStyle = PBS_UNDERLINED; |
| 906 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 907 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | nBorderStyle = PBS_SOLID; |
| 909 | break; |
| 910 | } |
| 911 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 912 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 913 | |
| 914 | CPWL_Color crText(COLORTYPE_GRAY, 0); |
| 915 | |
| 916 | FX_FLOAT fFontSize = 12.0f; |
| 917 | CFX_ByteString csNameTag; |
| 918 | |
| 919 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 920 | if (da.HasColor()) { |
| 921 | da.GetColor(iColorType, fc); |
| 922 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 923 | } |
| 924 | |
| 925 | if (da.HasFont()) |
| 926 | da.GetFont(csNameTag, fFontSize); |
| 927 | |
| 928 | CFX_WideString csWCaption; |
| 929 | CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption; |
| 930 | |
| 931 | if (pControl->HasMKEntry("CA")) { |
| 932 | csNormalCaption = pControl->GetNormalCaption(); |
| 933 | } |
| 934 | if (pControl->HasMKEntry("RC")) { |
| 935 | csRolloverCaption = pControl->GetRolloverCaption(); |
| 936 | } |
| 937 | if (pControl->HasMKEntry("AC")) { |
| 938 | csDownCaption = pControl->GetDownCaption(); |
| 939 | } |
| 940 | |
| 941 | CPDF_Stream* pNormalIcon = NULL; |
| 942 | CPDF_Stream* pRolloverIcon = NULL; |
| 943 | CPDF_Stream* pDownIcon = NULL; |
| 944 | |
| 945 | if (pControl->HasMKEntry("I")) { |
| 946 | pNormalIcon = pControl->GetNormalIcon(); |
| 947 | } |
| 948 | if (pControl->HasMKEntry("RI")) { |
| 949 | pRolloverIcon = pControl->GetRolloverIcon(); |
| 950 | } |
| 951 | if (pControl->HasMKEntry("IX")) { |
| 952 | pDownIcon = pControl->GetDownIcon(); |
| 953 | } |
| 954 | |
| 955 | if (pNormalIcon) { |
| 956 | if (CPDF_Dictionary* pImageDict = pNormalIcon->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", "ImgA"); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | if (pRolloverIcon) { |
| 963 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->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", "ImgB"); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | if (pDownIcon) { |
| 970 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 971 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 972 | pImageDict->SetAtString("Name", "ImgC"); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 977 | |
| 978 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 979 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 980 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 981 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 982 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 983 | |
| 984 | CFX_ByteString csAP = |
| 985 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 986 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 987 | crLeftTop, crRightBottom, nBorderStyle, |
| 988 | dsBorder) + |
| 989 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 990 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 991 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 992 | |
| 993 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 994 | if (pNormalIcon) |
| 995 | AddImageToAppearance("N", pNormalIcon); |
| 996 | |
| 997 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 998 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 999 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1000 | csRolloverCaption = csNormalCaption; |
| 1001 | pRolloverIcon = pNormalIcon; |
| 1002 | } |
| 1003 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1004 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1005 | |
| 1006 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1007 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1008 | crLeftTop, crRightBottom, |
| 1009 | nBorderStyle, dsBorder) + |
| 1010 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1011 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1013 | nLayout); |
| 1014 | |
| 1015 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1016 | if (pRolloverIcon) |
| 1017 | AddImageToAppearance("R", pRolloverIcon); |
| 1018 | |
| 1019 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1020 | csDownCaption = csNormalCaption; |
| 1021 | pDownIcon = pNormalIcon; |
| 1022 | } |
| 1023 | |
| 1024 | switch (nBorderStyle) { |
| 1025 | case PBS_BEVELED: { |
| 1026 | CPWL_Color crTemp = crLeftTop; |
| 1027 | crLeftTop = crRightBottom; |
| 1028 | crRightBottom = crTemp; |
| 1029 | } break; |
| 1030 | case PBS_INSET: |
| 1031 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1032 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1033 | break; |
| 1034 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1035 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1036 | font_map.SetAPType("D"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1037 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1038 | csAP = CPWL_Utils::GetRectFillAppStream( |
| 1039 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1040 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1041 | crLeftTop, crRightBottom, |
| 1042 | nBorderStyle, dsBorder) + |
| 1043 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1044 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1045 | pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1046 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1047 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1048 | if (pDownIcon) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1049 | AddImageToAppearance("D", pDownIcon); |
| 1050 | } else { |
| 1051 | RemoveAppearance("D"); |
| 1052 | RemoveAppearance("R"); |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | void CPDFSDK_Widget::ResetAppearance_CheckBox() { |
| 1057 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1058 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | int iColorType; |
| 1060 | FX_FLOAT fc[4]; |
| 1061 | |
| 1062 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1063 | if (iColorType > 0) |
| 1064 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1065 | |
| 1066 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1067 | if (iColorType > 0) |
| 1068 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1069 | |
| 1070 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1071 | int32_t nBorderStyle = 0; |
| 1072 | CPWL_Dash dsBorder(3, 0, 0); |
| 1073 | CPWL_Color crLeftTop, crRightBottom; |
| 1074 | |
| 1075 | switch (GetBorderStyle()) { |
| 1076 | case BBS_DASH: |
| 1077 | nBorderStyle = PBS_DASH; |
| 1078 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1079 | break; |
| 1080 | case BBS_BEVELED: |
| 1081 | nBorderStyle = PBS_BEVELED; |
| 1082 | fBorderWidth *= 2; |
| 1083 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1084 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1085 | break; |
| 1086 | case BBS_INSET: |
| 1087 | nBorderStyle = PBS_INSET; |
| 1088 | fBorderWidth *= 2; |
| 1089 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1090 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1091 | break; |
| 1092 | case BBS_UNDERLINE: |
| 1093 | nBorderStyle = PBS_UNDERLINED; |
| 1094 | break; |
| 1095 | default: |
| 1096 | nBorderStyle = PBS_SOLID; |
| 1097 | break; |
| 1098 | } |
| 1099 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1100 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1101 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1102 | |
| 1103 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1104 | if (da.HasColor()) { |
| 1105 | da.GetColor(iColorType, fc); |
| 1106 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1107 | } |
| 1108 | |
| 1109 | int32_t nStyle = 0; |
| 1110 | |
| 1111 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1112 | if (csWCaption.GetLength() > 0) { |
| 1113 | switch (csWCaption[0]) { |
| 1114 | case L'l': |
| 1115 | nStyle = PCS_CIRCLE; |
| 1116 | break; |
| 1117 | case L'8': |
| 1118 | nStyle = PCS_CROSS; |
| 1119 | break; |
| 1120 | case L'u': |
| 1121 | nStyle = PCS_DIAMOND; |
| 1122 | break; |
| 1123 | case L'n': |
| 1124 | nStyle = PCS_SQUARE; |
| 1125 | break; |
| 1126 | case L'H': |
| 1127 | nStyle = PCS_STAR; |
| 1128 | break; |
| 1129 | default: // L'4' |
| 1130 | nStyle = PCS_CHECK; |
| 1131 | break; |
| 1132 | } |
| 1133 | } else { |
| 1134 | nStyle = PCS_CHECK; |
| 1135 | } |
| 1136 | |
| 1137 | CFX_ByteString csAP_N_ON = |
| 1138 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1139 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1140 | crLeftTop, crRightBottom, nBorderStyle, |
| 1141 | dsBorder); |
| 1142 | |
| 1143 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1144 | |
| 1145 | switch (nBorderStyle) { |
| 1146 | case PBS_BEVELED: { |
| 1147 | CPWL_Color crTemp = crLeftTop; |
| 1148 | crLeftTop = crRightBottom; |
| 1149 | crRightBottom = crTemp; |
| 1150 | } break; |
| 1151 | case PBS_INSET: |
| 1152 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1153 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | CFX_ByteString csAP_D_ON = |
| 1158 | CPWL_Utils::GetRectFillAppStream( |
| 1159 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1160 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1161 | crLeftTop, crRightBottom, nBorderStyle, |
| 1162 | dsBorder); |
| 1163 | |
| 1164 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1165 | |
| 1166 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1167 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1168 | |
| 1169 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1170 | pControl->GetCheckedAPState()); |
| 1171 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1172 | |
| 1173 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1174 | pControl->GetCheckedAPState()); |
| 1175 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1176 | |
| 1177 | CFX_ByteString csAS = GetAppState(); |
| 1178 | if (csAS.IsEmpty()) |
| 1179 | SetAppState("Off"); |
| 1180 | } |
| 1181 | |
| 1182 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1183 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1185 | int iColorType; |
| 1186 | FX_FLOAT fc[4]; |
| 1187 | |
| 1188 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1189 | if (iColorType > 0) |
| 1190 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1191 | |
| 1192 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1193 | if (iColorType > 0) |
| 1194 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1195 | |
| 1196 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1197 | int32_t nBorderStyle = 0; |
| 1198 | CPWL_Dash dsBorder(3, 0, 0); |
| 1199 | CPWL_Color crLeftTop, crRightBottom; |
| 1200 | |
| 1201 | switch (GetBorderStyle()) { |
| 1202 | case BBS_DASH: |
| 1203 | nBorderStyle = PBS_DASH; |
| 1204 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1205 | break; |
| 1206 | case BBS_BEVELED: |
| 1207 | nBorderStyle = PBS_BEVELED; |
| 1208 | fBorderWidth *= 2; |
| 1209 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1210 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1211 | break; |
| 1212 | case BBS_INSET: |
| 1213 | nBorderStyle = PBS_INSET; |
| 1214 | fBorderWidth *= 2; |
| 1215 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1216 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1217 | break; |
| 1218 | case BBS_UNDERLINE: |
| 1219 | nBorderStyle = PBS_UNDERLINED; |
| 1220 | break; |
| 1221 | default: |
| 1222 | nBorderStyle = PBS_SOLID; |
| 1223 | break; |
| 1224 | } |
| 1225 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1226 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1227 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1228 | |
| 1229 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1230 | if (da.HasColor()) { |
| 1231 | da.GetColor(iColorType, fc); |
| 1232 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1233 | } |
| 1234 | |
| 1235 | int32_t nStyle = 0; |
| 1236 | |
| 1237 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1238 | if (csWCaption.GetLength() > 0) { |
| 1239 | switch (csWCaption[0]) { |
| 1240 | default: // L'l': |
| 1241 | nStyle = PCS_CIRCLE; |
| 1242 | break; |
| 1243 | case L'8': |
| 1244 | nStyle = PCS_CROSS; |
| 1245 | break; |
| 1246 | case L'u': |
| 1247 | nStyle = PCS_DIAMOND; |
| 1248 | break; |
| 1249 | case L'n': |
| 1250 | nStyle = PCS_SQUARE; |
| 1251 | break; |
| 1252 | case L'H': |
| 1253 | nStyle = PCS_STAR; |
| 1254 | break; |
| 1255 | case L'4': |
| 1256 | nStyle = PCS_CHECK; |
| 1257 | break; |
| 1258 | } |
| 1259 | } else { |
| 1260 | nStyle = PCS_CIRCLE; |
| 1261 | } |
| 1262 | |
| 1263 | CFX_ByteString csAP_N_ON; |
| 1264 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1265 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1266 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1267 | |
| 1268 | if (nStyle == PCS_CIRCLE) { |
| 1269 | if (nBorderStyle == PBS_BEVELED) { |
| 1270 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1271 | crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1272 | } else if (nBorderStyle == PBS_INSET) { |
| 1273 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1274 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1275 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1277 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1278 | CPWL_Utils::GetCircleBorderAppStream( |
| 1279 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1280 | nBorderStyle, dsBorder); |
| 1281 | } else { |
| 1282 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1283 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1284 | crLeftTop, crRightBottom, |
| 1285 | nBorderStyle, dsBorder); |
| 1286 | } |
| 1287 | |
| 1288 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1289 | |
| 1290 | switch (nBorderStyle) { |
| 1291 | case PBS_BEVELED: { |
| 1292 | CPWL_Color crTemp = crLeftTop; |
| 1293 | crLeftTop = crRightBottom; |
| 1294 | crRightBottom = crTemp; |
| 1295 | } break; |
| 1296 | case PBS_INSET: |
| 1297 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1298 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1299 | break; |
| 1300 | } |
| 1301 | |
| 1302 | CFX_ByteString csAP_D_ON; |
| 1303 | |
| 1304 | if (nStyle == PCS_CIRCLE) { |
| 1305 | CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1306 | if (nBorderStyle == PBS_BEVELED) { |
| 1307 | crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1308 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1309 | crBK = crBackground; |
| 1310 | } else if (nBorderStyle == PBS_INSET) { |
| 1311 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1312 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1313 | } |
| 1314 | |
| 1315 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1316 | CPWL_Utils::GetCircleBorderAppStream( |
| 1317 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1318 | nBorderStyle, dsBorder); |
| 1319 | } else { |
| 1320 | csAP_D_ON = CPWL_Utils::GetRectFillAppStream( |
| 1321 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1322 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1323 | crLeftTop, crRightBottom, |
| 1324 | nBorderStyle, dsBorder); |
| 1325 | } |
| 1326 | |
| 1327 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1328 | |
| 1329 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1330 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1331 | |
| 1332 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1333 | pControl->GetCheckedAPState()); |
| 1334 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1335 | |
| 1336 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1337 | pControl->GetCheckedAPState()); |
| 1338 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1339 | |
| 1340 | CFX_ByteString csAS = GetAppState(); |
| 1341 | if (csAS.IsEmpty()) |
| 1342 | SetAppState("Off"); |
| 1343 | } |
| 1344 | |
| 1345 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { |
| 1346 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1347 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1348 | CFX_ByteTextBuf sBody, sLines; |
| 1349 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1350 | CFX_FloatRect rcClient = GetClientRect(); |
| 1351 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1352 | rcButton.left = rcButton.right - 13; |
| 1353 | rcButton.Normalize(); |
| 1354 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1355 | IFX_Edit* pEdit = IFX_Edit::NewEdit(); |
| 1356 | pEdit->EnableRefresh(FALSE); |
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 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1359 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1360 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1361 | pEdit->SetFontMap(&font_map); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1362 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1363 | CFX_FloatRect rcEdit = rcClient; |
| 1364 | rcEdit.right = rcButton.left; |
| 1365 | rcEdit.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1366 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1367 | pEdit->SetPlateRect(rcEdit); |
| 1368 | pEdit->SetAlignmentV(1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1369 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1370 | FX_FLOAT fFontSize = GetFontSize(); |
| 1371 | if (IsFloatZero(fFontSize)) |
| 1372 | pEdit->SetAutoFontSize(TRUE); |
| 1373 | else |
| 1374 | pEdit->SetFontSize(fFontSize); |
| 1375 | |
| 1376 | pEdit->Initialize(); |
| 1377 | |
| 1378 | if (sValue) { |
| 1379 | pEdit->SetText(sValue); |
| 1380 | } else { |
| 1381 | int32_t nCurSel = pField->GetSelectedIndex(0); |
| 1382 | |
| 1383 | if (nCurSel < 0) |
| 1384 | pEdit->SetText(pField->GetValue().c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1385 | else |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1386 | pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1389 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1390 | |
| 1391 | CFX_ByteString sEdit = |
| 1392 | CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); |
| 1393 | if (sEdit.GetLength() > 0) { |
| 1394 | sBody << "/Tx BMC\n" |
| 1395 | << "q\n"; |
| 1396 | if (rcContent.Width() > rcEdit.Width() || |
| 1397 | rcContent.Height() > rcEdit.Height()) { |
| 1398 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1399 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1400 | } |
| 1401 | |
| 1402 | CPWL_Color crText = GetTextPWLColor(); |
| 1403 | sBody << "BT\n" |
| 1404 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1405 | << "Q\nEMC\n"; |
| 1406 | } |
| 1407 | |
| 1408 | IFX_Edit::DelEdit(pEdit); |
| 1409 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1410 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1411 | |
| 1412 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1413 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1414 | |
| 1415 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1416 | } |
| 1417 | |
| 1418 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1419 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1420 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1421 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1422 | CFX_ByteTextBuf sBody, sLines; |
| 1423 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1424 | IFX_Edit* pEdit = IFX_Edit::NewEdit(); |
| 1425 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1426 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1427 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1428 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
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 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1431 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1432 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1433 | 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] | 1434 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1435 | FX_FLOAT fFontSize = GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1436 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1437 | if (IsFloatZero(fFontSize)) |
| 1438 | pEdit->SetFontSize(12.0f); |
| 1439 | else |
| 1440 | pEdit->SetFontSize(fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1441 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1442 | pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1443 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1444 | CFX_ByteTextBuf sList; |
| 1445 | FX_FLOAT fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1446 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1447 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1448 | int32_t nCount = pField->CountOptions(); |
| 1449 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1450 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1451 | for (int32_t i = nTop; i < nCount; i++) { |
| 1452 | FX_BOOL bSelected = FALSE; |
| 1453 | for (int32_t j = 0; j < nSelCount; j++) { |
| 1454 | if (pField->GetSelectedIndex(j) == i) { |
| 1455 | bSelected = TRUE; |
| 1456 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1457 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1458 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1459 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1460 | pEdit->SetText(pField->GetOptionLabel(i).c_str()); |
| 1461 | |
| 1462 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1463 | FX_FLOAT fItemHeight = rcContent.Height(); |
| 1464 | |
| 1465 | if (bSelected) { |
| 1466 | CFX_FloatRect rcItem = |
| 1467 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
| 1468 | sList << "q\n" |
| 1469 | << CPWL_Utils::GetColorAppStream( |
| 1470 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1471 | 113.0f / 255.0f), |
| 1472 | TRUE) |
| 1473 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1474 | << " " << rcItem.Height() << " re f\n" |
| 1475 | << "Q\n"; |
| 1476 | |
| 1477 | sList << "BT\n" |
| 1478 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
| 1479 | TRUE) |
| 1480 | << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) |
| 1481 | << "ET\n"; |
| 1482 | } else { |
| 1483 | CPWL_Color crText = GetTextPWLColor(); |
| 1484 | sList << "BT\n" |
| 1485 | << CPWL_Utils::GetColorAppStream(crText, TRUE) |
| 1486 | << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) |
| 1487 | << "ET\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1488 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1489 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1490 | fy -= fItemHeight; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1491 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1492 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1493 | if (sList.GetSize() > 0) { |
| 1494 | sBody << "/Tx BMC\n" |
| 1495 | << "q\n" |
| 1496 | << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1497 | << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1498 | sBody << sList << "Q\nEMC\n"; |
| 1499 | } |
| 1500 | |
| 1501 | IFX_Edit::DelEdit(pEdit); |
| 1502 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1503 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1504 | sLines.AsStringC() + sBody.AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1505 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1506 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1509 | void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { |
| 1510 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1511 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1512 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1513 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1514 | IFX_Edit* pEdit = IFX_Edit::NewEdit(); |
| 1515 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1516 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1517 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
| 1518 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1519 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1520 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1521 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1522 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1523 | CFX_FloatRect rcClient = GetClientRect(); |
| 1524 | pEdit->SetPlateRect(rcClient); |
| 1525 | pEdit->SetAlignmentH(pControl->GetControlAlignment()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1526 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1527 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
| 1528 | FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1529 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1530 | if (bMultiLine) { |
| 1531 | pEdit->SetMultiLine(TRUE); |
| 1532 | pEdit->SetAutoReturn(TRUE); |
| 1533 | } else { |
| 1534 | pEdit->SetAlignmentV(1); |
| 1535 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1536 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1537 | uint16_t subWord = 0; |
| 1538 | if ((dwFieldFlags >> 13) & 1) { |
| 1539 | subWord = '*'; |
| 1540 | pEdit->SetPasswordChar(subWord); |
| 1541 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1542 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1543 | int nMaxLen = pField->GetMaxLen(); |
| 1544 | FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; |
| 1545 | FX_FLOAT fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1546 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1547 | #ifdef PDF_ENABLE_XFA |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1548 | CFX_WideString sValueTmp; |
| 1549 | if (!sValue && GetMixXFAWidget()) { |
| 1550 | sValueTmp = GetValue(TRUE); |
| 1551 | sValue = sValueTmp.c_str(); |
| 1552 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1553 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1554 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1555 | if (nMaxLen > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1556 | if (bCharArray) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1557 | pEdit->SetCharArray(nMaxLen); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1558 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1559 | if (IsFloatZero(fFontSize)) { |
| 1560 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
| 1561 | rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1562 | } |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1563 | } else { |
| 1564 | if (sValue) |
| 1565 | nMaxLen = wcslen((const wchar_t*)sValue); |
| 1566 | pEdit->SetLimitChar(nMaxLen); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1567 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame^] | 1570 | if (IsFloatZero(fFontSize)) |
| 1571 | pEdit->SetAutoFontSize(TRUE); |
| 1572 | else |
| 1573 | pEdit->SetFontSize(fFontSize); |
| 1574 | |
| 1575 | pEdit->Initialize(); |
| 1576 | |
| 1577 | if (sValue) |
| 1578 | pEdit->SetText(sValue); |
| 1579 | else |
| 1580 | pEdit->SetText(pField->GetValue().c_str()); |
| 1581 | |
| 1582 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1583 | |
| 1584 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
| 1585 | pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); |
| 1586 | |
| 1587 | if (sEdit.GetLength() > 0) { |
| 1588 | sBody << "/Tx BMC\n" |
| 1589 | << "q\n"; |
| 1590 | if (rcContent.Width() > rcClient.Width() || |
| 1591 | rcContent.Height() > rcClient.Height()) { |
| 1592 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1593 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1594 | } |
| 1595 | CPWL_Color crText = GetTextPWLColor(); |
| 1596 | sBody << "BT\n" |
| 1597 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1598 | << "Q\nEMC\n"; |
| 1599 | } |
| 1600 | |
| 1601 | if (bCharArray) { |
| 1602 | switch (GetBorderStyle()) { |
| 1603 | case BBS_SOLID: { |
| 1604 | CFX_ByteString sColor = |
| 1605 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1606 | if (sColor.GetLength() > 0) { |
| 1607 | sLines << "q\n" |
| 1608 | << GetBorderWidth() << " w\n" |
| 1609 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1610 | << " 2 J 0 j\n"; |
| 1611 | |
| 1612 | for (int32_t i = 1; i < nMaxLen; i++) { |
| 1613 | sLines << rcClient.left + |
| 1614 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1615 | << " " << rcClient.bottom << " m\n" |
| 1616 | << rcClient.left + |
| 1617 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1618 | << " " << rcClient.top << " l S\n"; |
| 1619 | } |
| 1620 | |
| 1621 | sLines << "Q\n"; |
| 1622 | } |
| 1623 | } break; |
| 1624 | case BBS_DASH: { |
| 1625 | CFX_ByteString sColor = |
| 1626 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1627 | if (sColor.GetLength() > 0) { |
| 1628 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1629 | |
| 1630 | sLines << "q\n" |
| 1631 | << GetBorderWidth() << " w\n" |
| 1632 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1633 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1634 | << dsBorder.nPhase << " d\n"; |
| 1635 | |
| 1636 | for (int32_t i = 1; i < nMaxLen; i++) { |
| 1637 | sLines << rcClient.left + |
| 1638 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1639 | << " " << rcClient.bottom << " m\n" |
| 1640 | << rcClient.left + |
| 1641 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1642 | << " " << rcClient.top << " l S\n"; |
| 1643 | } |
| 1644 | |
| 1645 | sLines << "Q\n"; |
| 1646 | } |
| 1647 | } break; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | IFX_Edit::DelEdit(pEdit); |
| 1652 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1653 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1654 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1655 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1656 | } |
| 1657 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1658 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1659 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1660 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1661 | switch (GetBorderStyle()) { |
| 1662 | case BBS_BEVELED: |
| 1663 | case BBS_INSET: |
| 1664 | fBorderWidth *= 2.0f; |
| 1665 | break; |
| 1666 | } |
| 1667 | |
| 1668 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1671 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1672 | CFX_FloatRect rectAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1673 | FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; |
| 1674 | FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; |
| 1675 | |
| 1676 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1677 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1678 | switch (abs(pControl->GetRotation() % 360)) { |
| 1679 | case 0: |
| 1680 | case 180: |
| 1681 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1682 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1683 | break; |
| 1684 | case 90: |
| 1685 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1686 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1687 | break; |
| 1688 | } |
| 1689 | |
| 1690 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1693 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1694 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1695 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) { |
| 1696 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
| 1697 | } |
| 1698 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1701 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1702 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1703 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1704 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1705 | CPWL_Color crLeftTop, crRightBottom; |
| 1706 | |
| 1707 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1708 | int32_t nBorderStyle = 0; |
| 1709 | CPWL_Dash dsBorder(3, 0, 0); |
| 1710 | |
| 1711 | switch (GetBorderStyle()) { |
| 1712 | case BBS_DASH: |
| 1713 | nBorderStyle = PBS_DASH; |
| 1714 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1715 | break; |
| 1716 | case BBS_BEVELED: |
| 1717 | nBorderStyle = PBS_BEVELED; |
| 1718 | fBorderWidth *= 2; |
| 1719 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1720 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1721 | break; |
| 1722 | case BBS_INSET: |
| 1723 | nBorderStyle = PBS_INSET; |
| 1724 | fBorderWidth *= 2; |
| 1725 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1726 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1727 | break; |
| 1728 | case BBS_UNDERLINE: |
| 1729 | nBorderStyle = PBS_UNDERLINED; |
| 1730 | break; |
| 1731 | default: |
| 1732 | nBorderStyle = PBS_SOLID; |
| 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1737 | crLeftTop, crRightBottom, nBorderStyle, |
| 1738 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1741 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1742 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1743 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1744 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1745 | FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; |
| 1746 | FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; |
| 1747 | |
| 1748 | switch (abs(pControl->GetRotation() % 360)) { |
| 1749 | case 0: |
| 1750 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1751 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1752 | break; |
| 1753 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1754 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1755 | break; |
| 1756 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1757 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1758 | break; |
| 1759 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1760 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1761 | break; |
| 1762 | } |
| 1763 | |
| 1764 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1767 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1768 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1769 | |
| 1770 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1771 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1772 | if (da.HasColor()) { |
| 1773 | int32_t iColorType; |
| 1774 | FX_FLOAT fc[4]; |
| 1775 | da.GetColor(iColorType, fc); |
| 1776 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1777 | } |
| 1778 | |
| 1779 | return crText; |
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::GetBorderPWLColor() const { |
| 1783 | CPWL_Color crBorder; |
| 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->GetOriginalBorderColor(iColorType, fc); |
| 1789 | if (iColorType > 0) |
| 1790 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1791 | |
| 1792 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1793 | } |
| 1794 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1795 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1796 | CPWL_Color crFill; |
| 1797 | |
| 1798 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1799 | int32_t iColorType; |
| 1800 | FX_FLOAT fc[4]; |
| 1801 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1802 | if (iColorType > 0) |
| 1803 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1804 | |
| 1805 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1808 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1809 | CPDF_Stream* pImage) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1810 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1811 | ASSERT(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1812 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1813 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1814 | CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1815 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1816 | CFX_ByteString sImageAlias = "IMG"; |
| 1817 | |
| 1818 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1819 | sImageAlias = pImageDict->GetStringBy("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1820 | if (sImageAlias.IsEmpty()) |
| 1821 | sImageAlias = "IMG"; |
| 1822 | } |
| 1823 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1824 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1825 | if (!pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1826 | pStreamResList = new CPDF_Dictionary(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1827 | pStreamDict->SetAt("Resources", pStreamResList); |
| 1828 | } |
| 1829 | |
| 1830 | if (pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1831 | CPDF_Dictionary* pXObject = new CPDF_Dictionary; |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1832 | pXObject->SetAtReference(sImageAlias, pDoc, pImage); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1833 | pStreamResList->SetAt("XObject", pXObject); |
| 1834 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1835 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1836 | |
| 1837 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
tsepez | 7b1ccf9 | 2016-04-14 11:04:57 -0700 | [diff] [blame] | 1838 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) |
| 1839 | pAPDict->RemoveAt(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1843 | PDFSDK_FieldAction& data, |
| 1844 | CPDFSDK_PageView* pPageView) { |
| 1845 | CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1846 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1847 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1848 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1849 | CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1850 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1851 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1852 | |
| 1853 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1854 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1855 | CXFA_EventParam param; |
| 1856 | param.m_eType = eEventType; |
| 1857 | param.m_wsChange = data.sChange; |
| 1858 | param.m_iCommitKey = data.nCommitKey; |
| 1859 | param.m_bShift = data.bShift; |
| 1860 | param.m_iSelStart = data.nSelStart; |
| 1861 | param.m_iSelEnd = data.nSelEnd; |
| 1862 | param.m_wsFullText = data.sValue; |
| 1863 | param.m_bKeyDown = data.bKeyDown; |
| 1864 | param.m_bModifier = data.bModifier; |
| 1865 | param.m_wsNewText = data.sValue; |
| 1866 | if (data.nSelEnd > data.nSelStart) |
| 1867 | param.m_wsNewText.Delete(data.nSelStart, |
| 1868 | data.nSelEnd - data.nSelStart); |
| 1869 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1870 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1871 | param.m_wsPrevText = data.sValue; |
| 1872 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1873 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1874 | param.m_pTarget = pAcc; |
| 1875 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1876 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1877 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1878 | pDocView->UpdateDocView(); |
| 1879 | } |
| 1880 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1881 | if (nRet == XFA_EVENTERROR_Success) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1882 | return TRUE; |
| 1883 | } |
| 1884 | } |
| 1885 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1886 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1887 | |
| 1888 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1889 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1890 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 1891 | return pActionHandler->DoAction_Field(action, type, pDocument, |
| 1892 | GetFormField(), data); |
| 1893 | } |
| 1894 | return FALSE; |
| 1895 | } |
| 1896 | |
| 1897 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1898 | switch (eAAT) { |
| 1899 | case CPDF_AAction::CursorEnter: |
| 1900 | case CPDF_AAction::CursorExit: |
| 1901 | case CPDF_AAction::ButtonDown: |
| 1902 | case CPDF_AAction::ButtonUp: |
| 1903 | case CPDF_AAction::GetFocus: |
| 1904 | case CPDF_AAction::LoseFocus: |
| 1905 | case CPDF_AAction::PageOpen: |
| 1906 | case CPDF_AAction::PageClose: |
| 1907 | case CPDF_AAction::PageVisible: |
| 1908 | case CPDF_AAction::PageInvisible: |
| 1909 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1910 | |
| 1911 | case CPDF_AAction::KeyStroke: |
| 1912 | case CPDF_AAction::Format: |
| 1913 | case CPDF_AAction::Validate: |
| 1914 | case CPDF_AAction::Calculate: { |
| 1915 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1916 | if (pField->GetAdditionalAction().GetDict()) |
| 1917 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1918 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1919 | } |
| 1920 | default: |
| 1921 | break; |
| 1922 | } |
| 1923 | |
| 1924 | return CPDF_Action(); |
| 1925 | } |
| 1926 | |
| 1927 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1928 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1929 | return pFormField->GetAlternateName(); |
| 1930 | } |
| 1931 | |
| 1932 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1933 | return m_nAppAge; |
| 1934 | } |
| 1935 | |
| 1936 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1937 | return m_nValueAge; |
| 1938 | } |
| 1939 | |
| 1940 | FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) { |
| 1941 | CPDF_Annot* pAnnot = GetPDFAnnot(); |
| 1942 | CFX_FloatRect annotRect; |
| 1943 | pAnnot->GetRect(annotRect); |
| 1944 | if (annotRect.Contains(pageX, pageY)) { |
| 1945 | if (!IsVisible()) |
| 1946 | return FALSE; |
| 1947 | |
| 1948 | int nFieldFlags = GetFieldFlags(); |
| 1949 | if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
| 1950 | return FALSE; |
| 1951 | |
| 1952 | return TRUE; |
| 1953 | } |
| 1954 | return FALSE; |
| 1955 | } |
| 1956 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1957 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1958 | CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(CXFA_FFWidget* pAnnot, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1959 | CPDFSDK_PageView* pPageView, |
| 1960 | CPDFSDK_InterForm* pInterForm) |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 1961 | : CPDFSDK_Annot(pPageView), |
| 1962 | m_pInterForm(pInterForm), |
| 1963 | m_hXFAWidget(pAnnot) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1964 | |
| 1965 | FX_BOOL CPDFSDK_XFAWidget::IsXFAField() { |
| 1966 | return TRUE; |
| 1967 | } |
| 1968 | |
| 1969 | CFX_ByteString CPDFSDK_XFAWidget::GetType() const { |
| 1970 | return FSDK_XFAWIDGET_TYPENAME; |
| 1971 | } |
| 1972 | |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 1973 | CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1974 | CFX_RectF rcBBox; |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1975 | GetXFAWidget()->GetRect(rcBBox); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1976 | return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 1977 | rcBBox.top + rcBBox.height); |
| 1978 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1979 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1980 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1981 | CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) |
| 1982 | : m_pDocument(pDocument), |
| 1983 | m_pInterForm(NULL), |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1984 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1985 | m_bXfaCalculate(TRUE), |
| 1986 | m_bXfaValidationsEnabled(TRUE), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1987 | #endif // PDF_ENABLE_XFA |
| 1988 | m_bCalculate(TRUE), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1989 | m_bBusy(FALSE) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1990 | m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1991 | m_pInterForm->SetFormNotify(this); |
| 1992 | |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 1993 | for (int i = 0; i < kNumFieldTypes; ++i) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1994 | m_bNeedHightlight[i] = FALSE; |
| 1995 | m_iHighlightAlpha = 0; |
| 1996 | } |
| 1997 | |
| 1998 | CPDFSDK_InterForm::~CPDFSDK_InterForm() { |
| 1999 | delete m_pInterForm; |
| 2000 | m_pInterForm = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2001 | m_Map.clear(); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2002 | #ifdef PDF_ENABLE_XFA |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2003 | m_XFAMap.clear(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2004 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | FX_BOOL CPDFSDK_InterForm::HighlightWidgets() { |
| 2008 | return FALSE; |
| 2009 | } |
| 2010 | |
| 2011 | CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, |
| 2012 | FX_BOOL bNext) const { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2013 | std::unique_ptr<CBA_AnnotIterator> pIterator( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2014 | new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); |
| 2015 | |
| 2016 | if (bNext) { |
| 2017 | return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget); |
| 2018 | } |
| 2019 | return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget); |
| 2020 | } |
| 2021 | |
| 2022 | CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { |
| 2023 | if (!pControl || !m_pInterForm) |
| 2024 | return nullptr; |
| 2025 | |
| 2026 | CPDFSDK_Widget* pWidget = nullptr; |
| 2027 | const auto it = m_Map.find(pControl); |
| 2028 | if (it != m_Map.end()) |
| 2029 | pWidget = it->second; |
| 2030 | |
| 2031 | if (pWidget) |
| 2032 | return pWidget; |
| 2033 | |
| 2034 | CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 2035 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2036 | CPDFSDK_PageView* pPage = nullptr; |
| 2037 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2038 | if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2039 | int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
| 2040 | if (nPageIndex >= 0) { |
| 2041 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2042 | } |
| 2043 | } |
| 2044 | |
| 2045 | if (!pPage) { |
| 2046 | int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
| 2047 | if (nPageIndex >= 0) { |
| 2048 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | if (!pPage) |
| 2053 | return nullptr; |
| 2054 | return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); |
| 2055 | } |
| 2056 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2057 | void CPDFSDK_InterForm::GetWidgets( |
| 2058 | const CFX_WideString& sFieldName, |
| 2059 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2060 | for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2061 | CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2062 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2063 | GetWidgets(pFormField, widgets); |
| 2064 | } |
| 2065 | } |
| 2066 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2067 | void CPDFSDK_InterForm::GetWidgets( |
| 2068 | CPDF_FormField* pField, |
| 2069 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2070 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2071 | CPDF_FormControl* pFormCtrl = pField->GetControl(i); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2072 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2073 | CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2074 | if (pWidget) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2075 | widgets->push_back(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
| 2080 | CPDF_Document* pDocument, |
| 2081 | CPDF_Dictionary* pAnnotDict) const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2082 | ASSERT(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2083 | |
| 2084 | for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { |
| 2085 | if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2086 | if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2087 | for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { |
tsepez | bd56755 | 2016-03-29 14:51:50 -0700 | [diff] [blame] | 2088 | CPDF_Object* pDict = pAnnots->GetDirectObjectAt(j); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2089 | if (pAnnotDict == pDict) { |
| 2090 | return i; |
| 2091 | } |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | return -1; |
| 2098 | } |
| 2099 | |
| 2100 | void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, |
| 2101 | CPDFSDK_Widget* pWidget) { |
| 2102 | m_Map[pControl] = pWidget; |
| 2103 | } |
| 2104 | |
| 2105 | void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) { |
| 2106 | m_Map.erase(pControl); |
| 2107 | } |
| 2108 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2109 | void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) { |
| 2110 | m_bCalculate = bEnabled; |
| 2111 | } |
| 2112 | |
| 2113 | FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { |
| 2114 | return m_bCalculate; |
| 2115 | } |
| 2116 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2117 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2118 | void CPDFSDK_InterForm::AddXFAMap(CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2119 | CPDFSDK_XFAWidget* pWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2120 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2121 | m_XFAMap[hWidget] = pWidget; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2124 | void CPDFSDK_InterForm::RemoveXFAMap(CXFA_FFWidget* hWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2125 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2126 | m_XFAMap.erase(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 2129 | CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(CXFA_FFWidget* hWidget) { |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 2130 | ASSERT(hWidget); |
tsepez | 16a2033 | 2016-04-22 14:00:47 -0700 | [diff] [blame] | 2131 | auto it = m_XFAMap.find(hWidget); |
| 2132 | return it != m_XFAMap.end() ? it->second : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2133 | } |
| 2134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2135 | void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) { |
| 2136 | m_bXfaCalculate = bEnabled; |
| 2137 | } |
| 2138 | FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const { |
| 2139 | return m_bXfaCalculate; |
| 2140 | } |
| 2141 | |
| 2142 | FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() { |
| 2143 | return m_bXfaValidationsEnabled; |
| 2144 | } |
| 2145 | void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) { |
| 2146 | m_bXfaValidationsEnabled = bEnabled; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2147 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2148 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2149 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2150 | void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2151 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2152 | ASSERT(pEnv); |
| 2153 | if (!pEnv->IsJSInitiated()) |
| 2154 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2155 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2156 | if (m_bBusy) |
| 2157 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2158 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2159 | m_bBusy = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2161 | if (IsCalculateEnabled()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2162 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2163 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2164 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2165 | int nSize = m_pInterForm->CountFieldsInCalculationOrder(); |
| 2166 | for (int i = 0; i < nSize; i++) { |
| 2167 | if (CPDF_FormField* pField = |
| 2168 | m_pInterForm->GetFieldInCalculationOrder(i)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2169 | int nType = pField->GetFieldType(); |
| 2170 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2171 | CPDF_AAction aAction = pField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2172 | if (aAction.GetDict() && |
| 2173 | aAction.ActionExist(CPDF_AAction::Calculate)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2174 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2175 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2176 | CFX_WideString csJS = action.GetJavaScript(); |
| 2177 | if (!csJS.IsEmpty()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2178 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2179 | CFX_WideString sOldValue = pField->GetValue(); |
| 2180 | CFX_WideString sValue = sOldValue; |
| 2181 | FX_BOOL bRC = TRUE; |
| 2182 | pContext->OnField_Calculate(pFormField, pField, sValue, bRC); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2183 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2184 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2185 | FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2186 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2187 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2188 | if (bRet) { |
| 2189 | if (bRC) { |
| 2190 | if (sValue.Compare(sOldValue) != 0) |
| 2191 | pField->SetValue(sValue, TRUE); |
| 2192 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2193 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2194 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2195 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2196 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2197 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2198 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2199 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2200 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2202 | m_bBusy = FALSE; |
| 2203 | } |
| 2204 | |
| 2205 | CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, |
| 2206 | FX_BOOL& bFormated) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2207 | CFX_WideString sValue = pFormField->GetValue(); |
| 2208 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2209 | ASSERT(pEnv); |
| 2210 | if (!pEnv->IsJSInitiated()) { |
| 2211 | bFormated = FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2212 | return sValue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2213 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2214 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2215 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2216 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2217 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2218 | if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) { |
| 2219 | if (pFormField->CountSelectedItems() > 0) { |
| 2220 | int index = pFormField->GetSelectedIndex(0); |
| 2221 | if (index >= 0) |
| 2222 | sValue = pFormField->GetOptionLabel(index); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2223 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2224 | } |
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 | bFormated = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2227 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2228 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2229 | if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2230 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2231 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2232 | CFX_WideString script = action.GetJavaScript(); |
| 2233 | if (!script.IsEmpty()) { |
| 2234 | CFX_WideString Value = sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2235 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2236 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2237 | pContext->OnField_Format(pFormField, Value, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2238 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2239 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2240 | FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2241 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2242 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2243 | if (bRet) { |
| 2244 | sValue = Value; |
| 2245 | bFormated = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2246 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2247 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2248 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | return sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2254 | void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, |
| 2255 | const FX_WCHAR* sValue, |
| 2256 | FX_BOOL bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2257 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2258 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2259 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2260 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) |
| 2261 | pWidget->ResetAppearance(sValue, bValueChanged); |
| 2262 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2265 | void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2266 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2267 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2268 | ASSERT(pFormCtrl); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2269 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2270 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2271 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2272 | CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 2273 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2274 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2275 | FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2277 | pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 2278 | rcBBox.bottom); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2279 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2283 | FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| 2284 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2285 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2286 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2287 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2288 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2289 | CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2290 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2291 | return TRUE; |
| 2292 | |
| 2293 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2294 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2295 | PDFSDK_FieldAction fa; |
| 2296 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2297 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2298 | fa.sValue = csValue; |
| 2299 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
| 2300 | m_pDocument, pFormField, fa); |
| 2301 | return fa.bRC; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2304 | FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
| 2305 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2306 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2307 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2308 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2309 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2310 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2311 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2312 | return TRUE; |
| 2313 | |
| 2314 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2315 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2316 | PDFSDK_FieldAction fa; |
| 2317 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2318 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2319 | fa.sValue = csValue; |
| 2320 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
| 2321 | m_pDocument, pFormField, fa); |
| 2322 | return fa.bRC; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2325 | FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2326 | ASSERT(action.GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2327 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2328 | CPDF_ActionFields af(&action); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2329 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2330 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2331 | |
| 2332 | FX_BOOL bHide = action.GetHideStatus(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2333 | FX_BOOL bChanged = FALSE; |
| 2334 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2335 | for (CPDF_FormField* pField : fields) { |
| 2336 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| 2337 | CPDF_FormControl* pControl = pField->GetControl(i); |
| 2338 | ASSERT(pControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2339 | |
| 2340 | if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2341 | uint32_t nFlags = pWidget->GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2342 | nFlags &= ~ANNOTFLAG_INVISIBLE; |
| 2343 | nFlags &= ~ANNOTFLAG_NOVIEW; |
| 2344 | if (bHide) |
| 2345 | nFlags |= ANNOTFLAG_HIDDEN; |
| 2346 | else |
| 2347 | nFlags &= ~ANNOTFLAG_HIDDEN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2348 | pWidget->SetFlags(nFlags); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2349 | pWidget->GetPageView()->UpdateView(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2350 | bChanged = TRUE; |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | return bChanged; |
| 2356 | } |
| 2357 | |
| 2358 | FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2359 | CFX_WideString sDestination = action.GetFilePath(); |
| 2360 | if (sDestination.IsEmpty()) |
| 2361 | return FALSE; |
| 2362 | |
| 2363 | CPDF_Dictionary* pActionDict = action.GetDict(); |
| 2364 | if (pActionDict->KeyExist("Fields")) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2365 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2366 | uint32_t dwFlags = action.GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2367 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2368 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2369 | if (!fields.empty()) { |
| 2370 | bool bIncludeOrExclude = !(dwFlags & 0x01); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2371 | if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2372 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2373 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2374 | return SubmitFields(sDestination, fields, bIncludeOrExclude, false); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2375 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2376 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2377 | if (m_pInterForm->CheckRequiredFields(nullptr, true)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2378 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2379 | |
| 2380 | return SubmitForm(sDestination, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2383 | FX_BOOL CPDFSDK_InterForm::SubmitFields( |
| 2384 | const CFX_WideString& csDestination, |
| 2385 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2386 | bool bIncludeOrExclude, |
| 2387 | bool bUrlEncoded) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2388 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2389 | |
| 2390 | CFX_ByteTextBuf textBuf; |
| 2391 | ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); |
| 2392 | |
| 2393 | uint8_t* pBuffer = textBuf.GetBuffer(); |
| 2394 | FX_STRSIZE nBufSize = textBuf.GetLength(); |
| 2395 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2396 | if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2397 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2398 | |
| 2399 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2400 | return TRUE; |
| 2401 | } |
| 2402 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2403 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
| 2404 | CFX_WideString csTxtFile) { |
| 2405 | return TRUE; |
| 2406 | } |
| 2407 | |
| 2408 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
| 2409 | FX_STRSIZE& nBufSize) { |
| 2410 | CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
| 2411 | if (pFDF) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2412 | CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2413 | if (!pMainDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2414 | return FALSE; |
| 2415 | |
| 2416 | // Get fields |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2417 | CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2418 | if (!pFields) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2419 | return FALSE; |
| 2420 | |
| 2421 | CFX_ByteTextBuf fdfEncodedData; |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2422 | for (uint32_t i = 0; i < pFields->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2423 | CPDF_Dictionary* pField = pFields->GetDictAt(i); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2424 | if (!pField) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2425 | continue; |
| 2426 | CFX_WideString name; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2427 | name = pField->GetUnicodeTextBy("T"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2428 | CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2429 | CFX_ByteString csBValue = pField->GetStringBy("V"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2430 | CFX_WideString csWValue = PDF_DecodeText(csBValue); |
| 2431 | CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
| 2432 | |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2433 | fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2434 | name_b.ReleaseBuffer(); |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2435 | fdfEncodedData << "="; |
| 2436 | fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2437 | csValue_b.ReleaseBuffer(); |
| 2438 | if (i != pFields->GetCount() - 1) |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2439 | fdfEncodedData << "&"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | nBufSize = fdfEncodedData.GetLength(); |
| 2443 | pBuf = FX_Alloc(uint8_t, nBufSize); |
| 2444 | FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
| 2445 | } |
| 2446 | return TRUE; |
| 2447 | } |
| 2448 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2449 | FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| 2450 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2451 | bool bIncludeOrExclude, |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2452 | CFX_ByteTextBuf& textBuf) { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2453 | std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2454 | m_pDocument->GetPath().AsStringC(), fields, bIncludeOrExclude)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2455 | return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2458 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2459 | void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, |
| 2460 | FX_BOOL bSynchronizeElse) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2461 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2462 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2463 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2464 | pWidget->Synchronize(bSynchronizeElse); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2465 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2466 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2467 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2468 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2469 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2470 | CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 2471 | const CFX_WideString& sFileExt) { |
| 2472 | CFX_WideString sFileName; |
| 2473 | return L""; |
| 2474 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2475 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2476 | FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
| 2477 | FX_BOOL bUrlEncoded) { |
| 2478 | if (sDestination.IsEmpty()) |
| 2479 | return FALSE; |
| 2480 | |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2481 | if (!m_pDocument || !m_pInterForm) |
| 2482 | return FALSE; |
| 2483 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2484 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2485 | CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2486 | CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC()); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2487 | if (!pFDFDoc) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2488 | return FALSE; |
| 2489 | |
| 2490 | CFX_ByteTextBuf FdfBuffer; |
| 2491 | FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
| 2492 | delete pFDFDoc; |
| 2493 | if (!bRet) |
| 2494 | return FALSE; |
| 2495 | |
| 2496 | uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
| 2497 | FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
| 2498 | |
| 2499 | if (bUrlEncoded) { |
| 2500 | if (!FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2501 | return FALSE; |
| 2502 | } |
| 2503 | |
| 2504 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
| 2505 | |
Lei Zhang | da180e9 | 2015-08-14 22:22:13 -0700 | [diff] [blame] | 2506 | if (bUrlEncoded) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2507 | FX_Free(pBuffer); |
| 2508 | pBuffer = NULL; |
| 2509 | } |
| 2510 | |
| 2511 | return TRUE; |
| 2512 | } |
| 2513 | |
| 2514 | FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 2515 | CFDF_Document* pFDF = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 2516 | m_pInterForm->ExportToFDF(m_pDocument->GetPath().AsStringC()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2517 | if (!pFDF) |
| 2518 | return FALSE; |
| 2519 | |
| 2520 | FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
| 2521 | delete pFDF; |
| 2522 | |
| 2523 | return bRet; |
| 2524 | } |
| 2525 | |
| 2526 | FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2527 | ASSERT(action.GetDict()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2528 | |
| 2529 | CPDF_Dictionary* pActionDict = action.GetDict(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2530 | if (!pActionDict->KeyExist("Fields")) |
| 2531 | return m_pInterForm->ResetForm(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2532 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2533 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2534 | uint32_t dwFlags = action.GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2535 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2536 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2537 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2538 | return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { |
| 2542 | return FALSE; |
| 2543 | } |
| 2544 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2545 | std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( |
| 2546 | const std::vector<CPDF_Object*>& objects) const { |
| 2547 | std::vector<CPDF_FormField*> fields; |
| 2548 | for (CPDF_Object* pObject : objects) { |
| 2549 | if (pObject && pObject->IsString()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2550 | CFX_WideString csName = pObject->GetUnicodeText(); |
| 2551 | CPDF_FormField* pField = m_pInterForm->GetField(0, csName); |
Dan Sinclair | d43ebdd | 2015-10-27 15:37:54 -0400 | [diff] [blame] | 2552 | if (pField) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2553 | fields.push_back(pField); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2554 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2555 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2556 | return fields; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2559 | int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField, |
| 2560 | const CFX_WideString& csValue) { |
| 2561 | int nType = pField->GetFieldType(); |
| 2562 | if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2563 | return 0; |
| 2564 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2565 | if (!OnKeyStrokeCommit(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2566 | return -1; |
| 2567 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2568 | if (!OnValidate(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2569 | return -1; |
| 2570 | |
| 2571 | return 1; |
| 2572 | } |
| 2573 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2574 | void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { |
| 2575 | #ifdef PDF_ENABLE_XFA |
| 2576 | SynchronizeField(pField, FALSE); |
| 2577 | #endif // PDF_ENABLE_XFA |
| 2578 | int nType = pField->GetFieldType(); |
| 2579 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2580 | OnCalculate(pField); |
| 2581 | FX_BOOL bFormated = FALSE; |
| 2582 | CFX_WideString sValue = OnFormat(pField, bFormated); |
| 2583 | ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); |
| 2584 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2585 | } |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, |
| 2589 | const CFX_WideString& csValue) { |
| 2590 | if (pField->GetFieldType() != FIELDTYPE_LISTBOX) |
| 2591 | return 0; |
| 2592 | |
| 2593 | if (!OnKeyStrokeCommit(pField, csValue)) |
| 2594 | return -1; |
| 2595 | |
| 2596 | if (!OnValidate(pField, csValue)) |
| 2597 | return -1; |
| 2598 | |
| 2599 | return 1; |
| 2600 | } |
| 2601 | |
| 2602 | void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) { |
| 2603 | if (pField->GetFieldType() == FIELDTYPE_LISTBOX) { |
| 2604 | OnCalculate(pField); |
| 2605 | ResetFieldAppearance(pField, NULL, TRUE); |
| 2606 | UpdateField(pField); |
| 2607 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2610 | void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { |
| 2611 | int nType = pField->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2612 | if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) { |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2613 | OnCalculate(pField); |
| 2614 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2615 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2618 | int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2619 | return 0; |
| 2620 | } |
| 2621 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2622 | void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2623 | OnCalculate(nullptr); |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2627 | return 0; |
| 2628 | } |
| 2629 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2630 | void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2631 | OnCalculate(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2635 | if (nFieldType < 1 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2636 | return FALSE; |
| 2637 | return m_bNeedHightlight[nFieldType - 1]; |
| 2638 | } |
| 2639 | |
| 2640 | void CPDFSDK_InterForm::RemoveAllHighLight() { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2641 | for (int i = 0; i < kNumFieldTypes; ++i) |
| 2642 | m_bNeedHightlight[i] = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2643 | } |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2645 | void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2646 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2647 | return; |
| 2648 | switch (nFieldType) { |
| 2649 | case 0: { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2650 | for (int i = 0; i < kNumFieldTypes; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2651 | m_aHighlightColor[i] = clr; |
| 2652 | m_bNeedHightlight[i] = TRUE; |
| 2653 | } |
| 2654 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2655 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2656 | default: { |
| 2657 | m_aHighlightColor[nFieldType - 1] = clr; |
| 2658 | m_bNeedHightlight[nFieldType - 1] = TRUE; |
| 2659 | break; |
| 2660 | } |
| 2661 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2664 | FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2665 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2666 | return FXSYS_RGB(255, 255, 255); |
| 2667 | if (nFieldType == 0) |
| 2668 | return m_aHighlightColor[0]; |
| 2669 | return m_aHighlightColor[nFieldType - 1]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2672 | CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, |
| 2673 | const CFX_ByteString& sType, |
| 2674 | const CFX_ByteString& sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2675 | : m_eTabOrder(STRUCTURE), |
| 2676 | m_pPageView(pPageView), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2677 | m_sType(sType), |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2678 | m_sSubType(sSubType) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2679 | CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2680 | CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2681 | if (sTabs == "R") |
| 2682 | m_eTabOrder = ROW; |
| 2683 | else if (sTabs == "C") |
| 2684 | m_eTabOrder = COLUMN; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2685 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2686 | GenerateResults(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 2689 | CBA_AnnotIterator::~CBA_AnnotIterator() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2690 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2691 | CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2692 | return m_Annots.empty() ? nullptr : m_Annots.front(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2695 | CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2696 | return m_Annots.empty() ? nullptr : m_Annots.back(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2699 | CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2700 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2701 | if (iter == m_Annots.end()) |
| 2702 | return nullptr; |
| 2703 | ++iter; |
| 2704 | if (iter == m_Annots.end()) |
| 2705 | iter = m_Annots.begin(); |
| 2706 | return *iter; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2709 | CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2710 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2711 | if (iter == m_Annots.end()) |
| 2712 | return nullptr; |
| 2713 | if (iter == m_Annots.begin()) |
| 2714 | iter = m_Annots.end(); |
| 2715 | return *(--iter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2718 | // static |
| 2719 | bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1, |
| 2720 | const CPDFSDK_Annot* p2) { |
| 2721 | return GetAnnotRect(p1).left < GetAnnotRect(p2).left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2724 | // static |
| 2725 | bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1, |
| 2726 | const CPDFSDK_Annot* p2) { |
| 2727 | return GetAnnotRect(p1).top > GetAnnotRect(p2).top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2730 | void CBA_AnnotIterator::GenerateResults() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2731 | switch (m_eTabOrder) { |
| 2732 | case STRUCTURE: { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 2733 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2734 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2735 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2736 | m_Annots.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2737 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2738 | } break; |
| 2739 | case ROW: { |
| 2740 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2741 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2742 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2743 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2744 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2747 | std::sort(sa.begin(), sa.end(), CompareByLeftAscending); |
| 2748 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2749 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2750 | FX_FLOAT fTop = 0.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2751 | for (int i = sa.size() - 1; i >= 0; i--) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2752 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2753 | if (rcAnnot.top > fTop) { |
| 2754 | nLeftTopIndex = i; |
| 2755 | fTop = rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2756 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2757 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2758 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2759 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2760 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2761 | m_Annots.push_back(pLeftTopAnnot); |
| 2762 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2763 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2764 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2765 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2766 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2767 | FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; |
| 2768 | if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2769 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2770 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2771 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2772 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2773 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2774 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2775 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2776 | } |
| 2777 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2778 | } break; |
| 2779 | case COLUMN: { |
| 2780 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2781 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2782 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2783 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2784 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2787 | std::sort(sa.begin(), sa.end(), CompareByTopDescending); |
| 2788 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2789 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2790 | FX_FLOAT fLeft = -1.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2791 | for (int i = sa.size() - 1; i >= 0; --i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2792 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2793 | if (fLeft < 0) { |
| 2794 | nLeftTopIndex = 0; |
| 2795 | fLeft = rcAnnot.left; |
| 2796 | } else if (rcAnnot.left < fLeft) { |
| 2797 | nLeftTopIndex = i; |
| 2798 | fLeft = rcAnnot.left; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2799 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2800 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2801 | |
| 2802 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2803 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2804 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2805 | m_Annots.push_back(pLeftTopAnnot); |
| 2806 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2807 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2808 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2809 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2810 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2811 | FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; |
| 2812 | if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2813 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2814 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame] | 2815 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2816 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2817 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2818 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2819 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2820 | } |
| 2821 | } |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2822 | break; |
| 2823 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2824 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2825 | } |
| 2826 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2827 | CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2828 | CFX_FloatRect rcAnnot; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2829 | pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2830 | return rcAnnot; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2831 | } |