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