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 static bool SetWidgetDisplayStatus(CPDFSDK_Widget* pWidget, int value) { |
| 30 if (!pWidget) |
| 31 return false; |
| 32 |
| 33 uint32_t dwFlag = pWidget->GetFlags(); |
| 34 switch (value) { |
| 35 case 0: |
| 36 dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 37 dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 38 dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 39 dwFlag |= ANNOTFLAG_PRINT; |
| 40 break; |
| 41 case 1: |
| 42 dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 43 dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 44 dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT); |
| 45 break; |
| 46 case 2: |
| 47 dwFlag &= (~ANNOTFLAG_INVISIBLE); |
| 48 dwFlag &= (~ANNOTFLAG_PRINT); |
| 49 dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 50 dwFlag &= (~ANNOTFLAG_NOVIEW); |
| 51 break; |
| 52 case 3: |
| 53 dwFlag |= ANNOTFLAG_NOVIEW; |
| 54 dwFlag |= ANNOTFLAG_PRINT; |
| 55 dwFlag &= (~ANNOTFLAG_HIDDEN); |
| 56 break; |
| 57 } |
| 58 |
| 59 if (dwFlag != pWidget->GetFlags()) { |
| 60 pWidget->SetFlags(dwFlag); |
| 61 return true; |
| 62 } |
| 63 |
| 64 return false; |
| 65 } |
| 66 |
29 BEGIN_JS_STATIC_CONST(CJS_Field) | 67 BEGIN_JS_STATIC_CONST(CJS_Field) |
30 END_JS_STATIC_CONST() | 68 END_JS_STATIC_CONST() |
31 | 69 |
32 BEGIN_JS_STATIC_PROP(CJS_Field) | 70 BEGIN_JS_STATIC_PROP(CJS_Field) |
33 JS_STATIC_PROP_ENTRY(alignment) | 71 JS_STATIC_PROP_ENTRY(alignment) |
34 JS_STATIC_PROP_ENTRY(borderStyle) | 72 JS_STATIC_PROP_ENTRY(borderStyle) |
35 JS_STATIC_PROP_ENTRY(buttonAlignX) | 73 JS_STATIC_PROP_ENTRY(buttonAlignX) |
36 JS_STATIC_PROP_ENTRY(buttonAlignY) | 74 JS_STATIC_PROP_ENTRY(buttonAlignY) |
37 JS_STATIC_PROP_ENTRY(buttonFitBounds) | 75 JS_STATIC_PROP_ENTRY(buttonFitBounds) |
38 JS_STATIC_PROP_ENTRY(buttonPosition) | 76 JS_STATIC_PROP_ENTRY(buttonPosition) |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); | 1275 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
1238 std::vector<CPDF_FormField*> FieldArray = | 1276 std::vector<CPDF_FormField*> FieldArray = |
1239 GetFormFields(pDocument, swFieldName); | 1277 GetFormFields(pDocument, swFieldName); |
1240 for (CPDF_FormField* pFormField : FieldArray) { | 1278 for (CPDF_FormField* pFormField : FieldArray) { |
1241 if (nControlIndex < 0) { | 1279 if (nControlIndex < 0) { |
1242 FX_BOOL bSet = FALSE; | 1280 FX_BOOL bSet = FALSE; |
1243 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { | 1281 for (int i = 0, sz = pFormField->CountControls(); i < sz; ++i) { |
1244 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 1282 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
1245 ASSERT(pFormControl); | 1283 ASSERT(pFormControl); |
1246 | 1284 |
1247 if (CPDFSDK_Widget* pWidget = | 1285 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); |
1248 pInterForm->GetWidget(pFormControl, true)) { | 1286 bSet = SetWidgetDisplayStatus(pWidget, number); |
1249 uint32_t dwFlag = pWidget->GetFlags(); | |
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 } | 1287 } |
1281 | 1288 |
1282 if (bSet) | 1289 if (bSet) |
1283 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); | 1290 UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); |
1284 } else { | 1291 } else { |
1285 if (nControlIndex >= pFormField->CountControls()) | 1292 if (nControlIndex >= pFormField->CountControls()) |
1286 return; | 1293 return; |
1287 if (CPDF_FormControl* pFormControl = | 1294 |
1288 pFormField->GetControl(nControlIndex)) { | 1295 CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex); |
1289 if (CPDFSDK_Widget* pWidget = | 1296 if (!pFormControl) |
1290 pInterForm->GetWidget(pFormControl, true)) { | 1297 return; |
1291 uint32_t dwFlag = pWidget->GetFlags(); | 1298 |
1292 switch (number) { | 1299 CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl, true); |
1293 case 0: | 1300 if (SetWidgetDisplayStatus(pWidget, number)) |
1294 dwFlag &= (~ANNOTFLAG_INVISIBLE); | 1301 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 } | 1302 } |
1323 } | 1303 } |
1324 } | 1304 } |
1325 | 1305 |
1326 FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { | 1306 FX_BOOL Field::doc(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { |
1327 if (!vp.IsGetting()) { | 1307 if (!vp.IsGetting()) { |
1328 return FALSE; | 1308 return FALSE; |
1329 } | 1309 } |
1330 vp << m_pJSDoc->GetCJSDoc(); | 1310 vp << m_pJSDoc->GetCJSDoc(); |
1331 return TRUE; | 1311 return TRUE; |
(...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3540 } | 3520 } |
3541 } | 3521 } |
3542 | 3522 |
3543 void Field::AddField(CPDFSDK_Document* pDocument, | 3523 void Field::AddField(CPDFSDK_Document* pDocument, |
3544 int nPageIndex, | 3524 int nPageIndex, |
3545 int nFieldType, | 3525 int nFieldType, |
3546 const CFX_WideString& sName, | 3526 const CFX_WideString& sName, |
3547 const CFX_FloatRect& rcCoords) { | 3527 const CFX_FloatRect& rcCoords) { |
3548 // Not supported. | 3528 // Not supported. |
3549 } | 3529 } |
OLD | NEW |