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