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 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/javascript/Field.h" |
Tom Sepez | 3745841 | 2015-10-06 11:33:46 -0700 | [diff] [blame] | 8 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <string> |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 15 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/include/fsdk_mgr.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 17 | #include "fpdfsdk/javascript/Document.h" |
| 18 | #include "fpdfsdk/javascript/Icon.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 19 | #include "fpdfsdk/javascript/JS_Define.h" |
| 20 | #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 21 | #include "fpdfsdk/javascript/JS_Object.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 22 | #include "fpdfsdk/javascript/JS_Value.h" |
| 23 | #include "fpdfsdk/javascript/PublicMethods.h" |
dsinclair | 64376be | 2016-03-31 20:03:24 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/javascript/cjs_context.h" |
| 25 | #include "fpdfsdk/javascript/cjs_runtime.h" |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 26 | #include "fpdfsdk/javascript/color.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | BEGIN_JS_STATIC_CONST(CJS_Field) |
| 29 | END_JS_STATIC_CONST() |
| 30 | |
| 31 | BEGIN_JS_STATIC_PROP(CJS_Field) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | JS_STATIC_PROP_ENTRY(alignment) |
| 33 | JS_STATIC_PROP_ENTRY(borderStyle) |
| 34 | JS_STATIC_PROP_ENTRY(buttonAlignX) |
| 35 | JS_STATIC_PROP_ENTRY(buttonAlignY) |
| 36 | JS_STATIC_PROP_ENTRY(buttonFitBounds) |
| 37 | JS_STATIC_PROP_ENTRY(buttonPosition) |
| 38 | JS_STATIC_PROP_ENTRY(buttonScaleHow) |
| 39 | JS_STATIC_PROP_ENTRY(buttonScaleWhen) |
| 40 | JS_STATIC_PROP_ENTRY(calcOrderIndex) |
| 41 | JS_STATIC_PROP_ENTRY(charLimit) |
| 42 | JS_STATIC_PROP_ENTRY(comb) |
| 43 | JS_STATIC_PROP_ENTRY(commitOnSelChange) |
| 44 | JS_STATIC_PROP_ENTRY(currentValueIndices) |
| 45 | JS_STATIC_PROP_ENTRY(defaultStyle) |
| 46 | JS_STATIC_PROP_ENTRY(defaultValue) |
| 47 | JS_STATIC_PROP_ENTRY(doNotScroll) |
| 48 | JS_STATIC_PROP_ENTRY(doNotSpellCheck) |
| 49 | JS_STATIC_PROP_ENTRY(delay) |
| 50 | JS_STATIC_PROP_ENTRY(display) |
| 51 | JS_STATIC_PROP_ENTRY(doc) |
| 52 | JS_STATIC_PROP_ENTRY(editable) |
| 53 | JS_STATIC_PROP_ENTRY(exportValues) |
| 54 | JS_STATIC_PROP_ENTRY(hidden) |
| 55 | JS_STATIC_PROP_ENTRY(fileSelect) |
| 56 | JS_STATIC_PROP_ENTRY(fillColor) |
| 57 | JS_STATIC_PROP_ENTRY(lineWidth) |
| 58 | JS_STATIC_PROP_ENTRY(highlight) |
| 59 | JS_STATIC_PROP_ENTRY(multiline) |
| 60 | JS_STATIC_PROP_ENTRY(multipleSelection) |
| 61 | JS_STATIC_PROP_ENTRY(name) |
| 62 | JS_STATIC_PROP_ENTRY(numItems) |
| 63 | JS_STATIC_PROP_ENTRY(page) |
| 64 | JS_STATIC_PROP_ENTRY(password) |
| 65 | JS_STATIC_PROP_ENTRY(print) |
| 66 | JS_STATIC_PROP_ENTRY(radiosInUnison) |
| 67 | JS_STATIC_PROP_ENTRY(readonly) |
| 68 | JS_STATIC_PROP_ENTRY(rect) |
| 69 | JS_STATIC_PROP_ENTRY(required) |
| 70 | JS_STATIC_PROP_ENTRY(richText) |
| 71 | JS_STATIC_PROP_ENTRY(richValue) |
| 72 | JS_STATIC_PROP_ENTRY(rotation) |
| 73 | JS_STATIC_PROP_ENTRY(strokeColor) |
| 74 | JS_STATIC_PROP_ENTRY(style) |
| 75 | JS_STATIC_PROP_ENTRY(submitName) |
| 76 | JS_STATIC_PROP_ENTRY(textColor) |
| 77 | JS_STATIC_PROP_ENTRY(textFont) |
| 78 | JS_STATIC_PROP_ENTRY(textSize) |
| 79 | JS_STATIC_PROP_ENTRY(type) |
| 80 | JS_STATIC_PROP_ENTRY(userName) |
| 81 | JS_STATIC_PROP_ENTRY(value) |
| 82 | JS_STATIC_PROP_ENTRY(valueAsString) |
| 83 | JS_STATIC_PROP_ENTRY(source) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 84 | END_JS_STATIC_PROP() |
| 85 | |
| 86 | BEGIN_JS_STATIC_METHOD(CJS_Field) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | JS_STATIC_METHOD_ENTRY(browseForFileToSubmit) |
| 88 | JS_STATIC_METHOD_ENTRY(buttonGetCaption) |
| 89 | JS_STATIC_METHOD_ENTRY(buttonGetIcon) |
| 90 | JS_STATIC_METHOD_ENTRY(buttonImportIcon) |
| 91 | JS_STATIC_METHOD_ENTRY(buttonSetCaption) |
| 92 | JS_STATIC_METHOD_ENTRY(buttonSetIcon) |
| 93 | JS_STATIC_METHOD_ENTRY(checkThisBox) |
| 94 | JS_STATIC_METHOD_ENTRY(clearItems) |
| 95 | JS_STATIC_METHOD_ENTRY(defaultIsChecked) |
| 96 | JS_STATIC_METHOD_ENTRY(deleteItemAt) |
| 97 | JS_STATIC_METHOD_ENTRY(getArray) |
| 98 | JS_STATIC_METHOD_ENTRY(getItemAt) |
| 99 | JS_STATIC_METHOD_ENTRY(getLock) |
| 100 | JS_STATIC_METHOD_ENTRY(insertItemAt) |
| 101 | JS_STATIC_METHOD_ENTRY(isBoxChecked) |
| 102 | JS_STATIC_METHOD_ENTRY(isDefaultChecked) |
| 103 | JS_STATIC_METHOD_ENTRY(setAction) |
| 104 | JS_STATIC_METHOD_ENTRY(setFocus) |
| 105 | JS_STATIC_METHOD_ENTRY(setItems) |
| 106 | JS_STATIC_METHOD_ENTRY(setLock) |
| 107 | JS_STATIC_METHOD_ENTRY(signatureGetModifications) |
| 108 | JS_STATIC_METHOD_ENTRY(signatureGetSeedValue) |
| 109 | JS_STATIC_METHOD_ENTRY(signatureInfo) |
| 110 | JS_STATIC_METHOD_ENTRY(signatureSetSeedValue) |
| 111 | JS_STATIC_METHOD_ENTRY(signatureSign) |
| 112 | JS_STATIC_METHOD_ENTRY(signatureValidate) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | END_JS_STATIC_METHOD() |
| 114 | |
| 115 | IMPLEMENT_JS_CLASS(CJS_Field, Field) |
| 116 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame^] | 117 | CJS_DelayData::CJS_DelayData(FIELD_PROP prop, |
| 118 | int idx, |
| 119 | const CFX_WideString& name) |
| 120 | : eProp(prop), nControlIndex(idx), sFieldName(name) {} |
| 121 | |
| 122 | CJS_DelayData::~CJS_DelayData() {} |
| 123 | |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 124 | void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { |
| 125 | CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
| 126 | Field* pField = static_cast<Field*>(GetEmbedObject()); |
| 127 | pField->SetIsolate(pRuntime->GetIsolate()); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 128 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | Field::Field(CJS_Object* pJSObject) |
| 131 | : CJS_EmbedObj(pJSObject), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 132 | m_pJSDoc(nullptr), |
| 133 | m_pDocument(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | m_nFormControlIndex(-1), |
| 135 | m_bCanSet(FALSE), |
| 136 | m_bDelay(FALSE), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 137 | m_isolate(nullptr) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | |
| 139 | Field::~Field() {} |
| 140 | |
| 141 | // note: iControlNo = -1, means not a widget. |
| 142 | void Field::ParseFieldName(const std::wstring& strFieldNameParsed, |
| 143 | std::wstring& strFieldName, |
| 144 | int& iControlNo) { |
| 145 | int iStart = strFieldNameParsed.find_last_of(L'.'); |
| 146 | if (iStart == -1) { |
| 147 | strFieldName = strFieldNameParsed; |
| 148 | iControlNo = -1; |
| 149 | return; |
| 150 | } |
| 151 | std::wstring suffixal = strFieldNameParsed.substr(iStart + 1); |
| 152 | iControlNo = FXSYS_wtoi(suffixal.c_str()); |
| 153 | if (iControlNo == 0) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 154 | int iSpaceStart; |
| 155 | while ((iSpaceStart = suffixal.find_last_of(L" ")) != -1) { |
| 156 | suffixal.erase(iSpaceStart, 1); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | if (suffixal.compare(L"0") != 0) { |
| 160 | strFieldName = strFieldNameParsed; |
| 161 | iControlNo = -1; |
| 162 | return; |
| 163 | } |
| 164 | } |
| 165 | strFieldName = strFieldNameParsed.substr(0, iStart); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | FX_BOOL Field::AttachField(Document* pDocument, |
| 169 | const CFX_WideString& csFieldName) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | m_pJSDoc = pDocument; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | m_pDocument = pDocument->GetReaderDoc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) || |
| 173 | m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 174 | m_pDocument->GetPermissions(FPDFPERM_MODIFY); |
| 175 | |
| 176 | CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | CFX_WideString swFieldNameTemp = csFieldName; |
| 179 | swFieldNameTemp.Replace(L"..", L"."); |
| 180 | |
| 181 | if (pInterForm->CountFields(swFieldNameTemp) <= 0) { |
| 182 | std::wstring strFieldName; |
| 183 | int iControlNo = -1; |
| 184 | ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); |
| 185 | if (iControlNo == -1) |
| 186 | return FALSE; |
| 187 | |
| 188 | m_FieldName = strFieldName.c_str(); |
| 189 | m_nFormControlIndex = iControlNo; |
| 190 | return TRUE; |
| 191 | } |
| 192 | |
| 193 | m_FieldName = swFieldNameTemp; |
| 194 | m_nFormControlIndex = -1; |
| 195 | |
| 196 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 199 | std::vector<CPDF_FormField*> Field::GetFormFields( |
| 200 | CPDFSDK_Document* pDocument, |
| 201 | const CFX_WideString& csFieldName) { |
| 202 | std::vector<CPDF_FormField*> fields; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 203 | CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 205 | for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 207 | fields.push_back(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 209 | return fields; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 212 | std::vector<CPDF_FormField*> Field::GetFormFields( |
| 213 | const CFX_WideString& csFieldName) const { |
| 214 | return Field::GetFormFields(m_pDocument, csFieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void Field::UpdateFormField(CPDFSDK_Document* pDocument, |
| 218 | CPDF_FormField* pFormField, |
| 219 | FX_BOOL bChangeMark, |
| 220 | FX_BOOL bResetAP, |
| 221 | FX_BOOL bRefresh) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 222 | std::vector<CPDFSDK_Widget*> widgets; |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 223 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 224 | pInterForm->GetWidgets(pFormField, &widgets); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | |
| 226 | if (bResetAP) { |
| 227 | int nFieldType = pFormField->GetFieldType(); |
| 228 | if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 229 | for (CPDFSDK_Widget* pWidget : widgets) { |
| 230 | FX_BOOL bFormatted = FALSE; |
| 231 | CFX_WideString sValue = pWidget->OnFormat(bFormatted); |
| 232 | pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 233 | } |
| 234 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 235 | for (CPDFSDK_Widget* pWidget : widgets) { |
| 236 | pWidget->ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if (bRefresh) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 242 | for (CPDFSDK_Widget* pWidget : widgets) { |
| 243 | CPDFSDK_Document* pDoc = pWidget->GetInterForm()->GetDocument(); |
| 244 | pDoc->UpdateAllViews(nullptr, pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
| 248 | if (bChangeMark) |
| 249 | pDocument->SetChangeMark(); |
| 250 | } |
| 251 | |
| 252 | void Field::UpdateFormControl(CPDFSDK_Document* pDocument, |
| 253 | CPDF_FormControl* pFormControl, |
| 254 | FX_BOOL bChangeMark, |
| 255 | FX_BOOL bResetAP, |
| 256 | FX_BOOL bRefresh) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 257 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 258 | |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 259 | CPDFSDK_InterForm* pForm = pDocument->GetInterForm(); |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 260 | CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | |
| 262 | if (pWidget) { |
| 263 | if (bResetAP) { |
| 264 | int nFieldType = pWidget->GetFieldType(); |
| 265 | if (nFieldType == FIELDTYPE_COMBOBOX || |
| 266 | nFieldType == FIELDTYPE_TEXTFIELD) { |
| 267 | FX_BOOL bFormated = FALSE; |
| 268 | CFX_WideString sValue = pWidget->OnFormat(bFormated); |
| 269 | if (bFormated) |
| 270 | pWidget->ResetAppearance(sValue.c_str(), FALSE); |
| 271 | else |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 272 | pWidget->ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | } else { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 274 | pWidget->ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | if (bRefresh) { |
| 279 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 280 | CPDFSDK_Document* pDoc = pInterForm->GetDocument(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 281 | pDoc->UpdateAllViews(nullptr, pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | if (bChangeMark) |
| 286 | pDocument->SetChangeMark(); |
| 287 | } |
| 288 | |
| 289 | CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, |
| 290 | CPDF_FormControl* pFormControl) { |
Jun Fang | 14b20db | 2015-12-01 12:35:24 +0800 | [diff] [blame] | 291 | CPDFSDK_InterForm* pInterForm = |
| 292 | static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm()); |
| 293 | return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, |
| 297 | CFX_WideString csOptLabel) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { |
| 299 | if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) |
| 300 | return TRUE; |
| 301 | } |
| 302 | |
| 303 | return FALSE; |
| 304 | } |
| 305 | |
| 306 | CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { |
| 307 | if (!pFormField->CountControls() || |
| 308 | m_nFormControlIndex >= pFormField->CountControls()) |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 309 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | |
| 311 | if (m_nFormControlIndex < 0) |
| 312 | return pFormField->GetControl(0); |
| 313 | |
| 314 | return pFormField->GetControl(m_nFormControlIndex); |
| 315 | } |
| 316 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 317 | FX_BOOL Field::alignment(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 318 | CJS_PropValue& vp, |
| 319 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 320 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 321 | |
| 322 | if (vp.IsSetting()) { |
| 323 | if (!m_bCanSet) |
| 324 | return FALSE; |
| 325 | |
| 326 | CFX_ByteString alignStr; |
| 327 | vp >> alignStr; |
| 328 | |
| 329 | if (m_bDelay) { |
| 330 | AddDelay_String(FP_ALIGNMENT, alignStr); |
| 331 | } else { |
| 332 | Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 333 | alignStr); |
| 334 | } |
| 335 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 336 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 337 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | return FALSE; |
| 339 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 340 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 341 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 342 | return FALSE; |
| 343 | |
| 344 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 345 | if (!pFormControl) |
| 346 | return FALSE; |
| 347 | |
| 348 | switch (pFormControl->GetControlAlignment()) { |
| 349 | case 1: |
| 350 | vp << L"center"; |
| 351 | break; |
| 352 | case 0: |
| 353 | vp << L"left"; |
| 354 | break; |
| 355 | case 2: |
| 356 | vp << L"right"; |
| 357 | break; |
| 358 | default: |
| 359 | vp << L""; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return TRUE; |
| 364 | } |
| 365 | |
| 366 | void Field::SetAlignment(CPDFSDK_Document* pDocument, |
| 367 | const CFX_WideString& swFieldName, |
| 368 | int nControlIndex, |
| 369 | const CFX_ByteString& string) { |
| 370 | // Not supported. |
| 371 | } |
| 372 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 373 | FX_BOOL Field::borderStyle(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | CJS_PropValue& vp, |
| 375 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 376 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | |
| 378 | if (vp.IsSetting()) { |
| 379 | if (!m_bCanSet) |
| 380 | return FALSE; |
| 381 | |
| 382 | CFX_ByteString strType = ""; |
| 383 | vp >> strType; |
| 384 | |
| 385 | if (m_bDelay) { |
| 386 | AddDelay_String(FP_BORDERSTYLE, strType); |
| 387 | } else { |
| 388 | Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 389 | strType); |
| 390 | } |
| 391 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 392 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 393 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 394 | return FALSE; |
| 395 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 396 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 397 | if (!pFormField) |
| 398 | return FALSE; |
| 399 | |
| 400 | CPDFSDK_Widget* pWidget = |
| 401 | GetWidget(m_pDocument, GetSmartFieldControl(pFormField)); |
| 402 | if (!pWidget) |
| 403 | return FALSE; |
| 404 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 405 | switch (pWidget->GetBorderStyle()) { |
| 406 | case BorderStyle::SOLID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | vp << L"solid"; |
| 408 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 409 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 410 | vp << L"dashed"; |
| 411 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 412 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 413 | vp << L"beveled"; |
| 414 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 415 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 416 | vp << L"inset"; |
| 417 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 418 | case BorderStyle::UNDERLINE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 419 | vp << L"underline"; |
| 420 | break; |
| 421 | default: |
| 422 | vp << L""; |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | return TRUE; |
| 428 | } |
| 429 | |
| 430 | void Field::SetBorderStyle(CPDFSDK_Document* pDocument, |
| 431 | const CFX_WideString& swFieldName, |
| 432 | int nControlIndex, |
| 433 | const CFX_ByteString& string) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 434 | ASSERT(pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 435 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 436 | BorderStyle nBorderStyle = BorderStyle::SOLID; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 437 | if (string == "solid") |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 438 | nBorderStyle = BorderStyle::SOLID; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 439 | else if (string == "beveled") |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 440 | nBorderStyle = BorderStyle::BEVELED; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | else if (string == "dashed") |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 442 | nBorderStyle = BorderStyle::DASH; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 443 | else if (string == "inset") |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 444 | nBorderStyle = BorderStyle::INSET; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 445 | else if (string == "underline") |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 446 | nBorderStyle = BorderStyle::UNDERLINE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 447 | else |
| 448 | return; |
| 449 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 450 | std::vector<CPDF_FormField*> FieldArray = |
| 451 | GetFormFields(pDocument, swFieldName); |
| 452 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | if (nControlIndex < 0) { |
| 454 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 455 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | if (CPDFSDK_Widget* pWidget = |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 457 | GetWidget(pDocument, pFormField->GetControl(i))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 458 | if (pWidget->GetBorderStyle() != nBorderStyle) { |
| 459 | pWidget->SetBorderStyle(nBorderStyle); |
| 460 | bSet = TRUE; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | if (bSet) |
| 465 | UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); |
| 466 | } else { |
| 467 | if (nControlIndex >= pFormField->CountControls()) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 468 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | if (CPDF_FormControl* pFormControl = |
| 470 | pFormField->GetControl(nControlIndex)) { |
| 471 | if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl)) { |
| 472 | if (pWidget->GetBorderStyle() != nBorderStyle) { |
| 473 | pWidget->SetBorderStyle(nBorderStyle); |
| 474 | UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE); |
| 475 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 476 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 478 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 479 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 482 | FX_BOOL Field::buttonAlignX(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 483 | CJS_PropValue& vp, |
| 484 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 485 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 486 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | if (vp.IsSetting()) { |
| 488 | if (!m_bCanSet) |
| 489 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 490 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 491 | int nVP; |
| 492 | vp >> nVP; |
| 493 | |
| 494 | if (m_bDelay) { |
| 495 | AddDelay_Int(FP_BUTTONALIGNX, nVP); |
| 496 | } else { |
| 497 | Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 498 | nVP); |
| 499 | } |
| 500 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 501 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 502 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | return FALSE; |
| 504 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 505 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 506 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 507 | return FALSE; |
| 508 | |
| 509 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 510 | if (!pFormControl) |
| 511 | return FALSE; |
| 512 | |
| 513 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
| 514 | |
| 515 | FX_FLOAT fLeft, fBottom; |
| 516 | IconFit.GetIconPosition(fLeft, fBottom); |
| 517 | |
| 518 | vp << (int32_t)fLeft; |
| 519 | } |
| 520 | |
| 521 | return TRUE; |
| 522 | } |
| 523 | |
| 524 | void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, |
| 525 | const CFX_WideString& swFieldName, |
| 526 | int nControlIndex, |
| 527 | int number) { |
| 528 | // Not supported. |
| 529 | } |
| 530 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 531 | FX_BOOL Field::buttonAlignY(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 532 | CJS_PropValue& vp, |
| 533 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 534 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | |
| 536 | if (vp.IsSetting()) { |
| 537 | if (!m_bCanSet) |
| 538 | return FALSE; |
| 539 | |
| 540 | int nVP; |
| 541 | vp >> nVP; |
| 542 | |
| 543 | if (m_bDelay) { |
| 544 | AddDelay_Int(FP_BUTTONALIGNY, nVP); |
| 545 | } else { |
| 546 | Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 547 | nVP); |
| 548 | } |
| 549 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 550 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 551 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | return FALSE; |
| 553 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 554 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 556 | return FALSE; |
| 557 | |
| 558 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 559 | if (!pFormControl) |
| 560 | return FALSE; |
| 561 | |
| 562 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
| 563 | |
| 564 | FX_FLOAT fLeft, fBottom; |
| 565 | IconFit.GetIconPosition(fLeft, fBottom); |
| 566 | |
| 567 | vp << (int32_t)fBottom; |
| 568 | } |
| 569 | |
| 570 | return TRUE; |
| 571 | } |
| 572 | |
| 573 | void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, |
| 574 | const CFX_WideString& swFieldName, |
| 575 | int nControlIndex, |
| 576 | int number) { |
| 577 | // Not supported. |
| 578 | } |
| 579 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 580 | FX_BOOL Field::buttonFitBounds(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | CJS_PropValue& vp, |
| 582 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 583 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | |
| 585 | if (vp.IsSetting()) { |
| 586 | if (!m_bCanSet) |
| 587 | return FALSE; |
| 588 | |
| 589 | bool bVP; |
| 590 | vp >> bVP; |
| 591 | |
| 592 | if (m_bDelay) { |
| 593 | AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP); |
| 594 | } else { |
| 595 | Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 596 | bVP); |
| 597 | } |
| 598 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 599 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 600 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | return FALSE; |
| 602 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 603 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 605 | return FALSE; |
| 606 | |
| 607 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 608 | if (!pFormControl) |
| 609 | return FALSE; |
| 610 | |
thestig | ded3634 | 2016-05-23 17:54:02 -0700 | [diff] [blame] | 611 | vp << pFormControl->GetIconFit().GetFittingBounds(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | return TRUE; |
| 615 | } |
| 616 | |
| 617 | void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, |
| 618 | const CFX_WideString& swFieldName, |
| 619 | int nControlIndex, |
| 620 | bool b) { |
| 621 | // Not supported. |
| 622 | } |
| 623 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 624 | FX_BOOL Field::buttonPosition(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 625 | CJS_PropValue& vp, |
| 626 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 627 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | |
| 629 | if (vp.IsSetting()) { |
| 630 | if (!m_bCanSet) |
| 631 | return FALSE; |
| 632 | |
| 633 | int nVP; |
| 634 | vp >> nVP; |
| 635 | |
| 636 | if (m_bDelay) { |
| 637 | AddDelay_Int(FP_BUTTONPOSITION, nVP); |
| 638 | } else { |
| 639 | Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 640 | nVP); |
| 641 | } |
| 642 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 643 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 644 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | return FALSE; |
| 646 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 647 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 648 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 649 | return FALSE; |
| 650 | |
| 651 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 652 | if (!pFormControl) |
| 653 | return FALSE; |
| 654 | |
| 655 | vp << pFormControl->GetTextPosition(); |
| 656 | } |
| 657 | return TRUE; |
| 658 | } |
| 659 | |
| 660 | void Field::SetButtonPosition(CPDFSDK_Document* pDocument, |
| 661 | const CFX_WideString& swFieldName, |
| 662 | int nControlIndex, |
| 663 | int number) { |
| 664 | // Not supported. |
| 665 | } |
| 666 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 667 | FX_BOOL Field::buttonScaleHow(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 668 | CJS_PropValue& vp, |
| 669 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 670 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 671 | |
| 672 | if (vp.IsSetting()) { |
| 673 | if (!m_bCanSet) |
| 674 | return FALSE; |
| 675 | |
| 676 | int nVP; |
| 677 | vp >> nVP; |
| 678 | |
| 679 | if (m_bDelay) { |
| 680 | AddDelay_Int(FP_BUTTONSCALEHOW, nVP); |
| 681 | } else { |
| 682 | Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 683 | nVP); |
| 684 | } |
| 685 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 686 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 687 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | return FALSE; |
| 689 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 690 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 692 | return FALSE; |
| 693 | |
| 694 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 695 | if (!pFormControl) |
| 696 | return FALSE; |
| 697 | |
| 698 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
| 699 | if (IconFit.IsProportionalScale()) |
| 700 | vp << (int32_t)0; |
| 701 | else |
| 702 | vp << (int32_t)1; |
| 703 | } |
| 704 | |
| 705 | return TRUE; |
| 706 | } |
| 707 | |
| 708 | void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, |
| 709 | const CFX_WideString& swFieldName, |
| 710 | int nControlIndex, |
| 711 | int number) { |
| 712 | // Not supported. |
| 713 | } |
| 714 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 715 | FX_BOOL Field::buttonScaleWhen(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 716 | CJS_PropValue& vp, |
| 717 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 718 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 719 | |
| 720 | if (vp.IsSetting()) { |
| 721 | if (!m_bCanSet) |
| 722 | return FALSE; |
| 723 | |
| 724 | int nVP; |
| 725 | vp >> nVP; |
| 726 | |
| 727 | if (m_bDelay) { |
| 728 | AddDelay_Int(FP_BUTTONSCALEWHEN, nVP); |
| 729 | } else { |
| 730 | Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 731 | nVP); |
| 732 | } |
| 733 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 734 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 735 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 736 | return FALSE; |
| 737 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 738 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 739 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 740 | return FALSE; |
| 741 | |
| 742 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 743 | if (!pFormControl) |
| 744 | return FALSE; |
| 745 | |
| 746 | CPDF_IconFit IconFit = pFormControl->GetIconFit(); |
| 747 | int ScaleM = IconFit.GetScaleMethod(); |
| 748 | switch (ScaleM) { |
| 749 | case CPDF_IconFit::Always: |
| 750 | vp << (int32_t)CPDF_IconFit::Always; |
| 751 | break; |
| 752 | case CPDF_IconFit::Bigger: |
| 753 | vp << (int32_t)CPDF_IconFit::Bigger; |
| 754 | break; |
| 755 | case CPDF_IconFit::Never: |
| 756 | vp << (int32_t)CPDF_IconFit::Never; |
| 757 | break; |
| 758 | case CPDF_IconFit::Smaller: |
| 759 | vp << (int32_t)CPDF_IconFit::Smaller; |
| 760 | break; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | return TRUE; |
| 765 | } |
| 766 | |
| 767 | void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, |
| 768 | const CFX_WideString& swFieldName, |
| 769 | int nControlIndex, |
| 770 | int number) { |
| 771 | // Not supported. |
| 772 | } |
| 773 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 774 | FX_BOOL Field::calcOrderIndex(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 775 | CJS_PropValue& vp, |
| 776 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 777 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | |
| 779 | if (vp.IsSetting()) { |
| 780 | if (!m_bCanSet) |
| 781 | return FALSE; |
| 782 | |
| 783 | int nVP; |
| 784 | vp >> nVP; |
| 785 | |
| 786 | if (m_bDelay) { |
| 787 | AddDelay_Int(FP_CALCORDERINDEX, nVP); |
| 788 | } else { |
| 789 | Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 790 | nVP); |
| 791 | } |
| 792 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 793 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 794 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 795 | return FALSE; |
| 796 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 797 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 799 | pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 801 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 802 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 803 | CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 804 | CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 805 | vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); |
| 806 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 807 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 808 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 809 | } |
| 810 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 811 | void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, |
| 812 | const CFX_WideString& swFieldName, |
| 813 | int nControlIndex, |
| 814 | int number) { |
| 815 | // Not supported. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 818 | FX_BOOL Field::charLimit(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 819 | CJS_PropValue& vp, |
| 820 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 821 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 822 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | if (vp.IsSetting()) { |
| 824 | if (!m_bCanSet) |
| 825 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 826 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 827 | int nVP; |
| 828 | vp >> nVP; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 829 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | if (m_bDelay) { |
| 831 | AddDelay_Int(FP_CHARLIMIT, nVP); |
| 832 | } else { |
| 833 | Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 834 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 835 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 836 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 837 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 838 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 839 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 840 | CPDF_FormField* pFormField = FieldArray[0]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 841 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 843 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 844 | vp << (int32_t)pFormField->GetMaxLen(); |
| 845 | } |
| 846 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 849 | void Field::SetCharLimit(CPDFSDK_Document* pDocument, |
| 850 | const CFX_WideString& swFieldName, |
| 851 | int nControlIndex, |
| 852 | int number) { |
| 853 | // Not supported. |
| 854 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 855 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 856 | FX_BOOL Field::comb(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | CJS_PropValue& vp, |
| 858 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 859 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 860 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 861 | if (vp.IsSetting()) { |
| 862 | if (!m_bCanSet) |
| 863 | return FALSE; |
| 864 | |
| 865 | bool bVP; |
| 866 | vp >> bVP; |
| 867 | |
| 868 | if (m_bDelay) { |
| 869 | AddDelay_Bool(FP_COMB, bVP); |
| 870 | } else { |
| 871 | Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 872 | } |
| 873 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 874 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 875 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 877 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 878 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 879 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 880 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 881 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 882 | if (pFormField->GetFieldFlags() & FIELDFLAG_COMB) |
| 883 | vp << true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 884 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 885 | vp << false; |
| 886 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 887 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 889 | } |
| 890 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 891 | void Field::SetComb(CPDFSDK_Document* pDocument, |
| 892 | const CFX_WideString& swFieldName, |
| 893 | int nControlIndex, |
| 894 | bool b) { |
| 895 | // Not supported. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 896 | } |
| 897 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 898 | FX_BOOL Field::commitOnSelChange(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | CJS_PropValue& vp, |
| 900 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 901 | ASSERT(m_pDocument); |
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 | if (vp.IsSetting()) { |
| 904 | if (!m_bCanSet) |
| 905 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 906 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 907 | bool bVP; |
| 908 | vp >> bVP; |
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 | if (m_bDelay) { |
| 911 | AddDelay_Bool(FP_COMMITONSELCHANGE, bVP); |
| 912 | } else { |
| 913 | Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 914 | bVP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 915 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 917 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 918 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 919 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 920 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 921 | CPDF_FormField* pFormField = FieldArray[0]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 922 | if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 923 | pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 924 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 925 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 926 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 927 | if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE) |
| 928 | vp << true; |
| 929 | else |
| 930 | vp << false; |
| 931 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 932 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 933 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 936 | void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, |
| 937 | const CFX_WideString& swFieldName, |
| 938 | int nControlIndex, |
| 939 | bool b) { |
| 940 | // Not supported. |
| 941 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 942 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 943 | FX_BOOL Field::currentValueIndices(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 944 | CJS_PropValue& vp, |
| 945 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 946 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 947 | |
| 948 | if (vp.IsSetting()) { |
| 949 | if (!m_bCanSet) |
| 950 | return FALSE; |
| 951 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 952 | std::vector<uint32_t> array; |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 953 | if (vp.GetType() == CJS_Value::VT_number) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 954 | int iSelecting = 0; |
| 955 | vp >> iSelecting; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 956 | array.push_back(iSelecting); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | } else if (vp.IsArrayObject()) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 958 | CJS_Array SelArray(pRuntime); |
| 959 | CJS_Value SelValue(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 960 | int iSelecting; |
| 961 | vp >> SelArray; |
| 962 | for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { |
| 963 | SelArray.GetElement(i, SelValue); |
| 964 | iSelecting = SelValue.ToInt(); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 965 | array.push_back(iSelecting); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | |
| 969 | if (m_bDelay) { |
| 970 | AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); |
| 971 | } else { |
| 972 | Field::SetCurrentValueIndices(m_pDocument, m_FieldName, |
| 973 | m_nFormControlIndex, array); |
| 974 | } |
| 975 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 976 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 977 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 979 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 980 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 981 | if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 982 | pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 983 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 984 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 985 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 986 | if (pFormField->CountSelectedItems() == 1) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 987 | vp << pFormField->GetSelectedIndex(0); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 988 | } else if (pFormField->CountSelectedItems() > 1) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 989 | CJS_Array SelArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 990 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 991 | SelArray.SetElement( |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 992 | i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | } |
| 994 | vp << SelArray; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 995 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 996 | vp << -1; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 997 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1003 | void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, |
| 1004 | const CFX_WideString& swFieldName, |
| 1005 | int nControlIndex, |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 1006 | const std::vector<uint32_t>& array) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1007 | ASSERT(pDocument); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1008 | std::vector<CPDF_FormField*> FieldArray = |
| 1009 | GetFormFields(pDocument, swFieldName); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 1010 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1011 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1012 | int nFieldType = pFormField->GetFieldType(); |
| 1013 | if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1014 | uint32_t dwFieldFlags = pFormField->GetFieldFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | pFormField->ClearSelection(TRUE); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 1016 | for (size_t i = 0; i < array.size(); ++i) { |
| 1017 | if (i != 0 && !(dwFieldFlags & (1 << 21))) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | break; |
Wei Li | 05d53f0 | 2016-03-29 16:42:53 -0700 | [diff] [blame] | 1019 | if (array[i] < static_cast<uint32_t>(pFormField->CountOptions()) && |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 1020 | !pFormField->IsItemSelected(array[i])) { |
| 1021 | pFormField->SetItemSelection(array[i], TRUE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1022 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1023 | } |
| 1024 | UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1025 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1026 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1029 | FX_BOOL Field::defaultStyle(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1030 | CJS_PropValue& vp, |
| 1031 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1032 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1035 | void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, |
| 1036 | const CFX_WideString& swFieldName, |
| 1037 | int nControlIndex) { |
| 1038 | // Not supported. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1041 | FX_BOOL Field::defaultValue(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1042 | CJS_PropValue& vp, |
| 1043 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1044 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1045 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1046 | if (vp.IsSetting()) { |
| 1047 | if (!m_bCanSet) |
| 1048 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1049 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | CFX_WideString WideStr; |
| 1051 | vp >> WideStr; |
| 1052 | |
| 1053 | if (m_bDelay) { |
| 1054 | AddDelay_WideString(FP_DEFAULTVALUE, WideStr); |
| 1055 | } else { |
| 1056 | Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 1057 | WideStr); |
| 1058 | } |
| 1059 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1060 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1061 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1062 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1063 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1064 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1065 | if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON || |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1066 | pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1067 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1068 | } |
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 | vp << pFormField->GetDefaultValue(); |
| 1071 | } |
| 1072 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1075 | void Field::SetDefaultValue(CPDFSDK_Document* pDocument, |
| 1076 | const CFX_WideString& swFieldName, |
| 1077 | int nControlIndex, |
| 1078 | const CFX_WideString& string) { |
| 1079 | // Not supported. |
| 1080 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1081 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1082 | FX_BOOL Field::doNotScroll(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1083 | CJS_PropValue& vp, |
| 1084 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1085 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1086 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1087 | if (vp.IsSetting()) { |
| 1088 | if (!m_bCanSet) |
| 1089 | return FALSE; |
| 1090 | |
| 1091 | bool bVP; |
| 1092 | vp >> bVP; |
| 1093 | |
| 1094 | if (m_bDelay) { |
| 1095 | AddDelay_Bool(FP_DONOTSCROLL, bVP); |
| 1096 | } else { |
| 1097 | Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 1098 | } |
| 1099 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1100 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1101 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1102 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1103 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1104 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1105 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 1106 | return FALSE; |
| 1107 | |
| 1108 | if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL) |
| 1109 | vp << true; |
| 1110 | else |
| 1111 | vp << false; |
| 1112 | } |
| 1113 | |
| 1114 | return TRUE; |
| 1115 | } |
| 1116 | |
| 1117 | void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, |
| 1118 | const CFX_WideString& swFieldName, |
| 1119 | int nControlIndex, |
| 1120 | bool b) { |
| 1121 | // Not supported. |
| 1122 | } |
| 1123 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1124 | FX_BOOL Field::doNotSpellCheck(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1125 | CJS_PropValue& vp, |
| 1126 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1127 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1128 | |
| 1129 | if (vp.IsSetting()) { |
| 1130 | if (!m_bCanSet) |
| 1131 | return FALSE; |
| 1132 | |
| 1133 | bool bVP; |
| 1134 | vp >> bVP; |
| 1135 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1136 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1137 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1138 | return FALSE; |
| 1139 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1140 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1141 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1142 | pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1143 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1144 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1145 | |
| 1146 | if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK) |
| 1147 | vp << true; |
| 1148 | else |
| 1149 | vp << false; |
| 1150 | } |
| 1151 | |
| 1152 | return TRUE; |
| 1153 | } |
| 1154 | |
| 1155 | void Field::SetDelay(FX_BOOL bDelay) { |
| 1156 | m_bDelay = bDelay; |
| 1157 | |
| 1158 | if (!m_bDelay) { |
| 1159 | if (m_pJSDoc) |
| 1160 | m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1164 | FX_BOOL Field::delay(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1165 | CJS_PropValue& vp, |
| 1166 | CFX_WideString& sError) { |
| 1167 | if (vp.IsSetting()) { |
| 1168 | if (!m_bCanSet) |
| 1169 | return FALSE; |
| 1170 | |
| 1171 | bool bVP; |
| 1172 | vp >> bVP; |
| 1173 | |
| 1174 | SetDelay(bVP); |
| 1175 | } else { |
| 1176 | vp << m_bDelay; |
| 1177 | } |
| 1178 | return TRUE; |
| 1179 | } |
| 1180 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1181 | FX_BOOL Field::display(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1182 | CJS_PropValue& vp, |
| 1183 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | if (vp.IsSetting()) { |
| 1185 | if (!m_bCanSet) |
| 1186 | return FALSE; |
| 1187 | |
| 1188 | int nVP; |
| 1189 | vp >> nVP; |
| 1190 | |
| 1191 | if (m_bDelay) { |
| 1192 | AddDelay_Int(FP_DISPLAY, nVP); |
| 1193 | } else { |
| 1194 | Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); |
| 1195 | } |
| 1196 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1197 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1198 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1199 | return FALSE; |
| 1200 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1201 | CPDF_FormField* pFormField = FieldArray[0]; |
| 1202 | ASSERT(pFormField); |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1203 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1204 | CPDFSDK_Widget* pWidget = |
| 1205 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1206 | if (!pWidget) |
| 1207 | return FALSE; |
| 1208 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1209 | uint32_t dwFlag = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1210 | |
| 1211 | if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) { |
| 1212 | vp << (int32_t)1; |
| 1213 | } else { |
| 1214 | if (ANNOTFLAG_PRINT & dwFlag) { |
| 1215 | if (ANNOTFLAG_NOVIEW & dwFlag) { |
| 1216 | vp << (int32_t)3; |
| 1217 | } else { |
| 1218 | vp << (int32_t)0; |
| 1219 | } |
| 1220 | } else { |
| 1221 | vp << (int32_t)2; |
| 1222 | } |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | return TRUE; |
| 1227 | } |
| 1228 | |
| 1229 | void Field::SetDisplay(CPDFSDK_Document* pDocument, |
| 1230 | const CFX_WideString& swFieldName, |
| 1231 | int nControlIndex, |
| 1232 | int number) { |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1233 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1234 | std::vector<CPDF_FormField*> FieldArray = |
| 1235 | GetFormFields(pDocument, swFieldName); |
| 1236 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1237 | if (nControlIndex < 0) { |
| 1238 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1239 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 1240 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1241 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1242 | |
| 1243 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1244 | uint32_t dwFlag = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1245 | switch (number) { |
| 1246 | case 0: |
| 1247 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1248 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1249 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1250 | dwFlag |= ANNOTFLAG_PRINT; |
| 1251 | break; |
| 1252 | case 1: |
| 1253 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1254 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1255 | dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 1256 | break; |
| 1257 | case 2: |
| 1258 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1259 | dwFlag &= (~ANNOTFLAG_PRINT); |
| 1260 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1261 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1262 | break; |
| 1263 | case 3: |
| 1264 | dwFlag |= ANNOTFLAG_NOVIEW; |
| 1265 | dwFlag |= ANNOTFLAG_PRINT; |
| 1266 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1267 | break; |
| 1268 | } |
| 1269 | |
| 1270 | if (dwFlag != pWidget->GetFlags()) { |
| 1271 | pWidget->SetFlags(dwFlag); |
| 1272 | bSet = TRUE; |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | if (bSet) |
| 1278 | UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
| 1279 | } else { |
| 1280 | if (nControlIndex >= pFormField->CountControls()) |
| 1281 | return; |
| 1282 | if (CPDF_FormControl* pFormControl = |
| 1283 | pFormField->GetControl(nControlIndex)) { |
| 1284 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1285 | uint32_t dwFlag = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1286 | switch (number) { |
| 1287 | case 0: |
| 1288 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1289 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1290 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1291 | dwFlag |= ANNOTFLAG_PRINT; |
| 1292 | break; |
| 1293 | case 1: |
| 1294 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1295 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1296 | dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 1297 | break; |
| 1298 | case 2: |
| 1299 | dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 1300 | dwFlag &= (~ANNOTFLAG_PRINT); |
| 1301 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1302 | dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 1303 | break; |
| 1304 | case 3: |
| 1305 | dwFlag |= ANNOTFLAG_NOVIEW; |
| 1306 | dwFlag |= ANNOTFLAG_PRINT; |
| 1307 | dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 1308 | break; |
| 1309 | } |
| 1310 | if (dwFlag != pWidget->GetFlags()) { |
| 1311 | pWidget->SetFlags(dwFlag); |
| 1312 | UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); |
| 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | } |
| 1319 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1320 | FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1321 | if (!vp.IsGetting()) { |
| 1322 | return FALSE; |
| 1323 | } |
| 1324 | vp << m_pJSDoc->GetCJSDoc(); |
| 1325 | return TRUE; |
| 1326 | } |
| 1327 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1328 | FX_BOOL Field::editable(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1329 | CJS_PropValue& vp, |
| 1330 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1331 | if (vp.IsSetting()) { |
| 1332 | if (!m_bCanSet) |
| 1333 | return FALSE; |
| 1334 | |
| 1335 | bool bVP; |
| 1336 | vp >> bVP; |
| 1337 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1338 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1339 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1340 | return FALSE; |
| 1341 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1342 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1343 | if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) |
| 1344 | return FALSE; |
| 1345 | |
| 1346 | if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT) |
| 1347 | vp << true; |
| 1348 | else |
| 1349 | vp << false; |
| 1350 | } |
| 1351 | |
| 1352 | return TRUE; |
| 1353 | } |
| 1354 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1355 | FX_BOOL Field::exportValues(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1356 | CJS_PropValue& vp, |
| 1357 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1358 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1359 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1360 | return FALSE; |
| 1361 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1362 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1363 | if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1364 | pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1365 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1366 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1367 | |
| 1368 | if (vp.IsSetting()) { |
| 1369 | if (!m_bCanSet) |
| 1370 | return FALSE; |
| 1371 | |
| 1372 | if (!vp.IsArrayObject()) |
| 1373 | return FALSE; |
| 1374 | } else { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1375 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1376 | CJS_Array ExportValusArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1377 | if (m_nFormControlIndex < 0) { |
| 1378 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 1379 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 1380 | ExportValusArray.SetElement( |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1381 | i, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1382 | } |
| 1383 | } else { |
| 1384 | if (m_nFormControlIndex >= pFormField->CountControls()) |
| 1385 | return FALSE; |
| 1386 | |
| 1387 | CPDF_FormControl* pFormControl = |
| 1388 | pFormField->GetControl(m_nFormControlIndex); |
| 1389 | if (!pFormControl) |
| 1390 | return FALSE; |
| 1391 | |
| 1392 | ExportValusArray.SetElement( |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1393 | 0, CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1394 | } |
| 1395 | vp << ExportValusArray; |
| 1396 | } |
| 1397 | return TRUE; |
| 1398 | } |
| 1399 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1400 | FX_BOOL Field::fileSelect(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1401 | CJS_PropValue& vp, |
| 1402 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1403 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1404 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1405 | return FALSE; |
| 1406 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1407 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 1409 | return FALSE; |
| 1410 | |
| 1411 | if (vp.IsSetting()) { |
| 1412 | if (!m_bCanSet) |
| 1413 | return FALSE; |
| 1414 | |
| 1415 | bool bVP; |
| 1416 | vp >> bVP; |
| 1417 | } else { |
| 1418 | if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) |
| 1419 | vp << true; |
| 1420 | else |
| 1421 | vp << false; |
| 1422 | } |
| 1423 | return TRUE; |
| 1424 | } |
| 1425 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1426 | FX_BOOL Field::fillColor(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1427 | CJS_PropValue& vp, |
| 1428 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1429 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1430 | CJS_Array crArray(pRuntime); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1431 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1432 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1433 | return FALSE; |
| 1434 | |
| 1435 | if (vp.IsSetting()) { |
| 1436 | if (!m_bCanSet) |
| 1437 | return FALSE; |
| 1438 | |
| 1439 | if (!vp.IsArrayObject()) |
| 1440 | return FALSE; |
| 1441 | |
| 1442 | vp >> crArray; |
| 1443 | |
| 1444 | CPWL_Color color; |
| 1445 | color::ConvertArrayToPWLColor(crArray, color); |
| 1446 | if (m_bDelay) { |
| 1447 | AddDelay_Color(FP_FILLCOLOR, color); |
| 1448 | } else { |
| 1449 | Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); |
| 1450 | } |
| 1451 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1452 | CPDF_FormField* pFormField = FieldArray[0]; |
| 1453 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1454 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1455 | if (!pFormControl) |
| 1456 | return FALSE; |
| 1457 | |
| 1458 | int iColorType; |
| 1459 | pFormControl->GetBackgroundColor(iColorType); |
| 1460 | |
| 1461 | CPWL_Color color; |
| 1462 | if (iColorType == COLORTYPE_TRANSPARENT) { |
| 1463 | color = CPWL_Color(COLORTYPE_TRANSPARENT); |
| 1464 | } else if (iColorType == COLORTYPE_GRAY) { |
| 1465 | color = CPWL_Color(COLORTYPE_GRAY, |
| 1466 | pFormControl->GetOriginalBackgroundColor(0)); |
| 1467 | } else if (iColorType == COLORTYPE_RGB) { |
| 1468 | color = |
| 1469 | CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0), |
| 1470 | pFormControl->GetOriginalBackgroundColor(1), |
| 1471 | pFormControl->GetOriginalBackgroundColor(2)); |
| 1472 | } else if (iColorType == COLORTYPE_CMYK) { |
| 1473 | color = CPWL_Color(COLORTYPE_CMYK, |
| 1474 | pFormControl->GetOriginalBackgroundColor(0), |
| 1475 | pFormControl->GetOriginalBackgroundColor(1), |
| 1476 | pFormControl->GetOriginalBackgroundColor(2), |
| 1477 | pFormControl->GetOriginalBackgroundColor(3)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1478 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1479 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1480 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1481 | |
| 1482 | color::ConvertPWLColorToArray(color, crArray); |
| 1483 | vp << crArray; |
| 1484 | } |
| 1485 | |
| 1486 | return TRUE; |
| 1487 | } |
| 1488 | |
| 1489 | void Field::SetFillColor(CPDFSDK_Document* pDocument, |
| 1490 | const CFX_WideString& swFieldName, |
| 1491 | int nControlIndex, |
| 1492 | const CPWL_Color& color) { |
| 1493 | // Not supported. |
| 1494 | } |
| 1495 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1496 | FX_BOOL Field::hidden(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1497 | CJS_PropValue& vp, |
| 1498 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1499 | if (vp.IsSetting()) { |
| 1500 | if (!m_bCanSet) |
| 1501 | return FALSE; |
| 1502 | |
| 1503 | bool bVP; |
| 1504 | vp >> bVP; |
| 1505 | |
| 1506 | if (m_bDelay) { |
| 1507 | AddDelay_Bool(FP_HIDDEN, bVP); |
| 1508 | } else { |
| 1509 | Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 1510 | } |
| 1511 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1512 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1513 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1514 | return FALSE; |
| 1515 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1516 | CPDF_FormField* pFormField = FieldArray[0]; |
| 1517 | ASSERT(pFormField); |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1518 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1519 | CPDFSDK_Widget* pWidget = |
| 1520 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 1521 | if (!pWidget) |
| 1522 | return FALSE; |
| 1523 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1524 | uint32_t dwFlags = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1525 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1526 | if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1527 | vp << true; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1528 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1529 | vp << false; |
| 1530 | } |
| 1531 | |
| 1532 | return TRUE; |
| 1533 | } |
| 1534 | |
| 1535 | void Field::SetHidden(CPDFSDK_Document* pDocument, |
| 1536 | const CFX_WideString& swFieldName, |
| 1537 | int nControlIndex, |
| 1538 | bool b) { |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1539 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1540 | std::vector<CPDF_FormField*> FieldArray = |
| 1541 | GetFormFields(pDocument, swFieldName); |
| 1542 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1543 | if (nControlIndex < 0) { |
| 1544 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1545 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1546 | if (CPDFSDK_Widget* pWidget = |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1547 | pInterForm->GetWidget(pFormField->GetControl(i))) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1548 | uint32_t dwFlags = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1549 | |
| 1550 | if (b) { |
| 1551 | dwFlags &= (~ANNOTFLAG_INVISIBLE); |
| 1552 | dwFlags &= (~ANNOTFLAG_NOVIEW); |
| 1553 | dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 1554 | } else { |
| 1555 | dwFlags &= (~ANNOTFLAG_INVISIBLE); |
| 1556 | dwFlags &= (~ANNOTFLAG_HIDDEN); |
| 1557 | dwFlags &= (~ANNOTFLAG_NOVIEW); |
| 1558 | dwFlags |= ANNOTFLAG_PRINT; |
| 1559 | } |
| 1560 | |
| 1561 | if (dwFlags != pWidget->GetFlags()) { |
| 1562 | pWidget->SetFlags(dwFlags); |
| 1563 | bSet = TRUE; |
| 1564 | } |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | if (bSet) |
| 1569 | UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
| 1570 | } else { |
| 1571 | if (nControlIndex >= pFormField->CountControls()) |
| 1572 | return; |
| 1573 | if (CPDF_FormControl* pFormControl = |
| 1574 | pFormField->GetControl(nControlIndex)) { |
| 1575 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1576 | uint32_t dwFlags = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1577 | |
| 1578 | if (b) { |
| 1579 | dwFlags &= (~ANNOTFLAG_INVISIBLE); |
| 1580 | dwFlags &= (~ANNOTFLAG_NOVIEW); |
| 1581 | dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 1582 | } else { |
| 1583 | dwFlags &= (~ANNOTFLAG_INVISIBLE); |
| 1584 | dwFlags &= (~ANNOTFLAG_HIDDEN); |
| 1585 | dwFlags &= (~ANNOTFLAG_NOVIEW); |
| 1586 | dwFlags |= ANNOTFLAG_PRINT; |
| 1587 | } |
| 1588 | |
| 1589 | if (dwFlags != pWidget->GetFlags()) { |
| 1590 | pWidget->SetFlags(dwFlags); |
| 1591 | UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); |
| 1592 | } |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | } |
| 1598 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1599 | FX_BOOL Field::highlight(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1600 | CJS_PropValue& vp, |
| 1601 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1602 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (vp.IsSetting()) { |
| 1605 | if (!m_bCanSet) |
| 1606 | return FALSE; |
| 1607 | |
| 1608 | CFX_ByteString strMode; |
| 1609 | vp >> strMode; |
| 1610 | |
| 1611 | if (m_bDelay) { |
| 1612 | AddDelay_String(FP_HIGHLIGHT, strMode); |
| 1613 | } else { |
| 1614 | Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 1615 | strMode); |
| 1616 | } |
| 1617 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1618 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1619 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1620 | return FALSE; |
| 1621 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1622 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1623 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 1624 | return FALSE; |
| 1625 | |
| 1626 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1627 | if (!pFormControl) |
| 1628 | return FALSE; |
| 1629 | |
| 1630 | int eHM = pFormControl->GetHighlightingMode(); |
| 1631 | switch (eHM) { |
| 1632 | case CPDF_FormControl::None: |
| 1633 | vp << L"none"; |
| 1634 | break; |
| 1635 | case CPDF_FormControl::Push: |
| 1636 | vp << L"push"; |
| 1637 | break; |
| 1638 | case CPDF_FormControl::Invert: |
| 1639 | vp << L"invert"; |
| 1640 | break; |
| 1641 | case CPDF_FormControl::Outline: |
| 1642 | vp << L"outline"; |
| 1643 | break; |
| 1644 | case CPDF_FormControl::Toggle: |
| 1645 | vp << L"toggle"; |
| 1646 | break; |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | return TRUE; |
| 1651 | } |
| 1652 | |
| 1653 | void Field::SetHighlight(CPDFSDK_Document* pDocument, |
| 1654 | const CFX_WideString& swFieldName, |
| 1655 | int nControlIndex, |
| 1656 | const CFX_ByteString& string) { |
| 1657 | // Not supported. |
| 1658 | } |
| 1659 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1660 | FX_BOOL Field::lineWidth(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1661 | CJS_PropValue& vp, |
| 1662 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1663 | if (vp.IsSetting()) { |
| 1664 | if (!m_bCanSet) |
| 1665 | return FALSE; |
| 1666 | |
| 1667 | int iWidth; |
| 1668 | vp >> iWidth; |
| 1669 | |
| 1670 | if (m_bDelay) { |
| 1671 | AddDelay_Int(FP_LINEWIDTH, iWidth); |
| 1672 | } else { |
| 1673 | Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 1674 | iWidth); |
| 1675 | } |
| 1676 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1677 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1678 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1679 | return FALSE; |
| 1680 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1681 | CPDF_FormField* pFormField = FieldArray[0]; |
| 1682 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1683 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1684 | if (!pFormControl) |
| 1685 | return FALSE; |
| 1686 | |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1687 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1688 | if (!pFormField->CountControls()) |
| 1689 | return FALSE; |
| 1690 | |
| 1691 | CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); |
| 1692 | if (!pWidget) |
| 1693 | return FALSE; |
| 1694 | |
| 1695 | vp << (int32_t)pWidget->GetBorderWidth(); |
| 1696 | } |
| 1697 | |
| 1698 | return TRUE; |
| 1699 | } |
| 1700 | |
| 1701 | void Field::SetLineWidth(CPDFSDK_Document* pDocument, |
| 1702 | const CFX_WideString& swFieldName, |
| 1703 | int nControlIndex, |
| 1704 | int number) { |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1705 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1706 | std::vector<CPDF_FormField*> FieldArray = |
| 1707 | GetFormFields(pDocument, swFieldName); |
| 1708 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1709 | if (nControlIndex < 0) { |
| 1710 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1711 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 1712 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1713 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1714 | |
| 1715 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 1716 | if (number != pWidget->GetBorderWidth()) { |
| 1717 | pWidget->SetBorderWidth(number); |
| 1718 | bSet = TRUE; |
| 1719 | } |
| 1720 | } |
| 1721 | } |
| 1722 | if (bSet) |
| 1723 | UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); |
| 1724 | } else { |
| 1725 | if (nControlIndex >= pFormField->CountControls()) |
| 1726 | return; |
| 1727 | if (CPDF_FormControl* pFormControl = |
| 1728 | pFormField->GetControl(nControlIndex)) { |
| 1729 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
| 1730 | if (number != pWidget->GetBorderWidth()) { |
| 1731 | pWidget->SetBorderWidth(number); |
| 1732 | UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE); |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | } |
| 1737 | } |
| 1738 | } |
| 1739 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1740 | FX_BOOL Field::multiline(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1741 | CJS_PropValue& vp, |
| 1742 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1743 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1744 | |
| 1745 | if (vp.IsSetting()) { |
| 1746 | if (!m_bCanSet) |
| 1747 | return FALSE; |
| 1748 | |
| 1749 | bool bVP; |
| 1750 | vp >> bVP; |
| 1751 | |
| 1752 | if (m_bDelay) { |
| 1753 | AddDelay_Bool(FP_MULTILINE, bVP); |
| 1754 | } else { |
| 1755 | Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 1756 | } |
| 1757 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1758 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1759 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1760 | return FALSE; |
| 1761 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1762 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1763 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 1764 | return FALSE; |
| 1765 | |
| 1766 | if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE) |
| 1767 | vp << true; |
| 1768 | else |
| 1769 | vp << false; |
| 1770 | } |
| 1771 | |
| 1772 | return TRUE; |
| 1773 | } |
| 1774 | |
| 1775 | void Field::SetMultiline(CPDFSDK_Document* pDocument, |
| 1776 | const CFX_WideString& swFieldName, |
| 1777 | int nControlIndex, |
| 1778 | bool b) { |
| 1779 | // Not supported. |
| 1780 | } |
| 1781 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1782 | FX_BOOL Field::multipleSelection(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1783 | CJS_PropValue& vp, |
| 1784 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1785 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1786 | |
| 1787 | if (vp.IsSetting()) { |
| 1788 | if (!m_bCanSet) |
| 1789 | return FALSE; |
| 1790 | |
| 1791 | bool bVP; |
| 1792 | vp >> bVP; |
| 1793 | |
| 1794 | if (m_bDelay) { |
| 1795 | AddDelay_Bool(FP_MULTIPLESELECTION, bVP); |
| 1796 | } else { |
| 1797 | Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 1798 | bVP); |
| 1799 | } |
| 1800 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1801 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1802 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1803 | return FALSE; |
| 1804 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1805 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1806 | if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) |
| 1807 | return FALSE; |
| 1808 | |
| 1809 | if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT) |
| 1810 | vp << true; |
| 1811 | else |
| 1812 | vp << false; |
| 1813 | } |
| 1814 | |
| 1815 | return TRUE; |
| 1816 | } |
| 1817 | |
| 1818 | void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, |
| 1819 | const CFX_WideString& swFieldName, |
| 1820 | int nControlIndex, |
| 1821 | bool b) { |
| 1822 | // Not supported. |
| 1823 | } |
| 1824 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1825 | FX_BOOL Field::name(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1826 | CJS_PropValue& vp, |
| 1827 | CFX_WideString& sError) { |
| 1828 | if (!vp.IsGetting()) |
| 1829 | return FALSE; |
| 1830 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1831 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1832 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1833 | return FALSE; |
| 1834 | |
| 1835 | vp << m_FieldName; |
| 1836 | |
| 1837 | return TRUE; |
| 1838 | } |
| 1839 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1840 | FX_BOOL Field::numItems(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1841 | CJS_PropValue& vp, |
| 1842 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 1843 | if (!vp.IsGetting()) |
| 1844 | return FALSE; |
| 1845 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1846 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1847 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1848 | return FALSE; |
| 1849 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1850 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1851 | if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1852 | pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1853 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1854 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1855 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1856 | vp << (int32_t)pFormField->CountOptions(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1857 | return TRUE; |
| 1858 | } |
| 1859 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1860 | FX_BOOL Field::page(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1861 | CJS_PropValue& vp, |
| 1862 | CFX_WideString& sError) { |
| 1863 | if (!vp.IsGetting()) |
| 1864 | return FALSE; |
| 1865 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1866 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1867 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1868 | return FALSE; |
| 1869 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1870 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1871 | if (!pFormField) |
| 1872 | return FALSE; |
| 1873 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1874 | std::vector<CPDFSDK_Widget*> widgets; |
| 1875 | m_pDocument->GetInterForm()->GetWidgets(pFormField, &widgets); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1876 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1877 | if (widgets.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1878 | vp << (int32_t)-1; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1879 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1882 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1883 | CJS_Array PageArray(pRuntime); |
| 1884 | for (size_t i = 0; i < widgets.size(); ++i) { |
| 1885 | CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); |
| 1886 | if (!pPageView) |
| 1887 | return FALSE; |
| 1888 | |
| 1889 | PageArray.SetElement( |
| 1890 | i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); |
| 1891 | } |
| 1892 | |
| 1893 | vp << PageArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1894 | return TRUE; |
| 1895 | } |
| 1896 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1897 | FX_BOOL Field::password(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1898 | CJS_PropValue& vp, |
| 1899 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1900 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1901 | |
| 1902 | if (vp.IsSetting()) { |
| 1903 | if (!m_bCanSet) |
| 1904 | return FALSE; |
| 1905 | |
| 1906 | bool bVP; |
| 1907 | vp >> bVP; |
| 1908 | |
| 1909 | if (m_bDelay) { |
| 1910 | AddDelay_Bool(FP_PASSWORD, bVP); |
| 1911 | } else { |
| 1912 | Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 1913 | } |
| 1914 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1915 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1916 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1917 | return FALSE; |
| 1918 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1919 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1920 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 1921 | return FALSE; |
| 1922 | |
| 1923 | if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD) |
| 1924 | vp << true; |
| 1925 | else |
| 1926 | vp << false; |
| 1927 | } |
| 1928 | |
| 1929 | return TRUE; |
| 1930 | } |
| 1931 | |
| 1932 | void Field::SetPassword(CPDFSDK_Document* pDocument, |
| 1933 | const CFX_WideString& swFieldName, |
| 1934 | int nControlIndex, |
| 1935 | bool b) { |
| 1936 | // Not supported. |
| 1937 | } |
| 1938 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 1939 | FX_BOOL Field::print(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1940 | CJS_PropValue& vp, |
| 1941 | CFX_WideString& sError) { |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 1942 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1943 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1944 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1945 | return FALSE; |
| 1946 | |
| 1947 | if (vp.IsSetting()) { |
| 1948 | if (!m_bCanSet) |
| 1949 | return FALSE; |
| 1950 | |
| 1951 | bool bVP; |
| 1952 | vp >> bVP; |
| 1953 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1954 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1955 | if (m_nFormControlIndex < 0) { |
| 1956 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1957 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1958 | if (CPDFSDK_Widget* pWidget = |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1959 | pInterForm->GetWidget(pFormField->GetControl(i))) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1960 | uint32_t dwFlags = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1961 | if (bVP) |
| 1962 | dwFlags |= ANNOTFLAG_PRINT; |
| 1963 | else |
| 1964 | dwFlags &= ~ANNOTFLAG_PRINT; |
| 1965 | |
| 1966 | if (dwFlags != pWidget->GetFlags()) { |
| 1967 | pWidget->SetFlags(dwFlags); |
| 1968 | bSet = TRUE; |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | if (bSet) |
| 1974 | UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE); |
| 1975 | } else { |
| 1976 | if (m_nFormControlIndex >= pFormField->CountControls()) |
| 1977 | return FALSE; |
| 1978 | if (CPDF_FormControl* pFormControl = |
| 1979 | pFormField->GetControl(m_nFormControlIndex)) { |
| 1980 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1981 | uint32_t dwFlags = pWidget->GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1982 | if (bVP) |
| 1983 | dwFlags |= ANNOTFLAG_PRINT; |
| 1984 | else |
| 1985 | dwFlags &= ~ANNOTFLAG_PRINT; |
| 1986 | |
| 1987 | if (dwFlags != pWidget->GetFlags()) { |
| 1988 | pWidget->SetFlags(dwFlags); |
| 1989 | UpdateFormControl(m_pDocument, |
| 1990 | pFormField->GetControl(m_nFormControlIndex), |
| 1991 | TRUE, FALSE, TRUE); |
| 1992 | } |
| 1993 | } |
| 1994 | } |
| 1995 | } |
| 1996 | } |
| 1997 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1998 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1999 | CPDFSDK_Widget* pWidget = |
| 2000 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 2001 | if (!pWidget) |
| 2002 | return FALSE; |
| 2003 | |
| 2004 | if (pWidget->GetFlags() & ANNOTFLAG_PRINT) |
| 2005 | vp << true; |
| 2006 | else |
| 2007 | vp << false; |
| 2008 | } |
| 2009 | |
| 2010 | return TRUE; |
| 2011 | } |
| 2012 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2013 | FX_BOOL Field::radiosInUnison(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2014 | CJS_PropValue& vp, |
| 2015 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2016 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2017 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2018 | return FALSE; |
| 2019 | |
| 2020 | if (vp.IsSetting()) { |
| 2021 | if (!m_bCanSet) |
| 2022 | return FALSE; |
| 2023 | |
| 2024 | bool bVP; |
| 2025 | vp >> bVP; |
| 2026 | |
| 2027 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2028 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2029 | if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) |
| 2030 | return FALSE; |
| 2031 | |
| 2032 | if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON) |
| 2033 | vp << true; |
| 2034 | else |
| 2035 | vp << false; |
| 2036 | } |
| 2037 | |
| 2038 | return TRUE; |
| 2039 | } |
| 2040 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2041 | FX_BOOL Field::readonly(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2042 | CJS_PropValue& vp, |
| 2043 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2044 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2045 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2046 | return FALSE; |
| 2047 | |
| 2048 | if (vp.IsSetting()) { |
| 2049 | if (!m_bCanSet) |
| 2050 | return FALSE; |
| 2051 | |
| 2052 | bool bVP; |
| 2053 | vp >> bVP; |
| 2054 | |
| 2055 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2056 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2057 | if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY) |
| 2058 | vp << true; |
| 2059 | else |
| 2060 | vp << false; |
| 2061 | } |
| 2062 | |
| 2063 | return TRUE; |
| 2064 | } |
| 2065 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2066 | FX_BOOL Field::rect(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2067 | CJS_PropValue& vp, |
| 2068 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2069 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 2070 | CJS_Value Upper_Leftx(pRuntime); |
| 2071 | CJS_Value Upper_Lefty(pRuntime); |
| 2072 | CJS_Value Lower_Rightx(pRuntime); |
| 2073 | CJS_Value Lower_Righty(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2074 | |
| 2075 | if (vp.IsSetting()) { |
| 2076 | if (!m_bCanSet) |
| 2077 | return FALSE; |
| 2078 | if (!vp.IsArrayObject()) |
| 2079 | return FALSE; |
| 2080 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2081 | CJS_Array rcArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2082 | vp >> rcArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2083 | rcArray.GetElement(0, Upper_Leftx); |
| 2084 | rcArray.GetElement(1, Upper_Lefty); |
| 2085 | rcArray.GetElement(2, Lower_Rightx); |
| 2086 | rcArray.GetElement(3, Lower_Righty); |
| 2087 | |
| 2088 | FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 2089 | pArray[0] = (FX_FLOAT)Upper_Leftx.ToInt(); |
| 2090 | pArray[1] = (FX_FLOAT)Lower_Righty.ToInt(); |
| 2091 | pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt(); |
| 2092 | pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt(); |
| 2093 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2094 | CFX_FloatRect crRect(pArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2095 | if (m_bDelay) { |
| 2096 | AddDelay_Rect(FP_RECT, crRect); |
| 2097 | } else { |
| 2098 | Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect); |
| 2099 | } |
| 2100 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2101 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2102 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2103 | return FALSE; |
| 2104 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2105 | CPDF_FormField* pFormField = FieldArray[0]; |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 2106 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2107 | CPDFSDK_Widget* pWidget = |
| 2108 | pInterForm->GetWidget(GetSmartFieldControl(pFormField)); |
| 2109 | if (!pWidget) |
| 2110 | return FALSE; |
| 2111 | |
| 2112 | CFX_FloatRect crRect = pWidget->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2113 | Upper_Leftx = (int32_t)crRect.left; |
| 2114 | Upper_Lefty = (int32_t)crRect.top; |
| 2115 | Lower_Rightx = (int32_t)crRect.right; |
| 2116 | Lower_Righty = (int32_t)crRect.bottom; |
| 2117 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2118 | CJS_Array rcArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2119 | rcArray.SetElement(0, Upper_Leftx); |
| 2120 | rcArray.SetElement(1, Upper_Lefty); |
| 2121 | rcArray.SetElement(2, Lower_Rightx); |
| 2122 | rcArray.SetElement(3, Lower_Righty); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2123 | vp << rcArray; |
| 2124 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2125 | return TRUE; |
| 2126 | } |
| 2127 | |
| 2128 | void Field::SetRect(CPDFSDK_Document* pDocument, |
| 2129 | const CFX_WideString& swFieldName, |
| 2130 | int nControlIndex, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2131 | const CFX_FloatRect& rect) { |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 2132 | CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2133 | std::vector<CPDF_FormField*> FieldArray = |
| 2134 | GetFormFields(pDocument, swFieldName); |
| 2135 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2136 | if (nControlIndex < 0) { |
| 2137 | FX_BOOL bSet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2138 | for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2139 | CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2140 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2141 | |
| 2142 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2143 | CFX_FloatRect crRect = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2144 | |
| 2145 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2146 | crRect.Intersect(pPDFPage->GetPageBBox()); |
| 2147 | |
| 2148 | if (!crRect.IsEmpty()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2149 | CFX_FloatRect rcOld = pWidget->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2150 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 2151 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 2152 | pWidget->SetRect(crRect); |
| 2153 | bSet = TRUE; |
| 2154 | } |
| 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | if (bSet) |
| 2160 | UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); |
| 2161 | } else { |
| 2162 | if (nControlIndex >= pFormField->CountControls()) |
| 2163 | return; |
| 2164 | if (CPDF_FormControl* pFormControl = |
| 2165 | pFormField->GetControl(nControlIndex)) { |
| 2166 | if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2167 | CFX_FloatRect crRect = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2168 | |
| 2169 | CPDF_Page* pPDFPage = pWidget->GetPDFPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2170 | crRect.Intersect(pPDFPage->GetPageBBox()); |
| 2171 | |
| 2172 | if (!crRect.IsEmpty()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2173 | CFX_FloatRect rcOld = pWidget->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2174 | if (crRect.left != rcOld.left || crRect.right != rcOld.right || |
| 2175 | crRect.top != rcOld.top || crRect.bottom != rcOld.bottom) { |
| 2176 | pWidget->SetRect(crRect); |
| 2177 | UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE); |
| 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | } |
| 2184 | } |
| 2185 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2186 | FX_BOOL Field::required(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2187 | CJS_PropValue& vp, |
| 2188 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2189 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2190 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2191 | return FALSE; |
| 2192 | |
| 2193 | if (vp.IsSetting()) { |
| 2194 | if (!m_bCanSet) |
| 2195 | return FALSE; |
| 2196 | |
| 2197 | bool bVP; |
| 2198 | vp >> bVP; |
| 2199 | |
| 2200 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2201 | CPDF_FormField* pFormField = FieldArray[0]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2202 | if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2203 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2204 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2205 | if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED) |
| 2206 | vp << true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2207 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2208 | vp << false; |
| 2209 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2210 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2211 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2214 | FX_BOOL Field::richText(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2215 | CJS_PropValue& vp, |
| 2216 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2217 | ASSERT(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2218 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2219 | if (vp.IsSetting()) { |
| 2220 | if (!m_bCanSet) |
| 2221 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2222 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2223 | bool bVP; |
| 2224 | vp >> bVP; |
| 2225 | |
| 2226 | if (m_bDelay) { |
| 2227 | AddDelay_Bool(FP_RICHTEXT, bVP); |
| 2228 | } else { |
| 2229 | Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP); |
| 2230 | } |
| 2231 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2232 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2233 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2234 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2235 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2236 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2237 | if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) |
| 2238 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2239 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2240 | if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT) |
| 2241 | vp << true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2242 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2243 | vp << false; |
| 2244 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2246 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2249 | void Field::SetRichText(CPDFSDK_Document* pDocument, |
| 2250 | const CFX_WideString& swFieldName, |
| 2251 | int nControlIndex, |
| 2252 | bool b) { |
| 2253 | // Not supported. |
| 2254 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2255 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2256 | FX_BOOL Field::richValue(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2257 | CJS_PropValue& vp, |
| 2258 | CFX_WideString& sError) { |
| 2259 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2260 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2262 | void Field::SetRichValue(CPDFSDK_Document* pDocument, |
| 2263 | const CFX_WideString& swFieldName, |
| 2264 | int nControlIndex) { |
| 2265 | // Not supported. |
| 2266 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2267 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2268 | FX_BOOL Field::rotation(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2269 | CJS_PropValue& vp, |
| 2270 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2271 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2272 | |
| 2273 | if (vp.IsSetting()) { |
| 2274 | if (!m_bCanSet) |
| 2275 | return FALSE; |
| 2276 | |
| 2277 | int nVP; |
| 2278 | vp >> nVP; |
| 2279 | |
| 2280 | if (m_bDelay) { |
| 2281 | AddDelay_Int(FP_ROTATION, nVP); |
| 2282 | } else { |
| 2283 | Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); |
| 2284 | } |
| 2285 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2286 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2287 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2288 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2289 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2290 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2291 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2292 | if (!pFormControl) |
| 2293 | return FALSE; |
| 2294 | |
| 2295 | vp << (int32_t)pFormControl->GetRotation(); |
| 2296 | } |
| 2297 | |
| 2298 | return TRUE; |
| 2299 | } |
| 2300 | |
| 2301 | void Field::SetRotation(CPDFSDK_Document* pDocument, |
| 2302 | const CFX_WideString& swFieldName, |
| 2303 | int nControlIndex, |
| 2304 | int number) { |
| 2305 | // Not supported. |
| 2306 | } |
| 2307 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2308 | FX_BOOL Field::strokeColor(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2309 | CJS_PropValue& vp, |
| 2310 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2311 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 2312 | CJS_Array crArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2313 | |
| 2314 | if (vp.IsSetting()) { |
| 2315 | if (!m_bCanSet) |
| 2316 | return FALSE; |
| 2317 | |
| 2318 | if (!vp.IsArrayObject()) |
| 2319 | return FALSE; |
| 2320 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2321 | vp >> crArray; |
| 2322 | |
| 2323 | CPWL_Color color; |
| 2324 | color::ConvertArrayToPWLColor(crArray, color); |
| 2325 | |
| 2326 | if (m_bDelay) { |
| 2327 | AddDelay_Color(FP_STROKECOLOR, color); |
| 2328 | } else { |
| 2329 | Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 2330 | color); |
| 2331 | } |
| 2332 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2333 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2334 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2335 | return FALSE; |
| 2336 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2337 | CPDF_FormField* pFormField = FieldArray[0]; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2338 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2339 | if (!pFormControl) |
| 2340 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2341 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2342 | int iColorType; |
| 2343 | pFormControl->GetBorderColor(iColorType); |
| 2344 | |
| 2345 | CPWL_Color color; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2346 | if (iColorType == COLORTYPE_TRANSPARENT) { |
| 2347 | color = CPWL_Color(COLORTYPE_TRANSPARENT); |
| 2348 | } else if (iColorType == COLORTYPE_GRAY) { |
| 2349 | color = |
| 2350 | CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0)); |
| 2351 | } else if (iColorType == COLORTYPE_RGB) { |
| 2352 | color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0), |
| 2353 | pFormControl->GetOriginalBorderColor(1), |
| 2354 | pFormControl->GetOriginalBorderColor(2)); |
| 2355 | } else if (iColorType == COLORTYPE_CMYK) { |
| 2356 | color = |
| 2357 | CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0), |
| 2358 | pFormControl->GetOriginalBorderColor(1), |
| 2359 | pFormControl->GetOriginalBorderColor(2), |
| 2360 | pFormControl->GetOriginalBorderColor(3)); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2361 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2362 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2363 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2364 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2365 | color::ConvertPWLColorToArray(color, crArray); |
| 2366 | vp << crArray; |
| 2367 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2368 | return TRUE; |
| 2369 | } |
| 2370 | |
| 2371 | void Field::SetStrokeColor(CPDFSDK_Document* pDocument, |
| 2372 | const CFX_WideString& swFieldName, |
| 2373 | int nControlIndex, |
| 2374 | const CPWL_Color& color) { |
| 2375 | // Not supported. |
| 2376 | } |
| 2377 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2378 | FX_BOOL Field::style(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2379 | CJS_PropValue& vp, |
| 2380 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2381 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2382 | |
| 2383 | if (vp.IsSetting()) { |
| 2384 | if (!m_bCanSet) |
| 2385 | return FALSE; |
| 2386 | |
| 2387 | CFX_ByteString csBCaption; |
| 2388 | vp >> csBCaption; |
| 2389 | |
| 2390 | if (m_bDelay) { |
| 2391 | AddDelay_String(FP_STYLE, csBCaption); |
| 2392 | } else { |
| 2393 | Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 2394 | csBCaption); |
| 2395 | } |
| 2396 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2397 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2398 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2399 | return FALSE; |
| 2400 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2401 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2402 | if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON && |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2403 | pFormField->GetFieldType() != FIELDTYPE_CHECKBOX) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2404 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2405 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2406 | |
| 2407 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2408 | if (!pFormControl) |
| 2409 | return FALSE; |
| 2410 | |
| 2411 | CFX_WideString csWCaption = pFormControl->GetNormalCaption(); |
| 2412 | CFX_ByteString csBCaption; |
| 2413 | |
| 2414 | switch (csWCaption[0]) { |
| 2415 | case L'l': |
| 2416 | csBCaption = "circle"; |
| 2417 | break; |
| 2418 | case L'8': |
| 2419 | csBCaption = "cross"; |
| 2420 | break; |
| 2421 | case L'u': |
| 2422 | csBCaption = "diamond"; |
| 2423 | break; |
| 2424 | case L'n': |
| 2425 | csBCaption = "square"; |
| 2426 | break; |
| 2427 | case L'H': |
| 2428 | csBCaption = "star"; |
| 2429 | break; |
| 2430 | default: // L'4' |
| 2431 | csBCaption = "check"; |
| 2432 | break; |
| 2433 | } |
| 2434 | vp << csBCaption; |
| 2435 | } |
| 2436 | |
| 2437 | return TRUE; |
| 2438 | } |
| 2439 | |
| 2440 | void Field::SetStyle(CPDFSDK_Document* pDocument, |
| 2441 | const CFX_WideString& swFieldName, |
| 2442 | int nControlIndex, |
| 2443 | const CFX_ByteString& string) { |
| 2444 | // Not supported. |
| 2445 | } |
| 2446 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2447 | FX_BOOL Field::submitName(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2448 | CJS_PropValue& vp, |
| 2449 | CFX_WideString& sError) { |
| 2450 | return TRUE; |
| 2451 | } |
| 2452 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2453 | FX_BOOL Field::textColor(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2454 | CJS_PropValue& vp, |
| 2455 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2456 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 2457 | CJS_Array crArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2458 | |
| 2459 | if (vp.IsSetting()) { |
| 2460 | if (!m_bCanSet) |
| 2461 | return FALSE; |
| 2462 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2463 | if (!vp.IsArrayObject()) |
| 2464 | return FALSE; |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2465 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2466 | vp >> crArray; |
| 2467 | |
| 2468 | CPWL_Color color; |
| 2469 | color::ConvertArrayToPWLColor(crArray, color); |
| 2470 | |
| 2471 | if (m_bDelay) { |
| 2472 | AddDelay_Color(FP_TEXTCOLOR, color); |
| 2473 | } else { |
| 2474 | Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color); |
| 2475 | } |
| 2476 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2477 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2478 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2479 | return FALSE; |
| 2480 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2481 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2482 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2483 | if (!pFormControl) |
| 2484 | return FALSE; |
| 2485 | |
| 2486 | int iColorType; |
| 2487 | FX_ARGB color; |
| 2488 | CPDF_DefaultAppearance FieldAppearance = |
| 2489 | pFormControl->GetDefaultAppearance(); |
| 2490 | FieldAppearance.GetColor(color, iColorType); |
| 2491 | int32_t a, r, g, b; |
| 2492 | ArgbDecode(color, a, r, g, b); |
| 2493 | |
| 2494 | CPWL_Color crRet = |
| 2495 | CPWL_Color(COLORTYPE_RGB, r / 255.0f, g / 255.0f, b / 255.0f); |
| 2496 | |
| 2497 | if (iColorType == COLORTYPE_TRANSPARENT) |
| 2498 | crRet = CPWL_Color(COLORTYPE_TRANSPARENT); |
| 2499 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2500 | color::ConvertPWLColorToArray(crRet, crArray); |
| 2501 | vp << crArray; |
| 2502 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2503 | return TRUE; |
| 2504 | } |
| 2505 | |
| 2506 | void Field::SetTextColor(CPDFSDK_Document* pDocument, |
| 2507 | const CFX_WideString& swFieldName, |
| 2508 | int nControlIndex, |
| 2509 | const CPWL_Color& color) { |
| 2510 | // Not supported. |
| 2511 | } |
| 2512 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2513 | FX_BOOL Field::textFont(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2514 | CJS_PropValue& vp, |
| 2515 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2516 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2517 | |
| 2518 | if (vp.IsSetting()) { |
| 2519 | if (!m_bCanSet) |
| 2520 | return FALSE; |
| 2521 | |
| 2522 | CFX_ByteString csFontName; |
| 2523 | vp >> csFontName; |
| 2524 | if (csFontName.IsEmpty()) |
| 2525 | return FALSE; |
| 2526 | |
| 2527 | if (m_bDelay) { |
| 2528 | AddDelay_String(FP_TEXTFONT, csFontName); |
| 2529 | } else { |
| 2530 | Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, |
| 2531 | csFontName); |
| 2532 | } |
| 2533 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2534 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2535 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2536 | return FALSE; |
| 2537 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2538 | CPDF_FormField* pFormField = FieldArray[0]; |
| 2539 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2540 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2541 | if (!pFormControl) |
| 2542 | return FALSE; |
| 2543 | |
| 2544 | int nFieldType = pFormField->GetFieldType(); |
| 2545 | |
| 2546 | if (nFieldType == FIELDTYPE_PUSHBUTTON || |
| 2547 | nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX || |
| 2548 | nFieldType == FIELDTYPE_TEXTFIELD) { |
| 2549 | CPDF_Font* pFont = pFormControl->GetDefaultControlFont(); |
| 2550 | if (!pFont) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2551 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2552 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2553 | vp << pFont->GetBaseFont(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2554 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2555 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2556 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | return TRUE; |
| 2560 | } |
| 2561 | |
| 2562 | void Field::SetTextFont(CPDFSDK_Document* pDocument, |
| 2563 | const CFX_WideString& swFieldName, |
| 2564 | int nControlIndex, |
| 2565 | const CFX_ByteString& string) { |
| 2566 | // Not supported. |
| 2567 | } |
| 2568 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2569 | FX_BOOL Field::textSize(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2570 | CJS_PropValue& vp, |
| 2571 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2572 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2573 | |
| 2574 | if (vp.IsSetting()) { |
| 2575 | if (!m_bCanSet) |
| 2576 | return FALSE; |
| 2577 | |
| 2578 | int nVP; |
| 2579 | vp >> nVP; |
| 2580 | |
| 2581 | if (m_bDelay) { |
| 2582 | AddDelay_Int(FP_TEXTSIZE, nVP); |
| 2583 | } else { |
| 2584 | Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP); |
| 2585 | } |
| 2586 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2587 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2588 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2589 | return FALSE; |
| 2590 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2591 | CPDF_FormField* pFormField = FieldArray[0]; |
| 2592 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2593 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2594 | if (!pFormControl) |
| 2595 | return FALSE; |
| 2596 | |
| 2597 | CPDF_DefaultAppearance FieldAppearance = |
| 2598 | pFormControl->GetDefaultAppearance(); |
| 2599 | |
| 2600 | CFX_ByteString csFontNameTag; |
| 2601 | FX_FLOAT fFontSize; |
| 2602 | FieldAppearance.GetFont(csFontNameTag, fFontSize); |
| 2603 | |
| 2604 | vp << (int)fFontSize; |
| 2605 | } |
| 2606 | |
| 2607 | return TRUE; |
| 2608 | } |
| 2609 | |
| 2610 | void Field::SetTextSize(CPDFSDK_Document* pDocument, |
| 2611 | const CFX_WideString& swFieldName, |
| 2612 | int nControlIndex, |
| 2613 | int number) { |
| 2614 | // Not supported. |
| 2615 | } |
| 2616 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2617 | FX_BOOL Field::type(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2618 | CJS_PropValue& vp, |
| 2619 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2620 | if (!vp.IsGetting()) |
| 2621 | return FALSE; |
| 2622 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2623 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2624 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2625 | return FALSE; |
| 2626 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2627 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2628 | switch (pFormField->GetFieldType()) { |
| 2629 | case FIELDTYPE_UNKNOWN: |
| 2630 | vp << L"unknown"; |
| 2631 | break; |
| 2632 | case FIELDTYPE_PUSHBUTTON: |
| 2633 | vp << L"button"; |
| 2634 | break; |
| 2635 | case FIELDTYPE_CHECKBOX: |
| 2636 | vp << L"checkbox"; |
| 2637 | break; |
| 2638 | case FIELDTYPE_RADIOBUTTON: |
| 2639 | vp << L"radiobutton"; |
| 2640 | break; |
| 2641 | case FIELDTYPE_COMBOBOX: |
| 2642 | vp << L"combobox"; |
| 2643 | break; |
| 2644 | case FIELDTYPE_LISTBOX: |
| 2645 | vp << L"listbox"; |
| 2646 | break; |
| 2647 | case FIELDTYPE_TEXTFIELD: |
| 2648 | vp << L"text"; |
| 2649 | break; |
| 2650 | case FIELDTYPE_SIGNATURE: |
| 2651 | vp << L"signature"; |
| 2652 | break; |
| 2653 | default: |
| 2654 | vp << L"unknown"; |
| 2655 | break; |
| 2656 | } |
| 2657 | |
| 2658 | return TRUE; |
| 2659 | } |
| 2660 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2661 | FX_BOOL Field::userName(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2662 | CJS_PropValue& vp, |
| 2663 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2664 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2665 | |
| 2666 | if (vp.IsSetting()) { |
| 2667 | if (!m_bCanSet) |
| 2668 | return FALSE; |
| 2669 | |
| 2670 | CFX_WideString swName; |
| 2671 | vp >> swName; |
| 2672 | |
| 2673 | if (m_bDelay) { |
| 2674 | AddDelay_WideString(FP_USERNAME, swName); |
| 2675 | } else { |
| 2676 | Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName); |
| 2677 | } |
| 2678 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2679 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2680 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2681 | return FALSE; |
| 2682 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2683 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2684 | vp << (CFX_WideString)pFormField->GetAlternateName(); |
| 2685 | } |
| 2686 | |
| 2687 | return TRUE; |
| 2688 | } |
| 2689 | |
| 2690 | void Field::SetUserName(CPDFSDK_Document* pDocument, |
| 2691 | const CFX_WideString& swFieldName, |
| 2692 | int nControlIndex, |
| 2693 | const CFX_WideString& string) { |
| 2694 | // Not supported. |
| 2695 | } |
| 2696 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2697 | FX_BOOL Field::value(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2698 | CJS_PropValue& vp, |
| 2699 | CFX_WideString& sError) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2700 | CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2701 | |
| 2702 | if (vp.IsSetting()) { |
| 2703 | if (!m_bCanSet) |
| 2704 | return FALSE; |
| 2705 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2706 | std::vector<CFX_WideString> strArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2707 | if (vp.IsArrayObject()) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2708 | CJS_Array ValueArray(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2709 | vp.ConvertToArray(ValueArray); |
| 2710 | for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2711 | CJS_Value ElementValue(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2712 | ValueArray.GetElement(i, ElementValue); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2713 | strArray.push_back(ElementValue.ToCFXWideString()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2714 | } |
| 2715 | } else { |
| 2716 | CFX_WideString swValue; |
| 2717 | vp >> swValue; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2718 | strArray.push_back(swValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | if (m_bDelay) { |
| 2722 | AddDelay_WideStringArray(FP_VALUE, strArray); |
| 2723 | } else { |
| 2724 | Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray); |
| 2725 | } |
| 2726 | } else { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2727 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2728 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2729 | return FALSE; |
| 2730 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2731 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2732 | switch (pFormField->GetFieldType()) { |
| 2733 | case FIELDTYPE_PUSHBUTTON: |
| 2734 | return FALSE; |
| 2735 | case FIELDTYPE_COMBOBOX: |
| 2736 | case FIELDTYPE_TEXTFIELD: { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 2737 | vp << pFormField->GetValue(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2738 | } break; |
| 2739 | case FIELDTYPE_LISTBOX: { |
| 2740 | if (pFormField->CountSelectedItems() > 1) { |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 2741 | CJS_Array ValueArray(pRuntime); |
| 2742 | CJS_Value ElementValue(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2743 | int iIndex; |
| 2744 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 2745 | iIndex = pFormField->GetSelectedIndex(i); |
| 2746 | ElementValue = pFormField->GetOptionValue(iIndex).c_str(); |
| 2747 | if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) |
| 2748 | ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); |
| 2749 | ValueArray.SetElement(i, ElementValue); |
| 2750 | } |
| 2751 | vp << ValueArray; |
| 2752 | } else { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 2753 | vp << pFormField->GetValue(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2754 | } |
| 2755 | } break; |
| 2756 | case FIELDTYPE_CHECKBOX: |
| 2757 | case FIELDTYPE_RADIOBUTTON: { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 2758 | bool bFind = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2759 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 2760 | if (pFormField->GetControl(i)->IsChecked()) { |
| 2761 | vp << pFormField->GetControl(i)->GetExportValue(); |
| 2762 | bFind = true; |
| 2763 | break; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2764 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2765 | } |
| 2766 | if (!bFind) |
| 2767 | vp << L"Off"; |
| 2768 | } break; |
| 2769 | default: |
| 2770 | vp << pFormField->GetValue(); |
| 2771 | break; |
| 2772 | } |
| 2773 | } |
Tom Sepez | 4246b00 | 2016-01-20 11:48:29 -0800 | [diff] [blame] | 2774 | vp.MaybeCoerceToNumber(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2775 | return TRUE; |
| 2776 | } |
| 2777 | |
| 2778 | void Field::SetValue(CPDFSDK_Document* pDocument, |
| 2779 | const CFX_WideString& swFieldName, |
| 2780 | int nControlIndex, |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2781 | const std::vector<CFX_WideString>& strArray) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2782 | ASSERT(pDocument); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2783 | if (strArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2784 | return; |
| 2785 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2786 | std::vector<CPDF_FormField*> FieldArray = |
| 2787 | GetFormFields(pDocument, swFieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2788 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2789 | for (CPDF_FormField* pFormField : FieldArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2790 | if (pFormField->GetFullName().Compare(swFieldName) != 0) |
| 2791 | continue; |
| 2792 | |
| 2793 | switch (pFormField->GetFieldType()) { |
| 2794 | case FIELDTYPE_TEXTFIELD: |
| 2795 | case FIELDTYPE_COMBOBOX: |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2796 | if (pFormField->GetValue() != strArray[0]) { |
| 2797 | pFormField->SetValue(strArray[0], TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2798 | UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
| 2799 | } |
| 2800 | break; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2801 | case FIELDTYPE_CHECKBOX: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2802 | case FIELDTYPE_RADIOBUTTON: { |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2803 | if (pFormField->GetValue() != strArray[0]) { |
| 2804 | pFormField->SetValue(strArray[0], TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2805 | UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
| 2806 | } |
| 2807 | } break; |
| 2808 | case FIELDTYPE_LISTBOX: { |
| 2809 | FX_BOOL bModified = FALSE; |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2810 | for (const auto& str : strArray) { |
| 2811 | if (!pFormField->IsItemSelected(pFormField->FindOption(str))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2812 | bModified = TRUE; |
| 2813 | break; |
| 2814 | } |
| 2815 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2816 | if (bModified) { |
| 2817 | pFormField->ClearSelection(TRUE); |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 2818 | for (const auto& str : strArray) { |
| 2819 | int index = pFormField->FindOption(str); |
| 2820 | if (!pFormField->IsItemSelected(index)) |
| 2821 | pFormField->SetItemSelection(index, TRUE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2822 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2823 | UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
| 2824 | } |
| 2825 | } break; |
| 2826 | default: |
| 2827 | break; |
| 2828 | } |
| 2829 | } |
| 2830 | } |
| 2831 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2832 | FX_BOOL Field::valueAsString(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2833 | CJS_PropValue& vp, |
| 2834 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2835 | if (!vp.IsGetting()) |
| 2836 | return FALSE; |
| 2837 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2838 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2839 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2840 | return FALSE; |
| 2841 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2842 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2843 | if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) |
| 2844 | return FALSE; |
| 2845 | |
| 2846 | if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) { |
| 2847 | if (!pFormField->CountControls()) |
| 2848 | return FALSE; |
| 2849 | |
| 2850 | if (pFormField->GetControl(0)->IsChecked()) |
| 2851 | vp << L"Yes"; |
| 2852 | else |
| 2853 | vp << L"Off"; |
| 2854 | } else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && |
| 2855 | !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) { |
| 2856 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2857 | if (pFormField->GetControl(i)->IsChecked()) { |
| 2858 | vp << pFormField->GetControl(i)->GetExportValue().c_str(); |
| 2859 | break; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2860 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2861 | vp << L"Off"; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2862 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2863 | } |
| 2864 | } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && |
| 2865 | (pFormField->CountSelectedItems() > 1)) { |
| 2866 | vp << L""; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2867 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2868 | vp << pFormField->GetValue().c_str(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2869 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2870 | |
| 2871 | return TRUE; |
| 2872 | } |
| 2873 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2874 | FX_BOOL Field::browseForFileToSubmit(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2875 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2876 | CJS_Value& vRet, |
| 2877 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2878 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2879 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2880 | return FALSE; |
| 2881 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2882 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2883 | CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2884 | if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) && |
| 2885 | (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD)) { |
| 2886 | CFX_WideString wsFileName = pApp->JS_fieldBrowse(); |
| 2887 | if (!wsFileName.IsEmpty()) { |
| 2888 | pFormField->SetValue(wsFileName); |
| 2889 | UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE); |
| 2890 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2891 | return TRUE; |
| 2892 | } |
| 2893 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2896 | FX_BOOL Field::buttonGetCaption(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2897 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2898 | CJS_Value& vRet, |
| 2899 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2900 | int nface = 0; |
| 2901 | int iSize = params.size(); |
| 2902 | if (iSize >= 1) |
| 2903 | nface = params[0].ToInt(); |
| 2904 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2905 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2906 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2907 | return FALSE; |
| 2908 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2909 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2910 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 2911 | return FALSE; |
| 2912 | |
| 2913 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2914 | if (!pFormControl) |
| 2915 | return FALSE; |
| 2916 | |
| 2917 | if (nface == 0) |
| 2918 | vRet = pFormControl->GetNormalCaption().c_str(); |
| 2919 | else if (nface == 1) |
| 2920 | vRet = pFormControl->GetDownCaption().c_str(); |
| 2921 | else if (nface == 2) |
| 2922 | vRet = pFormControl->GetRolloverCaption().c_str(); |
| 2923 | else |
| 2924 | return FALSE; |
| 2925 | |
| 2926 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2929 | FX_BOOL Field::buttonGetIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2930 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2931 | CJS_Value& vRet, |
| 2932 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2933 | int nface = 0; |
| 2934 | int iSize = params.size(); |
| 2935 | if (iSize >= 1) |
| 2936 | nface = params[0].ToInt(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2937 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2938 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2939 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2940 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2941 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2942 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2943 | if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
| 2944 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2945 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2946 | CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 2947 | if (!pFormControl) |
| 2948 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2949 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2950 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2951 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 2952 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2953 | pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2954 | ASSERT(pObj.IsEmpty() == FALSE); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2955 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 2956 | CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2957 | Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2958 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 2959 | CPDF_Stream* pIconStream = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2960 | if (nface == 0) |
| 2961 | pIconStream = pFormControl->GetNormalIcon(); |
| 2962 | else if (nface == 1) |
| 2963 | pIconStream = pFormControl->GetDownIcon(); |
| 2964 | else if (nface == 2) |
| 2965 | pIconStream = pFormControl->GetRolloverIcon(); |
| 2966 | else |
| 2967 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2968 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2969 | pIcon->SetStream(pIconStream); |
| 2970 | vRet = pJS_Icon; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2971 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2972 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2975 | FX_BOOL Field::buttonImportIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2976 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2977 | CJS_Value& vRet, |
| 2978 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2979 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2982 | FX_BOOL Field::buttonSetCaption(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2983 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2984 | CJS_Value& vRet, |
| 2985 | CFX_WideString& sError) { |
| 2986 | return FALSE; |
| 2987 | } |
| 2988 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2989 | FX_BOOL Field::buttonSetIcon(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2990 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2991 | CJS_Value& vRet, |
| 2992 | CFX_WideString& sError) { |
| 2993 | return FALSE; |
| 2994 | } |
| 2995 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2996 | FX_BOOL Field::checkThisBox(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 2997 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2998 | CJS_Value& vRet, |
| 2999 | CFX_WideString& sError) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 3000 | ASSERT(m_pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3001 | |
| 3002 | if (!m_bCanSet) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3003 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3004 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3005 | int iSize = params.size(); |
| 3006 | if (iSize < 1) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3007 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3008 | |
| 3009 | int nWidget = params[0].ToInt(); |
| 3010 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 3011 | bool bCheckit = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3012 | if (iSize >= 2) |
| 3013 | bCheckit = params[1].ToBool(); |
| 3014 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3015 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3016 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3017 | return FALSE; |
| 3018 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3019 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3020 | if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && |
| 3021 | pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) |
| 3022 | return FALSE; |
| 3023 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
| 3024 | return FALSE; |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 3025 | // TODO(weili): Check whether anything special needed for radio button, |
| 3026 | // otherwise merge these branches. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3027 | if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 3028 | pFormField->CheckControl(nWidget, bCheckit, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3029 | else |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 3030 | pFormField->CheckControl(nWidget, bCheckit, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3031 | |
| 3032 | UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE); |
| 3033 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3036 | FX_BOOL Field::clearItems(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3037 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3038 | CJS_Value& vRet, |
| 3039 | CFX_WideString& sError) { |
| 3040 | return TRUE; |
| 3041 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3042 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3043 | FX_BOOL Field::defaultIsChecked(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3044 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3045 | CJS_Value& vRet, |
| 3046 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3047 | if (!m_bCanSet) |
| 3048 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3049 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3050 | int iSize = params.size(); |
| 3051 | if (iSize < 1) |
| 3052 | return FALSE; |
Tom Sepez | f4ef3f9 | 2015-04-23 11:31:31 -0700 | [diff] [blame] | 3053 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3054 | int nWidget = params[0].ToInt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3055 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3056 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3057 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3058 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3059 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3060 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3061 | if (nWidget < 0 || nWidget >= pFormField->CountControls()) { |
| 3062 | vRet = FALSE; |
| 3063 | return FALSE; |
| 3064 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3065 | vRet = pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || |
| 3066 | pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3067 | |
| 3068 | return TRUE; |
| 3069 | } |
| 3070 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3071 | FX_BOOL Field::deleteItemAt(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3072 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3073 | CJS_Value& vRet, |
| 3074 | CFX_WideString& sError) { |
| 3075 | return TRUE; |
| 3076 | } |
| 3077 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3078 | FX_BOOL Field::getArray(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3079 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3080 | CJS_Value& vRet, |
| 3081 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3082 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3083 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3084 | return FALSE; |
| 3085 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 3086 | std::vector<std::unique_ptr<CFX_WideString>> swSort; |
| 3087 | for (CPDF_FormField* pFormField : FieldArray) { |
| 3088 | swSort.push_back(std::unique_ptr<CFX_WideString>( |
| 3089 | new CFX_WideString(pFormField->GetFullName()))); |
| 3090 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3091 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 3092 | std::sort( |
| 3093 | swSort.begin(), swSort.end(), |
| 3094 | [](const std::unique_ptr<CFX_WideString>& p1, |
| 3095 | const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3096 | |
| 3097 | CJS_Context* pContext = (CJS_Context*)cc; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3098 | CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 3099 | CJS_Array FormFieldArray(pRuntime); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 3100 | |
| 3101 | int j = 0; |
| 3102 | for (const auto& pStr : swSort) { |
Tom Sepez | 39bfe12 | 2015-09-17 15:25:23 -0700 | [diff] [blame] | 3103 | v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 3104 | pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); |
Tom Sepez | cd56a7d | 2015-10-06 11:45:28 -0700 | [diff] [blame] | 3105 | ASSERT(!pObj.IsEmpty()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3106 | |
Tom Sepez | d5a0e95 | 2015-09-17 15:40:06 -0700 | [diff] [blame] | 3107 | CJS_Field* pJSField = |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 3108 | static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); |
| 3109 | Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3110 | pField->AttachField(m_pJSDoc, *pStr); |
| 3111 | |
Tom Sepez | 67fd5df | 2015-10-08 12:24:19 -0700 | [diff] [blame] | 3112 | CJS_Value FormFieldValue(pRuntime); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3113 | FormFieldValue = pJSField; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 3114 | FormFieldArray.SetElement(j++, FormFieldValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | vRet = FormFieldArray; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3118 | return TRUE; |
| 3119 | } |
| 3120 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3121 | FX_BOOL Field::getItemAt(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3122 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3123 | CJS_Value& vRet, |
| 3124 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3125 | int iSize = params.size(); |
| 3126 | |
| 3127 | int nIdx = -1; |
| 3128 | if (iSize >= 1) |
| 3129 | nIdx = params[0].ToInt(); |
| 3130 | |
| 3131 | FX_BOOL bExport = TRUE; |
| 3132 | if (iSize >= 2) |
| 3133 | bExport = params[1].ToBool(); |
| 3134 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3135 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3136 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3137 | return FALSE; |
| 3138 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3139 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3140 | if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) || |
| 3141 | (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) { |
| 3142 | if (nIdx == -1 || nIdx > pFormField->CountOptions()) |
| 3143 | nIdx = pFormField->CountOptions() - 1; |
| 3144 | if (bExport) { |
| 3145 | CFX_WideString strval = pFormField->GetOptionValue(nIdx); |
| 3146 | if (strval.IsEmpty()) |
| 3147 | vRet = pFormField->GetOptionLabel(nIdx).c_str(); |
| 3148 | else |
| 3149 | vRet = strval.c_str(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3150 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3151 | vRet = pFormField->GetOptionLabel(nIdx).c_str(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3152 | } |
| 3153 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3154 | return FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3155 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3156 | |
| 3157 | return TRUE; |
| 3158 | } |
| 3159 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3160 | FX_BOOL Field::getLock(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3161 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3162 | CJS_Value& vRet, |
| 3163 | CFX_WideString& sError) { |
| 3164 | return FALSE; |
| 3165 | } |
| 3166 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3167 | FX_BOOL Field::insertItemAt(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3168 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3169 | CJS_Value& vRet, |
| 3170 | CFX_WideString& sError) { |
| 3171 | return TRUE; |
| 3172 | } |
| 3173 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3174 | FX_BOOL Field::isBoxChecked(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3175 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3176 | CJS_Value& vRet, |
| 3177 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3178 | int nIndex = -1; |
| 3179 | if (params.size() >= 1) |
| 3180 | nIndex = params[0].ToInt(); |
| 3181 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3182 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3183 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3184 | return FALSE; |
| 3185 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3186 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3187 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) { |
| 3188 | vRet = FALSE; |
| 3189 | return FALSE; |
| 3190 | } |
| 3191 | |
| 3192 | if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) || |
| 3193 | (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) { |
| 3194 | if (pFormField->GetControl(nIndex)->IsChecked() != 0) |
| 3195 | vRet = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3196 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3197 | vRet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3198 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3199 | vRet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3200 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3201 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3202 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3205 | FX_BOOL Field::isDefaultChecked(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3206 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3207 | CJS_Value& vRet, |
| 3208 | CFX_WideString& sError) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3209 | int nIndex = -1; |
| 3210 | if (params.size() >= 1) |
| 3211 | nIndex = params[0].ToInt(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3212 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3213 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3214 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3215 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3216 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3217 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3218 | if (nIndex < 0 || nIndex >= pFormField->CountControls()) { |
| 3219 | vRet = FALSE; |
| 3220 | return FALSE; |
| 3221 | } |
| 3222 | if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) || |
| 3223 | (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) { |
| 3224 | if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0) |
| 3225 | vRet = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3226 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3227 | vRet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3228 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3229 | vRet = FALSE; |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3230 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3232 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3235 | FX_BOOL Field::setAction(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3236 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3237 | CJS_Value& vRet, |
| 3238 | CFX_WideString& sError) { |
| 3239 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3242 | FX_BOOL Field::setFocus(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3243 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3244 | CJS_Value& vRet, |
| 3245 | CFX_WideString& sError) { |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3246 | std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3247 | if (FieldArray.empty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3248 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3249 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 3250 | CPDF_FormField* pFormField = FieldArray[0]; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3251 | int32_t nCount = pFormField->CountControls(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3252 | if (nCount < 1) |
| 3253 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3254 | |
tsepez | 23ae4a5 | 2016-06-08 20:44:54 -0700 | [diff] [blame] | 3255 | CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 3256 | CPDFSDK_Widget* pWidget = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3257 | if (nCount == 1) { |
| 3258 | pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); |
| 3259 | } else { |
| 3260 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 3261 | UnderlyingPageType* pPage = UnderlyingFromFPDFPage( |
| 3262 | pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3263 | if (!pPage) |
| 3264 | return FALSE; |
| 3265 | if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) { |
| 3266 | for (int32_t i = 0; i < nCount; i++) { |
| 3267 | if (CPDFSDK_Widget* pTempWidget = |
| 3268 | pInterForm->GetWidget(pFormField->GetControl(i))) { |
| 3269 | if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) { |
| 3270 | pWidget = pTempWidget; |
| 3271 | break; |
| 3272 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3273 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3274 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3275 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3276 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3278 | if (pWidget) { |
| 3279 | m_pDocument->SetFocusAnnot(pWidget); |
| 3280 | } |
| 3281 | |
| 3282 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3285 | FX_BOOL Field::setItems(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3286 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3287 | CJS_Value& vRet, |
| 3288 | CFX_WideString& sError) { |
| 3289 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3292 | FX_BOOL Field::setLock(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3293 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3294 | CJS_Value& vRet, |
| 3295 | CFX_WideString& sError) { |
| 3296 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3299 | FX_BOOL Field::signatureGetModifications(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3300 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3301 | CJS_Value& vRet, |
| 3302 | CFX_WideString& sError) { |
| 3303 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3306 | FX_BOOL Field::signatureGetSeedValue(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3307 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3308 | CJS_Value& vRet, |
| 3309 | CFX_WideString& sError) { |
| 3310 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3313 | FX_BOOL Field::signatureInfo(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3314 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3315 | CJS_Value& vRet, |
| 3316 | CFX_WideString& sError) { |
| 3317 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3320 | FX_BOOL Field::signatureSetSeedValue(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3321 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3322 | CJS_Value& vRet, |
| 3323 | CFX_WideString& sError) { |
| 3324 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3327 | FX_BOOL Field::signatureSign(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3328 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3329 | CJS_Value& vRet, |
| 3330 | CFX_WideString& sError) { |
| 3331 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3334 | FX_BOOL Field::signatureValidate(IJS_Context* cc, |
Lei Zhang | 945fdb7 | 2015-11-11 10:18:16 -0800 | [diff] [blame] | 3335 | const std::vector<CJS_Value>& params, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3336 | CJS_Value& vRet, |
| 3337 | CFX_WideString& sError) { |
| 3338 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 3341 | FX_BOOL Field::source(IJS_Context* cc, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3342 | CJS_PropValue& vp, |
| 3343 | CFX_WideString& sError) { |
| 3344 | if (vp.IsGetting()) { |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 3345 | vp << (CJS_Object*)nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3351 | void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { |
| 3352 | CJS_DelayData* pNewData = |
| 3353 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3354 | pNewData->num = n; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3355 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3358 | void Field::AddDelay_Bool(FIELD_PROP prop, bool b) { |
| 3359 | CJS_DelayData* pNewData = |
| 3360 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3361 | pNewData->b = b; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3362 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3365 | void Field::AddDelay_String(FIELD_PROP prop, const CFX_ByteString& string) { |
| 3366 | CJS_DelayData* pNewData = |
| 3367 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3368 | pNewData->string = string; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3369 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3372 | void Field::AddDelay_WideString(FIELD_PROP prop, const CFX_WideString& string) { |
| 3373 | CJS_DelayData* pNewData = |
| 3374 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3375 | pNewData->widestring = string; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3376 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3377 | } |
| 3378 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3379 | void Field::AddDelay_Rect(FIELD_PROP prop, const CFX_FloatRect& rect) { |
| 3380 | CJS_DelayData* pNewData = |
| 3381 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3382 | pNewData->rect = rect; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3383 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3386 | void Field::AddDelay_Color(FIELD_PROP prop, const CPWL_Color& color) { |
| 3387 | CJS_DelayData* pNewData = |
| 3388 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3389 | pNewData->color = color; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3390 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3393 | void Field::AddDelay_WordArray(FIELD_PROP prop, |
| 3394 | const std::vector<uint32_t>& array) { |
| 3395 | CJS_DelayData* pNewData = |
| 3396 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
| 3397 | pNewData->wordarray = array; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3398 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
tsepez | 41a53ad | 2016-03-28 16:59:30 -0700 | [diff] [blame] | 3401 | void Field::AddDelay_WideStringArray(FIELD_PROP prop, |
| 3402 | const std::vector<CFX_WideString>& array) { |
| 3403 | CJS_DelayData* pNewData = |
| 3404 | new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
| 3405 | pNewData->widestringarray = array; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3406 | m_pJSDoc->AddDelayData(pNewData); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3409 | void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 3410 | ASSERT(pDocument); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3411 | switch (pData->eProp) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3412 | case FP_ALIGNMENT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3413 | Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3414 | pData->string); |
| 3415 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3416 | case FP_BORDERSTYLE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3417 | Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3418 | pData->string); |
| 3419 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3420 | case FP_BUTTONALIGNX: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3421 | Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3422 | pData->num); |
| 3423 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3424 | case FP_BUTTONALIGNY: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3425 | Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3426 | pData->num); |
| 3427 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3428 | case FP_BUTTONFITBOUNDS: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3429 | Field::SetButtonFitBounds(pDocument, pData->sFieldName, |
| 3430 | pData->nControlIndex, pData->b); |
| 3431 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3432 | case FP_BUTTONPOSITION: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3433 | Field::SetButtonPosition(pDocument, pData->sFieldName, |
| 3434 | pData->nControlIndex, pData->num); |
| 3435 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3436 | case FP_BUTTONSCALEHOW: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3437 | Field::SetButtonScaleHow(pDocument, pData->sFieldName, |
| 3438 | pData->nControlIndex, pData->num); |
| 3439 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3440 | case FP_BUTTONSCALEWHEN: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3441 | Field::SetButtonScaleWhen(pDocument, pData->sFieldName, |
| 3442 | pData->nControlIndex, pData->num); |
| 3443 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3444 | case FP_CALCORDERINDEX: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3445 | Field::SetCalcOrderIndex(pDocument, pData->sFieldName, |
| 3446 | pData->nControlIndex, pData->num); |
| 3447 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3448 | case FP_CHARLIMIT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3449 | Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3450 | pData->num); |
| 3451 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3452 | case FP_COMB: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3453 | Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3454 | pData->b); |
| 3455 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3456 | case FP_COMMITONSELCHANGE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3457 | Field::SetCommitOnSelChange(pDocument, pData->sFieldName, |
| 3458 | pData->nControlIndex, pData->b); |
| 3459 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3460 | case FP_CURRENTVALUEINDICES: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3461 | Field::SetCurrentValueIndices(pDocument, pData->sFieldName, |
| 3462 | pData->nControlIndex, pData->wordarray); |
| 3463 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3464 | case FP_DEFAULTVALUE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3465 | Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3466 | pData->widestring); |
| 3467 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3468 | case FP_DONOTSCROLL: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3469 | Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3470 | pData->b); |
| 3471 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3472 | case FP_DISPLAY: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3473 | Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3474 | pData->num); |
| 3475 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3476 | case FP_FILLCOLOR: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3477 | Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3478 | pData->color); |
| 3479 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3480 | case FP_HIDDEN: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3481 | Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3482 | pData->b); |
| 3483 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3484 | case FP_HIGHLIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3485 | Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3486 | pData->string); |
| 3487 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3488 | case FP_LINEWIDTH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3489 | Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3490 | pData->num); |
| 3491 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3492 | case FP_MULTILINE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3493 | Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3494 | pData->b); |
| 3495 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3496 | case FP_MULTIPLESELECTION: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3497 | Field::SetMultipleSelection(pDocument, pData->sFieldName, |
| 3498 | pData->nControlIndex, pData->b); |
| 3499 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3500 | case FP_PASSWORD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3501 | Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3502 | pData->b); |
| 3503 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3504 | case FP_RECT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3505 | Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3506 | pData->rect); |
| 3507 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3508 | case FP_RICHTEXT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3509 | Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3510 | pData->b); |
| 3511 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3512 | case FP_RICHVALUE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3513 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3514 | case FP_ROTATION: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3515 | Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3516 | pData->num); |
| 3517 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3518 | case FP_STROKECOLOR: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3519 | Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3520 | pData->color); |
| 3521 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3522 | case FP_STYLE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3523 | Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3524 | pData->string); |
| 3525 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3526 | case FP_TEXTCOLOR: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3527 | Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3528 | pData->color); |
| 3529 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3530 | case FP_TEXTFONT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3531 | Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3532 | pData->string); |
| 3533 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3534 | case FP_TEXTSIZE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3535 | Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3536 | pData->num); |
| 3537 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3538 | case FP_USERNAME: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3539 | Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3540 | pData->widestring); |
| 3541 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 3542 | case FP_VALUE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3543 | Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, |
| 3544 | pData->widestringarray); |
| 3545 | break; |
| 3546 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3549 | void Field::AddField(CPDFSDK_Document* pDocument, |
| 3550 | int nPageIndex, |
| 3551 | int nFieldType, |
| 3552 | const CFX_WideString& sName, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 3553 | const CFX_FloatRect& rcCoords) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 3554 | // Not supported. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 3555 | } |