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