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/fpdf_font/include/cpdf_font.h" | 14 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
15 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 15 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
16 #include "core/fpdfdoc/include/cpdf_interform.h" | 16 #include "core/fpdfdoc/include/cpdf_interform.h" |
17 #include "fpdfsdk/include/fsdk_mgr.h" | 17 #include "fpdfsdk/include/fsdk_mgr.h" |
18 #include "fpdfsdk/javascript/Document.h" | 18 #include "fpdfsdk/javascript/Document.h" |
19 #include "fpdfsdk/javascript/Icon.h" | 19 #include "fpdfsdk/javascript/Icon.h" |
20 #include "fpdfsdk/javascript/JS_Define.h" | 20 #include "fpdfsdk/javascript/JS_Define.h" |
21 #include "fpdfsdk/javascript/JS_EventHandler.h" | 21 #include "fpdfsdk/javascript/JS_EventHandler.h" |
22 #include "fpdfsdk/javascript/JS_Object.h" | 22 #include "fpdfsdk/javascript/JS_Object.h" |
23 #include "fpdfsdk/javascript/JS_Value.h" | 23 #include "fpdfsdk/javascript/JS_Value.h" |
24 #include "fpdfsdk/javascript/PublicMethods.h" | 24 #include "fpdfsdk/javascript/PublicMethods.h" |
25 #include "fpdfsdk/javascript/cjs_context.h" | 25 #include "fpdfsdk/javascript/cjs_context.h" |
26 #include "fpdfsdk/javascript/cjs_runtime.h" | 26 #include "fpdfsdk/javascript/cjs_runtime.h" |
27 #include "fpdfsdk/javascript/color.h" | 27 #include "fpdfsdk/javascript/color.h" |
28 | 28 |
| 29 namespace { |
| 30 |
| 31 bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) { |
| 32 if (!pWidget) |
| 33 return false; |
| 34 |
| 35 uint32_t dwFlag = pWidget->GetFlags(); |
| 36 switch (value) { |
| 37 case 0: |
| 38 dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 39 dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 40 dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 41 dwFlag |= ANNOTFLAG_PRINT; |
| 42 break; |
| 43 case 1: |
| 44 dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 45 dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 46 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 47 break; |
| 48 case 2: |
| 49 dwFlag &= ~ANNOTFLAG_INVISIBLE; |
| 50 dwFlag &= ~ANNOTFLAG_PRINT; |
| 51 dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 52 dwFlag &= ~ANNOTFLAG_NOVIEW; |
| 53 break; |
| 54 case 3: |
| 55 dwFlag |= ANNOTFLAG_NOVIEW; |
| 56 dwFlag |= ANNOTFLAG_PRINT; |
| 57 dwFlag &= ~ANNOTFLAG_HIDDEN; |
| 58 break; |
| 59 } |
| 60 |
| 61 if (dwFlag != pWidget->GetFlags()) { |
| 62 pWidget->SetFlags(dwFlag); |
| 63 return true; |
| 64 } |
| 65 |
| 66 return false; |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
29 BEGIN_JS_STATIC_CONST(CJS_Field) | 71 BEGIN_JS_STATIC_CONST(CJS_Field) |
30 END_JS_STATIC_CONST() | 72 END_JS_STATIC_CONST() |
31 | 73 |
32 BEGIN_JS_STATIC_PROP(CJS_Field) | 74 BEGIN_JS_STATIC_PROP(CJS_Field) |
33 JS_STATIC_PROP_ENTRY(alignment) | 75 JS_STATIC_PROP_ENTRY(alignment) |
34 JS_STATIC_PROP_ENTRY(borderStyle) | 76 JS_STATIC_PROP_ENTRY(borderStyle) |
35 JS_STATIC_PROP_ENTRY(buttonAlignX) | 77 JS_STATIC_PROP_ENTRY(buttonAlignX) |
36 JS_STATIC_PROP_ENTRY(buttonAlignY) | 78 JS_STATIC_PROP_ENTRY(buttonAlignY) |
37 JS_STATIC_PROP_ENTRY(buttonFitBounds) | 79 JS_STATIC_PROP_ENTRY(buttonFitBounds) |
38 JS_STATIC_PROP_ENTRY(buttonPosition) | 80 JS_STATIC_PROP_ENTRY(buttonPosition) |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 | 1274 |
1233 void Field::SetDisplay(CPDFSDK_Document* pDocument, | 1275 void Field::SetDisplay(CPDFSDK_Document* pDocument, |
1234 const CFX_WideString& swFieldName, | 1276 const CFX_WideString& swFieldName, |
1235 int nControlIndex, | 1277 int nControlIndex, |
1236 int number) { | 1278 int number) { |
1237 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); | 1279 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
1238 std::vector<CPDF_FormField*> FieldArray = | 1280 std::vector<CPDF_FormField*> FieldArray = |
1239 GetFormFields(pDocument, swFieldName); | 1281 GetFormFields(pDocument, swFieldName); |
1240 for (CPDF_FormField* pFormField : FieldArray) { | 1282 for (CPDF_FormField* pFormField : FieldArray) { |
1241 if (nControlIndex < 0) { | 1283 if (nControlIndex < 0) { |
1242 FX_BOOL bSet = FALSE; | 1284 bool bAnySet = false; |
1243 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { | 1285 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
1244 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 1286 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
1245 ASSERT(pFormControl); | 1287 ASSERT(pFormControl); |
1246 | 1288 |
1247 if (CPDFSDK_Widget* pWidget = | 1289 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); |
1248 pInterForm->GetWidget(pFormControl, true)) { | 1290 if (SetWidgetDisplayStatus(pWidget, number)) |
1249 uint32_t dwFlag = pWidget->GetFlags(); | 1291 bAnySet = true; |
1250 switch (number) { | |
1251 case 0: | |
1252 dwFlag &= (~ANNOTFLAG_INVISIBLE); | |
1253 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1254 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1255 dwFlag |= ANNOTFLAG_PRINT; | |
1256 break; | |
1257 case 1: | |
1258 dwFlag &= (~ANNOTFLAG_INVISIBLE); | |
1259 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1260 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); | |
1261 break; | |
1262 case 2: | |
1263 dwFlag &= (~ANNOTFLAG_INVISIBLE); | |
1264 dwFlag &= (~ANNOTFLAG_PRINT); | |
1265 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1266 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1267 break; | |
1268 case 3: | |
1269 dwFlag |= ANNOTFLAG_NOVIEW; | |
1270 dwFlag |= ANNOTFLAG_PRINT; | |
1271 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1272 break; | |
1273 } | |
1274 | |
1275 if (dwFlag != pWidget->GetFlags()) { | |
1276 pWidget->SetFlags(dwFlag); | |
1277 bSet = TRUE; | |
1278 } | |
1279 } | |
1280 } | 1292 } |
1281 | 1293 |
1282 if (bSet) | 1294 if (bAnySet) |
1283 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); | 1295 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
1284 } else { | 1296 } else { |
1285 if (nControlIndex >= pFormField->CountControls()) | 1297 if (nControlIndex >= pFormField->CountControls()) |
1286 return; | 1298 return; |
1287 if (CPDF_FormControl* pFormControl = | 1299 |
1288 pFormField->GetControl(nControlIndex)) { | 1300 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex); |
1289 if (CPDFSDK_Widget* pWidget = | 1301 if (!pFormControl) |
1290 pInterForm->GetWidget(pFormControl, true)) { | 1302 return; |
1291 uint32_t dwFlag = pWidget->GetFlags(); | 1303 |
1292 switch (number) { | 1304 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); |
1293 case 0: | 1305 if (SetWidgetDisplayStatus(pWidget, number)) |
1294 dwFlag &= (~ANNOTFLAG_INVISIBLE); | 1306 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); |
1295 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1296 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1297 dwFlag |= ANNOTFLAG_PRINT; | |
1298 break; | |
1299 case 1: | |
1300 dwFlag &= (~ANNOTFLAG_INVISIBLE); | |
1301 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1302 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); | |
1303 break; | |
1304 case 2: | |
1305 dwFlag &= (~ANNOTFLAG_INVISIBLE); | |
1306 dwFlag &= (~ANNOTFLAG_PRINT); | |
1307 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1308 dwFlag &= (~ANNOTFLAG_NOVIEW); | |
1309 break; | |
1310 case 3: | |
1311 dwFlag |= ANNOTFLAG_NOVIEW; | |
1312 dwFlag |= ANNOTFLAG_PRINT; | |
1313 dwFlag &= (~ANNOTFLAG_HIDDEN); | |
1314 break; | |
1315 } | |
1316 if (dwFlag != pWidget->GetFlags()) { | |
1317 pWidget->SetFlags(dwFlag); | |
1318 UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE); | |
1319 } | |
1320 } | |
1321 } | |
1322 } | 1307 } |
1323 } | 1308 } |
1324 } | 1309 } |
1325 | 1310 |
1326 FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 1311 FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
1327 if (!vp.IsGetting()) { | 1312 if (!vp.IsGetting()) { |
1328 return FALSE; | 1313 return FALSE; |
1329 } | 1314 } |
1330 vp << m_pJSDoc->GetCJSDoc(); | 1315 vp << m_pJSDoc->GetCJSDoc(); |
1331 return TRUE; | 1316 return TRUE; |
(...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 } | 3525 } |
3541 } | 3526 } |
3542 | 3527 |
3543 void Field::AddField(CPDFSDK_Document* pDocument, | 3528 void Field::AddField(CPDFSDK_Document* pDocument, |
3544 int nPageIndex, | 3529 int nPageIndex, |
3545 int nFieldType, | 3530 int nFieldType, |
3546 const CFX_WideString& sName, | 3531 const CFX_WideString& sName, |
3547 const CFX_FloatRect& rcCoords) { | 3532 const CFX_FloatRect& rcCoords) { |
3548 // Not supported. | 3533 // Not supported. |
3549 } | 3534 } |
OLD | NEW |