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