| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/Field.h" | 7 #include "fpdfsdk/javascript/Field.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "core/fpdfapi/font/cpdf_font.h" | 14 #include "core/fpdfapi/font/cpdf_font.h" |
| 15 #include "core/fpdfapi/page/cpdf_page.h" | 15 #include "core/fpdfapi/page/cpdf_page.h" |
| 16 #include "core/fpdfapi/parser/cpdf_document.h" | 16 #include "core/fpdfapi/parser/cpdf_document.h" |
| 17 #include "core/fpdfdoc/cpdf_interform.h" | 17 #include "core/fpdfdoc/cpdf_interform.h" |
| 18 #include "fpdfsdk/cpdfsdk_document.h" | |
| 19 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 18 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
| 20 #include "fpdfsdk/cpdfsdk_interform.h" | 19 #include "fpdfsdk/cpdfsdk_interform.h" |
| 21 #include "fpdfsdk/cpdfsdk_pageview.h" | 20 #include "fpdfsdk/cpdfsdk_pageview.h" |
| 22 #include "fpdfsdk/cpdfsdk_widget.h" | 21 #include "fpdfsdk/cpdfsdk_widget.h" |
| 23 #include "fpdfsdk/javascript/Document.h" | 22 #include "fpdfsdk/javascript/Document.h" |
| 24 #include "fpdfsdk/javascript/Icon.h" | 23 #include "fpdfsdk/javascript/Icon.h" |
| 25 #include "fpdfsdk/javascript/JS_Define.h" | 24 #include "fpdfsdk/javascript/JS_Define.h" |
| 26 #include "fpdfsdk/javascript/JS_EventHandler.h" | 25 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 27 #include "fpdfsdk/javascript/JS_Object.h" | 26 #include "fpdfsdk/javascript/JS_Object.h" |
| 28 #include "fpdfsdk/javascript/JS_Value.h" | 27 #include "fpdfsdk/javascript/JS_Value.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return; | 205 return; |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 strFieldName = strFieldNameParsed.substr(0, iStart); | 208 strFieldName = strFieldNameParsed.substr(0, iStart); |
| 210 } | 209 } |
| 211 | 210 |
| 212 FX_BOOL Field::AttachField(Document* pDocument, | 211 FX_BOOL Field::AttachField(Document* pDocument, |
| 213 const CFX_WideString& csFieldName) { | 212 const CFX_WideString& csFieldName) { |
| 214 m_pJSDoc = pDocument; | 213 m_pJSDoc = pDocument; |
| 215 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv()); | 214 m_pFormFillEnv.Reset(pDocument->GetFormFillEnv()); |
| 216 m_bCanSet = | 215 m_bCanSet = m_pFormFillEnv->GetPermissions(FPDFPERM_FILL_FORM) || |
| 217 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_FILL_FORM) || | 216 m_pFormFillEnv->GetPermissions(FPDFPERM_ANNOT_FORM) || |
| 218 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_ANNOT_FORM) || | 217 m_pFormFillEnv->GetPermissions(FPDFPERM_MODIFY); |
| 219 m_pFormFillEnv->GetSDKDocument()->GetPermissions(FPDFPERM_MODIFY); | |
| 220 | 218 |
| 221 CPDFSDK_InterForm* pRDInterForm = | 219 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); |
| 222 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 223 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); | 220 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
| 224 CFX_WideString swFieldNameTemp = csFieldName; | 221 CFX_WideString swFieldNameTemp = csFieldName; |
| 225 swFieldNameTemp.Replace(L"..", L"."); | 222 swFieldNameTemp.Replace(L"..", L"."); |
| 226 | 223 |
| 227 if (pInterForm->CountFields(swFieldNameTemp) <= 0) { | 224 if (pInterForm->CountFields(swFieldNameTemp) <= 0) { |
| 228 std::wstring strFieldName; | 225 std::wstring strFieldName; |
| 229 int iControlNo = -1; | 226 int iControlNo = -1; |
| 230 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); | 227 ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); |
| 231 if (iControlNo == -1) | 228 if (iControlNo == -1) |
| 232 return FALSE; | 229 return FALSE; |
| 233 | 230 |
| 234 m_FieldName = strFieldName.c_str(); | 231 m_FieldName = strFieldName.c_str(); |
| 235 m_nFormControlIndex = iControlNo; | 232 m_nFormControlIndex = iControlNo; |
| 236 return TRUE; | 233 return TRUE; |
| 237 } | 234 } |
| 238 | 235 |
| 239 m_FieldName = swFieldNameTemp; | 236 m_FieldName = swFieldNameTemp; |
| 240 m_nFormControlIndex = -1; | 237 m_nFormControlIndex = -1; |
| 241 | 238 |
| 242 return TRUE; | 239 return TRUE; |
| 243 } | 240 } |
| 244 | 241 |
| 245 std::vector<CPDF_FormField*> Field::GetFormFields( | 242 std::vector<CPDF_FormField*> Field::GetFormFields( |
| 246 CPDFSDK_FormFillEnvironment* pFormFillEnv, | 243 CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 247 const CFX_WideString& csFieldName) { | 244 const CFX_WideString& csFieldName) { |
| 248 std::vector<CPDF_FormField*> fields; | 245 std::vector<CPDF_FormField*> fields; |
| 249 CPDFSDK_InterForm* pReaderInterForm = | 246 CPDFSDK_InterForm* pReaderInterForm = pFormFillEnv->GetInterForm(); |
| 250 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 251 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 247 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| 252 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { | 248 for (int i = 0, sz = pInterForm->CountFields(csFieldName); i < sz; ++i) { |
| 253 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) | 249 if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName)) |
| 254 fields.push_back(pFormField); | 250 fields.push_back(pFormField); |
| 255 } | 251 } |
| 256 return fields; | 252 return fields; |
| 257 } | 253 } |
| 258 | 254 |
| 259 std::vector<CPDF_FormField*> Field::GetFormFields( | 255 std::vector<CPDF_FormField*> Field::GetFormFields( |
| 260 const CFX_WideString& csFieldName) const { | 256 const CFX_WideString& csFieldName) const { |
| 261 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName); | 257 return Field::GetFormFields(m_pFormFillEnv.Get(), csFieldName); |
| 262 } | 258 } |
| 263 | 259 |
| 264 void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 260 void Field::UpdateFormField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 265 CPDF_FormField* pFormField, | 261 CPDF_FormField* pFormField, |
| 266 FX_BOOL bChangeMark, | 262 FX_BOOL bChangeMark, |
| 267 FX_BOOL bResetAP, | 263 FX_BOOL bResetAP, |
| 268 FX_BOOL bRefresh) { | 264 FX_BOOL bRefresh) { |
| 269 CPDFSDK_InterForm* pInterForm = | 265 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 270 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 271 | 266 |
| 272 if (bResetAP) { | 267 if (bResetAP) { |
| 273 std::vector<CPDFSDK_Widget*> widgets; | 268 std::vector<CPDFSDK_Widget*> widgets; |
| 274 pInterForm->GetWidgets(pFormField, &widgets); | 269 pInterForm->GetWidgets(pFormField, &widgets); |
| 275 | 270 |
| 276 int nFieldType = pFormField->GetFieldType(); | 271 int nFieldType = pFormField->GetFieldType(); |
| 277 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) { | 272 if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) { |
| 278 for (CPDFSDK_Annot* pAnnot : widgets) { | 273 for (CPDFSDK_Annot* pAnnot : widgets) { |
| 279 FX_BOOL bFormatted = FALSE; | 274 FX_BOOL bFormatted = FALSE; |
| 280 CPDFSDK_Annot::ObservedPtr pObserved(pAnnot); | 275 CPDFSDK_Annot::ObservedPtr pObserved(pAnnot); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 294 | 289 |
| 295 if (bRefresh) { | 290 if (bRefresh) { |
| 296 // Refresh the widget list. The calls in |bResetAP| may have caused widgets | 291 // Refresh the widget list. The calls in |bResetAP| may have caused widgets |
| 297 // to be removed from the list. We need to call |GetWidgets| again to be | 292 // to be removed from the list. We need to call |GetWidgets| again to be |
| 298 // sure none of the widgets have been deleted. | 293 // sure none of the widgets have been deleted. |
| 299 std::vector<CPDFSDK_Widget*> widgets; | 294 std::vector<CPDFSDK_Widget*> widgets; |
| 300 pInterForm->GetWidgets(pFormField, &widgets); | 295 pInterForm->GetWidgets(pFormField, &widgets); |
| 301 | 296 |
| 302 // TODO(dsinclair): Determine if all widgets share the same | 297 // TODO(dsinclair): Determine if all widgets share the same |
| 303 // CPDFSDK_InterForm. If that's the case, we can move the code to | 298 // CPDFSDK_InterForm. If that's the case, we can move the code to |
| 304 // |GetSDKDocument| out of the loop. | 299 // |GetFormFillEnv| out of the loop. |
| 305 for (CPDFSDK_Widget* pWidget : widgets) { | 300 for (CPDFSDK_Widget* pWidget : widgets) { |
| 306 pWidget->GetInterForm() | 301 pWidget->GetInterForm() |
| 307 ->GetFormFillEnv() | 302 ->GetFormFillEnv() |
| 308 ->GetSDKDocument() | |
| 309 ->UpdateAllViews(nullptr, pWidget); | 303 ->UpdateAllViews(nullptr, pWidget); |
| 310 } | 304 } |
| 311 } | 305 } |
| 312 | 306 |
| 313 if (bChangeMark) | 307 if (bChangeMark) |
| 314 pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 308 pFormFillEnv->SetChangeMark(); |
| 315 } | 309 } |
| 316 | 310 |
| 317 void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 311 void Field::UpdateFormControl(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 318 CPDF_FormControl* pFormControl, | 312 CPDF_FormControl* pFormControl, |
| 319 FX_BOOL bChangeMark, | 313 FX_BOOL bChangeMark, |
| 320 FX_BOOL bResetAP, | 314 FX_BOOL bResetAP, |
| 321 FX_BOOL bRefresh) { | 315 FX_BOOL bRefresh) { |
| 322 ASSERT(pFormControl); | 316 ASSERT(pFormControl); |
| 323 | 317 |
| 324 CPDFSDK_InterForm* pForm = pFormFillEnv->GetSDKDocument()->GetInterForm(); | 318 CPDFSDK_InterForm* pForm = pFormFillEnv->GetInterForm(); |
| 325 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl, false); | 319 CPDFSDK_Widget* pWidget = pForm->GetWidget(pFormControl, false); |
| 326 | 320 |
| 327 if (pWidget) { | 321 if (pWidget) { |
| 328 if (bResetAP) { | 322 if (bResetAP) { |
| 329 int nFieldType = pWidget->GetFieldType(); | 323 int nFieldType = pWidget->GetFieldType(); |
| 330 if (nFieldType == FIELDTYPE_COMBOBOX || | 324 if (nFieldType == FIELDTYPE_COMBOBOX || |
| 331 nFieldType == FIELDTYPE_TEXTFIELD) { | 325 nFieldType == FIELDTYPE_TEXTFIELD) { |
| 332 FX_BOOL bFormatted = FALSE; | 326 FX_BOOL bFormatted = FALSE; |
| 333 CFX_WideString sValue = pWidget->OnFormat(bFormatted); | 327 CFX_WideString sValue = pWidget->OnFormat(bFormatted); |
| 334 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, FALSE); | 328 pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, FALSE); |
| 335 } else { | 329 } else { |
| 336 pWidget->ResetAppearance(nullptr, FALSE); | 330 pWidget->ResetAppearance(nullptr, FALSE); |
| 337 } | 331 } |
| 338 } | 332 } |
| 339 | 333 |
| 340 if (bRefresh) { | 334 if (bRefresh) { |
| 341 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); | 335 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 342 pInterForm->GetFormFillEnv()->GetSDKDocument()->UpdateAllViews(nullptr, | 336 pInterForm->GetFormFillEnv()->UpdateAllViews(nullptr, pWidget); |
| 343 pWidget); | |
| 344 } | 337 } |
| 345 } | 338 } |
| 346 | 339 |
| 347 if (bChangeMark) | 340 if (bChangeMark) |
| 348 pFormFillEnv->GetSDKDocument()->SetChangeMark(); | 341 pFormFillEnv->SetChangeMark(); |
| 349 } | 342 } |
| 350 | 343 |
| 351 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 344 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 352 CPDF_FormControl* pFormControl, | 345 CPDF_FormControl* pFormControl, |
| 353 bool createIfNeeded) { | 346 bool createIfNeeded) { |
| 354 CPDFSDK_InterForm* pInterForm = static_cast<CPDFSDK_InterForm*>( | 347 CPDFSDK_InterForm* pInterForm = |
| 355 pFormFillEnv->GetSDKDocument()->GetInterForm()); | 348 static_cast<CPDFSDK_InterForm*>(pFormFillEnv->GetInterForm()); |
| 356 return pInterForm ? pInterForm->GetWidget(pFormControl, createIfNeeded) | 349 return pInterForm ? pInterForm->GetWidget(pFormControl, createIfNeeded) |
| 357 : nullptr; | 350 : nullptr; |
| 358 } | 351 } |
| 359 | 352 |
| 360 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, | 353 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, |
| 361 CFX_WideString csOptLabel) { | 354 CFX_WideString csOptLabel) { |
| 362 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { | 355 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { |
| 363 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) | 356 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) |
| 364 return TRUE; | 357 return TRUE; |
| 365 } | 358 } |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 851 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 859 if (FieldArray.empty()) | 852 if (FieldArray.empty()) |
| 860 return FALSE; | 853 return FALSE; |
| 861 | 854 |
| 862 CPDF_FormField* pFormField = FieldArray[0]; | 855 CPDF_FormField* pFormField = FieldArray[0]; |
| 863 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && | 856 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
| 864 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) { | 857 pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) { |
| 865 return FALSE; | 858 return FALSE; |
| 866 } | 859 } |
| 867 | 860 |
| 868 CPDFSDK_InterForm* pRDInterForm = | 861 CPDFSDK_InterForm* pRDInterForm = m_pFormFillEnv->GetInterForm(); |
| 869 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 870 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); | 862 CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); |
| 871 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); | 863 vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); |
| 872 } | 864 } |
| 873 | 865 |
| 874 return TRUE; | 866 return TRUE; |
| 875 } | 867 } |
| 876 | 868 |
| 877 void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 869 void Field::SetCalcOrderIndex(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 878 const CFX_WideString& swFieldName, | 870 const CFX_WideString& swFieldName, |
| 879 int nControlIndex, | 871 int nControlIndex, |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, | 1255 Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1264 nVP); | 1256 nVP); |
| 1265 } | 1257 } |
| 1266 } else { | 1258 } else { |
| 1267 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 1259 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1268 if (FieldArray.empty()) | 1260 if (FieldArray.empty()) |
| 1269 return FALSE; | 1261 return FALSE; |
| 1270 | 1262 |
| 1271 CPDF_FormField* pFormField = FieldArray[0]; | 1263 CPDF_FormField* pFormField = FieldArray[0]; |
| 1272 ASSERT(pFormField); | 1264 ASSERT(pFormField); |
| 1273 CPDFSDK_InterForm* pInterForm = | 1265 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1274 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1275 CPDFSDK_Widget* pWidget = | 1266 CPDFSDK_Widget* pWidget = |
| 1276 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); | 1267 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); |
| 1277 if (!pWidget) | 1268 if (!pWidget) |
| 1278 return FALSE; | 1269 return FALSE; |
| 1279 | 1270 |
| 1280 uint32_t dwFlag = pWidget->GetFlags(); | 1271 uint32_t dwFlag = pWidget->GetFlags(); |
| 1281 | 1272 |
| 1282 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) { | 1273 if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) { |
| 1283 vp << (int32_t)1; | 1274 vp << (int32_t)1; |
| 1284 } else { | 1275 } else { |
| 1285 if (ANNOTFLAG_PRINT & dwFlag) { | 1276 if (ANNOTFLAG_PRINT & dwFlag) { |
| 1286 if (ANNOTFLAG_NOVIEW & dwFlag) { | 1277 if (ANNOTFLAG_NOVIEW & dwFlag) { |
| 1287 vp << (int32_t)3; | 1278 vp << (int32_t)3; |
| 1288 } else { | 1279 } else { |
| 1289 vp << (int32_t)0; | 1280 vp << (int32_t)0; |
| 1290 } | 1281 } |
| 1291 } else { | 1282 } else { |
| 1292 vp << (int32_t)2; | 1283 vp << (int32_t)2; |
| 1293 } | 1284 } |
| 1294 } | 1285 } |
| 1295 } | 1286 } |
| 1296 | 1287 |
| 1297 return TRUE; | 1288 return TRUE; |
| 1298 } | 1289 } |
| 1299 | 1290 |
| 1300 void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 1291 void Field::SetDisplay(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 1301 const CFX_WideString& swFieldName, | 1292 const CFX_WideString& swFieldName, |
| 1302 int nControlIndex, | 1293 int nControlIndex, |
| 1303 int number) { | 1294 int number) { |
| 1304 CPDFSDK_InterForm* pInterForm = | 1295 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 1305 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1306 std::vector<CPDF_FormField*> FieldArray = | 1296 std::vector<CPDF_FormField*> FieldArray = |
| 1307 GetFormFields(pFormFillEnv, swFieldName); | 1297 GetFormFields(pFormFillEnv, swFieldName); |
| 1308 for (CPDF_FormField* pFormField : FieldArray) { | 1298 for (CPDF_FormField* pFormField : FieldArray) { |
| 1309 if (nControlIndex < 0) { | 1299 if (nControlIndex < 0) { |
| 1310 bool bAnySet = false; | 1300 bool bAnySet = false; |
| 1311 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { | 1301 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 1312 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 1302 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 1313 ASSERT(pFormControl); | 1303 ASSERT(pFormControl); |
| 1314 | 1304 |
| 1315 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); | 1305 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, | 1519 Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 1530 bVP); | 1520 bVP); |
| 1531 } | 1521 } |
| 1532 } else { | 1522 } else { |
| 1533 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 1523 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1534 if (FieldArray.empty()) | 1524 if (FieldArray.empty()) |
| 1535 return FALSE; | 1525 return FALSE; |
| 1536 | 1526 |
| 1537 CPDF_FormField* pFormField = FieldArray[0]; | 1527 CPDF_FormField* pFormField = FieldArray[0]; |
| 1538 ASSERT(pFormField); | 1528 ASSERT(pFormField); |
| 1539 CPDFSDK_InterForm* pInterForm = | 1529 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1540 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1541 CPDFSDK_Widget* pWidget = | 1530 CPDFSDK_Widget* pWidget = |
| 1542 pInterForm->GetWidget(GetSmartFieldControl(pFormField), false); | 1531 pInterForm->GetWidget(GetSmartFieldControl(pFormField), false); |
| 1543 if (!pWidget) | 1532 if (!pWidget) |
| 1544 return FALSE; | 1533 return FALSE; |
| 1545 | 1534 |
| 1546 uint32_t dwFlags = pWidget->GetFlags(); | 1535 uint32_t dwFlags = pWidget->GetFlags(); |
| 1547 | 1536 |
| 1548 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) | 1537 if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) |
| 1549 vp << true; | 1538 vp << true; |
| 1550 else | 1539 else |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 1632 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1644 if (FieldArray.empty()) | 1633 if (FieldArray.empty()) |
| 1645 return FALSE; | 1634 return FALSE; |
| 1646 | 1635 |
| 1647 CPDF_FormField* pFormField = FieldArray[0]; | 1636 CPDF_FormField* pFormField = FieldArray[0]; |
| 1648 ASSERT(pFormField); | 1637 ASSERT(pFormField); |
| 1649 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); | 1638 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
| 1650 if (!pFormControl) | 1639 if (!pFormControl) |
| 1651 return FALSE; | 1640 return FALSE; |
| 1652 | 1641 |
| 1653 CPDFSDK_InterForm* pInterForm = | 1642 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1654 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1655 if (!pFormField->CountControls()) | 1643 if (!pFormField->CountControls()) |
| 1656 return FALSE; | 1644 return FALSE; |
| 1657 | 1645 |
| 1658 CPDFSDK_Widget* pWidget = | 1646 CPDFSDK_Widget* pWidget = |
| 1659 pInterForm->GetWidget(pFormField->GetControl(0), false); | 1647 pInterForm->GetWidget(pFormField->GetControl(0), false); |
| 1660 if (!pWidget) | 1648 if (!pWidget) |
| 1661 return FALSE; | 1649 return FALSE; |
| 1662 | 1650 |
| 1663 vp << (int32_t)pWidget->GetBorderWidth(); | 1651 vp << (int32_t)pWidget->GetBorderWidth(); |
| 1664 } | 1652 } |
| 1665 | 1653 |
| 1666 return TRUE; | 1654 return TRUE; |
| 1667 } | 1655 } |
| 1668 | 1656 |
| 1669 void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 1657 void Field::SetLineWidth(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 1670 const CFX_WideString& swFieldName, | 1658 const CFX_WideString& swFieldName, |
| 1671 int nControlIndex, | 1659 int nControlIndex, |
| 1672 int number) { | 1660 int number) { |
| 1673 CPDFSDK_InterForm* pInterForm = | 1661 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 1674 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1675 std::vector<CPDF_FormField*> FieldArray = | 1662 std::vector<CPDF_FormField*> FieldArray = |
| 1676 GetFormFields(pFormFillEnv, swFieldName); | 1663 GetFormFields(pFormFillEnv, swFieldName); |
| 1677 for (CPDF_FormField* pFormField : FieldArray) { | 1664 for (CPDF_FormField* pFormField : FieldArray) { |
| 1678 if (nControlIndex < 0) { | 1665 if (nControlIndex < 0) { |
| 1679 FX_BOOL bSet = FALSE; | 1666 FX_BOOL bSet = FALSE; |
| 1680 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { | 1667 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 1681 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 1668 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 1682 ASSERT(pFormControl); | 1669 ASSERT(pFormControl); |
| 1683 | 1670 |
| 1684 if (CPDFSDK_Widget* pWidget = | 1671 if (CPDFSDK_Widget* pWidget = |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 | 1824 |
| 1838 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 1825 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1839 if (FieldArray.empty()) | 1826 if (FieldArray.empty()) |
| 1840 return FALSE; | 1827 return FALSE; |
| 1841 | 1828 |
| 1842 CPDF_FormField* pFormField = FieldArray[0]; | 1829 CPDF_FormField* pFormField = FieldArray[0]; |
| 1843 if (!pFormField) | 1830 if (!pFormField) |
| 1844 return FALSE; | 1831 return FALSE; |
| 1845 | 1832 |
| 1846 std::vector<CPDFSDK_Widget*> widgets; | 1833 std::vector<CPDFSDK_Widget*> widgets; |
| 1847 m_pFormFillEnv->GetSDKDocument()->GetInterForm()->GetWidgets(pFormField, | 1834 m_pFormFillEnv->GetInterForm()->GetWidgets(pFormField, &widgets); |
| 1848 &widgets); | |
| 1849 | 1835 |
| 1850 if (widgets.empty()) { | 1836 if (widgets.empty()) { |
| 1851 vp << (int32_t)-1; | 1837 vp << (int32_t)-1; |
| 1852 return TRUE; | 1838 return TRUE; |
| 1853 } | 1839 } |
| 1854 | 1840 |
| 1855 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1841 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1856 CJS_Array PageArray; | 1842 CJS_Array PageArray; |
| 1857 for (size_t i = 0; i < widgets.size(); ++i) { | 1843 for (size_t i = 0; i < widgets.size(); ++i) { |
| 1858 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); | 1844 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1906 void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 1892 void Field::SetPassword(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 1907 const CFX_WideString& swFieldName, | 1893 const CFX_WideString& swFieldName, |
| 1908 int nControlIndex, | 1894 int nControlIndex, |
| 1909 bool b) { | 1895 bool b) { |
| 1910 // Not supported. | 1896 // Not supported. |
| 1911 } | 1897 } |
| 1912 | 1898 |
| 1913 FX_BOOL Field::print(IJS_Context* cc, | 1899 FX_BOOL Field::print(IJS_Context* cc, |
| 1914 CJS_PropValue& vp, | 1900 CJS_PropValue& vp, |
| 1915 CFX_WideString& sError) { | 1901 CFX_WideString& sError) { |
| 1916 CPDFSDK_InterForm* pInterForm = | 1902 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 1917 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 1918 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 1903 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 1919 if (FieldArray.empty()) | 1904 if (FieldArray.empty()) |
| 1920 return FALSE; | 1905 return FALSE; |
| 1921 | 1906 |
| 1922 if (vp.IsSetting()) { | 1907 if (vp.IsSetting()) { |
| 1923 if (!m_bCanSet) | 1908 if (!m_bCanSet) |
| 1924 return FALSE; | 1909 return FALSE; |
| 1925 | 1910 |
| 1926 bool bVP; | 1911 bool bVP; |
| 1927 vp >> bVP; | 1912 vp >> bVP; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2073 } else { | 2058 } else { |
| 2074 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, | 2059 Field::SetRect(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, |
| 2075 crRect); | 2060 crRect); |
| 2076 } | 2061 } |
| 2077 } else { | 2062 } else { |
| 2078 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 2063 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2079 if (FieldArray.empty()) | 2064 if (FieldArray.empty()) |
| 2080 return FALSE; | 2065 return FALSE; |
| 2081 | 2066 |
| 2082 CPDF_FormField* pFormField = FieldArray[0]; | 2067 CPDF_FormField* pFormField = FieldArray[0]; |
| 2083 CPDFSDK_InterForm* pInterForm = | 2068 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 2084 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 2085 CPDFSDK_Widget* pWidget = | 2069 CPDFSDK_Widget* pWidget = |
| 2086 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); | 2070 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); |
| 2087 if (!pWidget) | 2071 if (!pWidget) |
| 2088 return FALSE; | 2072 return FALSE; |
| 2089 | 2073 |
| 2090 CFX_FloatRect crRect = pWidget->GetRect(); | 2074 CFX_FloatRect crRect = pWidget->GetRect(); |
| 2091 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); | 2075 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); |
| 2092 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); | 2076 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); |
| 2093 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); | 2077 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); |
| 2094 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); | 2078 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); |
| 2095 | 2079 |
| 2096 CJS_Array rcArray; | 2080 CJS_Array rcArray; |
| 2097 rcArray.SetElement(pRuntime, 0, Upper_Leftx); | 2081 rcArray.SetElement(pRuntime, 0, Upper_Leftx); |
| 2098 rcArray.SetElement(pRuntime, 1, Upper_Lefty); | 2082 rcArray.SetElement(pRuntime, 1, Upper_Lefty); |
| 2099 rcArray.SetElement(pRuntime, 2, Lower_Rightx); | 2083 rcArray.SetElement(pRuntime, 2, Lower_Rightx); |
| 2100 rcArray.SetElement(pRuntime, 3, Lower_Righty); | 2084 rcArray.SetElement(pRuntime, 3, Lower_Righty); |
| 2101 vp << rcArray; | 2085 vp << rcArray; |
| 2102 } | 2086 } |
| 2103 return TRUE; | 2087 return TRUE; |
| 2104 } | 2088 } |
| 2105 | 2089 |
| 2106 void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 2090 void Field::SetRect(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 2107 const CFX_WideString& swFieldName, | 2091 const CFX_WideString& swFieldName, |
| 2108 int nControlIndex, | 2092 int nControlIndex, |
| 2109 const CFX_FloatRect& rect) { | 2093 const CFX_FloatRect& rect) { |
| 2110 CPDFSDK_InterForm* pInterForm = | 2094 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm(); |
| 2111 pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 2112 std::vector<CPDF_FormField*> FieldArray = | 2095 std::vector<CPDF_FormField*> FieldArray = |
| 2113 GetFormFields(pFormFillEnv, swFieldName); | 2096 GetFormFields(pFormFillEnv, swFieldName); |
| 2114 for (CPDF_FormField* pFormField : FieldArray) { | 2097 for (CPDF_FormField* pFormField : FieldArray) { |
| 2115 if (nControlIndex < 0) { | 2098 if (nControlIndex < 0) { |
| 2116 FX_BOOL bSet = FALSE; | 2099 FX_BOOL bSet = FALSE; |
| 2117 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { | 2100 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
| 2118 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 2101 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
| 2119 ASSERT(pFormControl); | 2102 ASSERT(pFormControl); |
| 2120 | 2103 |
| 2121 if (CPDFSDK_Widget* pWidget = | 2104 if (CPDFSDK_Widget* pWidget = |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3209 CFX_WideString& sError) { | 3192 CFX_WideString& sError) { |
| 3210 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3193 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3211 if (FieldArray.empty()) | 3194 if (FieldArray.empty()) |
| 3212 return FALSE; | 3195 return FALSE; |
| 3213 | 3196 |
| 3214 CPDF_FormField* pFormField = FieldArray[0]; | 3197 CPDF_FormField* pFormField = FieldArray[0]; |
| 3215 int32_t nCount = pFormField->CountControls(); | 3198 int32_t nCount = pFormField->CountControls(); |
| 3216 if (nCount < 1) | 3199 if (nCount < 1) |
| 3217 return FALSE; | 3200 return FALSE; |
| 3218 | 3201 |
| 3219 CPDFSDK_InterForm* pInterForm = | 3202 CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); |
| 3220 m_pFormFillEnv->GetSDKDocument()->GetInterForm(); | |
| 3221 CPDFSDK_Widget* pWidget = nullptr; | 3203 CPDFSDK_Widget* pWidget = nullptr; |
| 3222 if (nCount == 1) { | 3204 if (nCount == 1) { |
| 3223 pWidget = pInterForm->GetWidget(pFormField->GetControl(0), false); | 3205 pWidget = pInterForm->GetWidget(pFormField->GetControl(0), false); |
| 3224 } else { | 3206 } else { |
| 3225 UnderlyingPageType* pPage = | 3207 UnderlyingPageType* pPage = |
| 3226 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage( | 3208 UnderlyingFromFPDFPage(m_pFormFillEnv->GetCurrentPage( |
| 3227 m_pFormFillEnv->GetUnderlyingDocument())); | 3209 m_pFormFillEnv->GetUnderlyingDocument())); |
| 3228 if (!pPage) | 3210 if (!pPage) |
| 3229 return FALSE; | 3211 return FALSE; |
| 3230 if (CPDFSDK_PageView* pCurPageView = | 3212 if (CPDFSDK_PageView* pCurPageView = |
| 3231 m_pFormFillEnv->GetSDKDocument()->GetPageView(pPage, true)) { | 3213 m_pFormFillEnv->GetPageView(pPage, true)) { |
| 3232 for (int32_t i = 0; i < nCount; i++) { | 3214 for (int32_t i = 0; i < nCount; i++) { |
| 3233 if (CPDFSDK_Widget* pTempWidget = | 3215 if (CPDFSDK_Widget* pTempWidget = |
| 3234 pInterForm->GetWidget(pFormField->GetControl(i), false)) { | 3216 pInterForm->GetWidget(pFormField->GetControl(i), false)) { |
| 3235 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) { | 3217 if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) { |
| 3236 pWidget = pTempWidget; | 3218 pWidget = pTempWidget; |
| 3237 break; | 3219 break; |
| 3238 } | 3220 } |
| 3239 } | 3221 } |
| 3240 } | 3222 } |
| 3241 } | 3223 } |
| 3242 } | 3224 } |
| 3243 | 3225 |
| 3244 if (pWidget) { | 3226 if (pWidget) { |
| 3245 CPDFSDK_Annot::ObservedPtr pObserved(pWidget); | 3227 CPDFSDK_Annot::ObservedPtr pObserved(pWidget); |
| 3246 m_pFormFillEnv->GetSDKDocument()->SetFocusAnnot(&pObserved); | 3228 m_pFormFillEnv->SetFocusAnnot(&pObserved); |
| 3247 } | 3229 } |
| 3248 | 3230 |
| 3249 return TRUE; | 3231 return TRUE; |
| 3250 } | 3232 } |
| 3251 | 3233 |
| 3252 FX_BOOL Field::setItems(IJS_Context* cc, | 3234 FX_BOOL Field::setItems(IJS_Context* cc, |
| 3253 const std::vector<CJS_Value>& params, | 3235 const std::vector<CJS_Value>& params, |
| 3254 CJS_Value& vRet, | 3236 CJS_Value& vRet, |
| 3255 CFX_WideString& sError) { | 3237 CFX_WideString& sError) { |
| 3256 return TRUE; | 3238 return TRUE; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3513 } | 3495 } |
| 3514 } | 3496 } |
| 3515 | 3497 |
| 3516 void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 3498 void Field::AddField(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
| 3517 int nPageIndex, | 3499 int nPageIndex, |
| 3518 int nFieldType, | 3500 int nFieldType, |
| 3519 const CFX_WideString& sName, | 3501 const CFX_WideString& sName, |
| 3520 const CFX_FloatRect& rcCoords) { | 3502 const CFX_FloatRect& rcCoords) { |
| 3521 // Not supported. | 3503 // Not supported. |
| 3522 } | 3504 } |
| OLD | NEW |