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