blob: df8b839bb11c85badc78af910024a9609fb3707a [file] [log] [blame]
Lei Zhang94293682016-01-27 18:27:56 -08001// 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.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/include/fsdk_define.h"
8#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
9#include "fpdfsdk/include/fsdk_mgr.h"
10#include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h"
11#include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h"
12#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
13#include "fpdfsdk/include/javascript/IJavaScript.h"
14#include "public/fpdf_formfill.h"
15
16#define IDS_XFA_Validate_Input \
17 "At least one required field was empty. Please fill in the required " \
18 "fields\r\n(highlighted) before continuing."
19
20// submit
21#define FXFA_CONFIG 0x00000001
22#define FXFA_TEMPLATE 0x00000010
23#define FXFA_LOCALESET 0x00000100
24#define FXFA_DATASETS 0x00001000
25#define FXFA_XMPMETA 0x00010000
26#define FXFA_XFDF 0x00100000
27#define FXFA_FORM 0x01000000
28#define FXFA_PDF 0x10000000
29
30#ifndef _WIN32
31extern void SetLastError(int err);
32
33extern int GetLastError();
34#endif
35
36CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc,
37 CPDFXFA_App* pProvider)
38 : m_iDocType(DOCTYPE_PDF),
39 m_pPDFDoc(pPDFDoc),
40 m_pSDKDoc(nullptr),
41 m_pXFADoc(nullptr),
42 m_pXFADocView(nullptr),
43 m_pApp(pProvider),
44 m_pJSContext(nullptr) {
45}
46
47CPDFXFA_Document::~CPDFXFA_Document() {
Jun Fang23bf5602016-02-01 20:29:55 -080048 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv())
49 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
50
51 delete m_pSDKDoc;
52
Lei Zhang94293682016-01-27 18:27:56 -080053 if (m_pPDFDoc) {
54 CPDF_Parser* pParser = m_pPDFDoc->GetParser();
55 if (pParser)
56 delete pParser;
57 else
58 delete m_pPDFDoc;
59 }
Jun Fang23bf5602016-02-01 20:29:55 -080060 if (m_pXFADoc) {
61 IXFA_App* pApp = m_pApp->GetXFAApp();
62 if (pApp) {
63 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();
64 if (pDocHandler) {
65 CloseXFADoc(pDocHandler);
66 }
67 }
68 delete m_pXFADoc;
69 }
Lei Zhang94293682016-01-27 18:27:56 -080070}
71
72FX_BOOL CPDFXFA_Document::LoadXFADoc() {
73 if (!m_pPDFDoc)
74 return FALSE;
75
76 m_XFAPageList.RemoveAll();
77
78 IXFA_App* pApp = m_pApp->GetXFAApp();
79 if (!pApp)
80 return FALSE;
81
82 m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc);
83 if (!m_pXFADoc) {
84 SetLastError(FPDF_ERR_XFALOAD);
85 return FALSE;
86 }
87
88 IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();
89 if (!pDocHandler) {
90 SetLastError(FPDF_ERR_XFALOAD);
91 return FALSE;
92 }
93
94 pDocHandler->StartLoad(m_pXFADoc);
95 int iStatus = pDocHandler->DoLoad(m_pXFADoc, NULL);
96 if (iStatus != XFA_PARSESTATUS_Done) {
97 CloseXFADoc(pDocHandler);
98 SetLastError(FPDF_ERR_XFALOAD);
99 return FALSE;
100 }
101 pDocHandler->StopLoad(m_pXFADoc);
102 pDocHandler->SetJSERuntime(m_pXFADoc, m_pApp->GetJSERuntime());
103
104 if (pDocHandler->GetDocType(m_pXFADoc) == XFA_DOCTYPE_Dynamic)
105 m_iDocType = DOCTYPE_DYNAMIC_XFA;
106 else
107 m_iDocType = DOCTYPE_STATIC_XFA;
108
109 m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View);
110 if (m_pXFADocView->StartLayout() < 0) {
111 CloseXFADoc(pDocHandler);
112 SetLastError(FPDF_ERR_XFALAYOUT);
113 return FALSE;
114 }
115
116 m_pXFADocView->DoLayout(NULL);
117 m_pXFADocView->StopLayout();
118 return TRUE;
119}
120
121int CPDFXFA_Document::GetPageCount() {
122 if (!m_pPDFDoc && !m_pXFADoc)
123 return 0;
124
125 switch (m_iDocType) {
126 case DOCTYPE_PDF:
127 case DOCTYPE_STATIC_XFA:
128 if (m_pPDFDoc)
129 return m_pPDFDoc->GetPageCount();
130 case DOCTYPE_DYNAMIC_XFA:
131 if (m_pXFADoc)
132 return m_pXFADocView->CountPageViews();
133 default:
134 return 0;
135 }
136
137 return 0;
138}
139
140CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index) {
141 if (page_index < 0)
142 return nullptr;
143 CPDFXFA_Page* pPage = nullptr;
144 int nCount = m_XFAPageList.GetSize();
145 if (nCount > 0 && page_index < nCount) {
146 pPage = m_XFAPageList.GetAt(page_index);
147 if (pPage)
148 pPage->AddRef();
149 } else {
150 m_XFAPageList.SetSize(GetPageCount());
151 }
152 if (pPage)
153 return pPage;
154 pPage = new CPDFXFA_Page(this, page_index);
155 if (!pPage->LoadPage()) {
156 delete pPage;
157 return nullptr;
158 }
159 m_XFAPageList.SetAt(page_index, pPage);
160 return pPage;
161}
162
163CPDFXFA_Page* CPDFXFA_Document::GetPage(IXFA_PageView* pPage) {
164 if (!pPage)
165 return NULL;
166
167 if (!m_pXFADoc)
168 return NULL;
169
170 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
171 return NULL;
172
173 int nSize = m_XFAPageList.GetSize();
174 for (int i = 0; i < nSize; i++) {
175 CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i);
176 if (!pTempPage)
177 continue;
178 if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage)
179 return pTempPage;
180 }
181
182 return NULL;
183}
184
185void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page) {
186 m_XFAPageList.SetAt(page->GetPageIndex(), NULL);
187}
188
189CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument(
190 CPDFDoc_Environment* pFormFillEnv) {
191 if (!m_pSDKDoc && pFormFillEnv)
192 m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv);
193 return m_pSDKDoc;
194}
195
196void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF,
197 CPDF_Rect& pdfRect) {
198 pdfRect.left = fxRectF.left;
199 pdfRect.top = fxRectF.bottom();
200 pdfRect.right = fxRectF.right();
201 pdfRect.bottom = fxRectF.top;
202}
203
204void CPDFXFA_Document::SetChangeMark(IXFA_Doc* hDoc) {
205 if (hDoc == m_pXFADoc && m_pSDKDoc) {
206 m_pSDKDoc->SetChangeMark();
207 }
208}
209
210FX_BOOL CPDFXFA_Document::GetChangeMark(IXFA_Doc* hDoc) {
211 if (hDoc == m_pXFADoc && m_pSDKDoc)
212 return m_pSDKDoc->GetChangeMark();
213 return FALSE;
214}
215
216void CPDFXFA_Document::InvalidateRect(IXFA_PageView* pPageView,
217 const CFX_RectF& rt,
218 FX_DWORD dwFlags /* = 0 */) {
219 if (!m_pXFADoc || !m_pSDKDoc)
220 return;
221
222 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
223 return;
224
225 CPDF_Rect rcPage;
226 FXRect2PDFRect(rt, rcPage);
227
228 CPDFXFA_Page* pPage = GetPage(pPageView);
229
230 if (pPage == NULL)
231 return;
232
233 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
234 if (!pEnv)
235 return;
236
237 pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom,
238 rcPage.right, rcPage.top);
239}
240
241void CPDFXFA_Document::InvalidateRect(IXFA_Widget* hWidget,
242 FX_DWORD dwFlags /* = 0 */) {
243 if (!hWidget)
244 return;
245
246 if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView)
247 return;
248
249 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
250 return;
251
252 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
253 if (!pWidgetHandler)
254 return;
255
256 IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget);
257 if (!pPageView)
258 return;
259
260 CFX_RectF rect;
261 pWidgetHandler->GetRect(hWidget, rect);
262 InvalidateRect(pPageView, rect, dwFlags);
263}
264
265void CPDFXFA_Document::DisplayCaret(IXFA_Widget* hWidget,
266 FX_BOOL bVisible,
267 const CFX_RectF* pRtAnchor) {
268 if (!hWidget || pRtAnchor == NULL)
269 return;
270
271 if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView)
272 return;
273
274 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
275 return;
276
277 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
278 if (!pWidgetHandler)
279 return;
280
281 IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget);
282 if (!pPageView)
283 return;
284
285 CPDFXFA_Page* pPage = GetPage(pPageView);
286
287 if (pPage == NULL)
288 return;
289
290 CPDF_Rect rcCaret;
291 FXRect2PDFRect(*pRtAnchor, rcCaret);
292
293 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
294 if (!pEnv)
295 return;
296
297 pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top,
298 rcCaret.right, rcCaret.bottom);
299}
300
301FX_BOOL CPDFXFA_Document::GetPopupPos(IXFA_Widget* hWidget,
302 FX_FLOAT fMinPopup,
303 FX_FLOAT fMaxPopup,
304 const CFX_RectF& rtAnchor,
305 CFX_RectF& rtPopup) {
306 if (NULL == hWidget) {
307 return FALSE;
308 }
309 IXFA_PageView* pXFAPageView =
310 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
311 if (NULL == pXFAPageView) {
312 return FALSE;
313 }
314 CPDFXFA_Page* pPage = GetPage(pXFAPageView);
315 if (pPage == NULL)
316 return FALSE;
317
318 CXFA_WidgetAcc* pWidgetAcc =
319 m_pXFADocView->GetWidgetHandler()->GetDataAcc(hWidget);
320
321 int nRotate = 0;
322#ifdef PDF_ENABLE_XFA
323 nRotate = pWidgetAcc->GetRotate();
324#endif
325
326 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
327 if (pEnv == NULL)
328 return FALSE;
329 FS_RECTF pageViewRect;
330 pEnv->FFI_GetPageViewRect(pPage, pageViewRect);
331
332 CPDF_Rect rcAnchor;
333
334 rcAnchor.left = rtAnchor.left;
335 rcAnchor.top = rtAnchor.bottom();
336 rcAnchor.right = rtAnchor.right();
337 rcAnchor.bottom = rtAnchor.top;
338
339 int t1, t2, t;
340 FX_DWORD dwPos;
341 FX_FLOAT fPoupHeight;
342 switch (nRotate) {
343 case 90: {
344 t1 = (int)(pageViewRect.right - rcAnchor.right);
345 t2 = (int)(rcAnchor.left - pageViewRect.left);
346 if (rcAnchor.bottom < pageViewRect.bottom) {
347 rtPopup.left += rcAnchor.bottom - pageViewRect.bottom;
348 }
349
350 break;
351 }
352
353 case 180: {
354 t2 = (int)(pageViewRect.top - rcAnchor.top);
355 t1 = (int)(rcAnchor.bottom - pageViewRect.bottom);
356 if (rcAnchor.left < pageViewRect.left) {
357 rtPopup.left += rcAnchor.left - pageViewRect.left;
358 }
359 break;
360 }
361 case 270: {
362 t1 = (int)(rcAnchor.left - pageViewRect.left);
363 t2 = (int)(pageViewRect.right - rcAnchor.right);
364
365 if (rcAnchor.top > pageViewRect.top) {
366 rtPopup.left -= rcAnchor.top - pageViewRect.top;
367 }
368 break;
369 }
370 case 0:
371 default: {
372 t1 = (int)(pageViewRect.top - rcAnchor.top);
373 t2 = (int)(rcAnchor.bottom - pageViewRect.bottom);
374 if (rcAnchor.right > pageViewRect.right) {
375 rtPopup.left -= rcAnchor.right - pageViewRect.right;
376 }
377 break;
378 }
379 }
380
381 if (t1 <= 0 && t2 <= 0) {
382 return FALSE;
383 }
384 if (t1 <= 0) {
385 t = t2;
386 dwPos = 1;
387 } else if (t2 <= 0) {
388 t = t1;
389 dwPos = 0;
390 } else if (t1 > t2) {
391 t = t1;
392 dwPos = 0;
393 } else {
394 t = t2;
395 dwPos = 1;
396 }
397 if (t < fMinPopup) {
398 fPoupHeight = fMinPopup;
399 } else if (t > fMaxPopup) {
400 fPoupHeight = fMaxPopup;
401 } else {
402 fPoupHeight = (FX_FLOAT)t;
403 }
404
405 switch (nRotate) {
406 case 0:
407 case 180: {
408 if (dwPos == 0) {
409 rtPopup.top = rtAnchor.height;
410 rtPopup.height = fPoupHeight;
411 } else {
412 rtPopup.top = -fPoupHeight;
413 rtPopup.height = fPoupHeight;
414 }
415 break;
416 }
417 case 90:
418 case 270: {
419 if (dwPos == 0) {
420 rtPopup.top = rtAnchor.width;
421 rtPopup.height = fPoupHeight;
422 } else {
423 rtPopup.top = -fPoupHeight;
424 rtPopup.height = fPoupHeight;
425 }
426 break;
427 }
428 default:
429 break;
430 }
431
432 return TRUE;
433}
434
435FX_BOOL CPDFXFA_Document::PopupMenu(IXFA_Widget* hWidget,
436 CFX_PointF ptPopup,
437 const CFX_RectF* pRectExclude) {
438 if (NULL == hWidget) {
439 return FALSE;
440 }
441 IXFA_PageView* pXFAPageView =
442 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
443 if (pXFAPageView == NULL)
444 return FALSE;
445 CPDFXFA_Page* pPage = GetPage(pXFAPageView);
446
447 if (pPage == NULL)
448 return FALSE;
449
450 int menuFlag = 0;
451
452 IXFA_MenuHandler* pXFAMenuHander = m_pApp->GetXFAApp()->GetMenuHandler();
453 if (pXFAMenuHander->CanUndo(hWidget))
454 menuFlag |= FXFA_MEMU_UNDO;
455 if (pXFAMenuHander->CanRedo(hWidget))
456 menuFlag |= FXFA_MEMU_REDO;
457 if (pXFAMenuHander->CanPaste(hWidget))
458 menuFlag |= FXFA_MEMU_PASTE;
459 if (pXFAMenuHander->CanCopy(hWidget))
460 menuFlag |= FXFA_MEMU_COPY;
461 if (pXFAMenuHander->CanCut(hWidget))
462 menuFlag |= FXFA_MEMU_CUT;
463 if (pXFAMenuHander->CanSelectAll(hWidget))
464 menuFlag |= FXFA_MEMU_SELECTALL;
465
466 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
467 if (pEnv == NULL)
468 return FALSE;
469
470 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL);
471}
472
473void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView,
474 FX_DWORD dwFlags) {
475 if (!pPageView || (dwFlags != XFA_PAGEVIEWEVENT_PostAdded &&
476 dwFlags != XFA_PAGEVIEWEVENT_PostRemoved)) {
477 return;
478 }
479 CPDFXFA_Page* pPage = nullptr;
480 if (dwFlags == XFA_PAGEVIEWEVENT_PostAdded) {
481 pPage = GetPage(pPageView->GetPageViewIndex());
482 if (pPage)
483 pPage->SetXFAPageView(pPageView);
484 return;
485 }
486 pPage = GetPage(pPageView);
487 if (!pPage)
488 return;
489 pPage->SetXFAPageView(nullptr);
Jun Fang23bf5602016-02-01 20:29:55 -0800490 m_pSDKDoc->GetPageView(pPage)->ClearFXAnnots();
Lei Zhang94293682016-01-27 18:27:56 -0800491}
492
493void CPDFXFA_Document::WidgetEvent(IXFA_Widget* hWidget,
494 CXFA_WidgetAcc* pWidgetData,
495 FX_DWORD dwEvent,
496 void* pParam,
497 void* pAdditional) {
498 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget)
499 return;
500
501 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
502 if (!pEnv)
503 return;
504
505 IXFA_PageView* pPageView =
506 m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
507 if (pPageView == NULL)
508 return;
509
510 CPDFXFA_Page* pXFAPage = GetPage(pPageView);
511 if (pXFAPage == NULL)
512 return;
513
514 CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage);
515 if (dwEvent == XFA_WIDGETEVENT_PostAdded) {
516 pSdkPageView->AddAnnot(hWidget);
517
518 } else if (dwEvent == XFA_WIDGETEVENT_PreRemoved) {
519 CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget);
520 if (pAnnot) {
521 pSdkPageView->DeleteAnnot(pAnnot);
522 }
523 }
524}
525
526int32_t CPDFXFA_Document::CountPages(IXFA_Doc* hDoc) {
527 if (hDoc == m_pXFADoc && m_pSDKDoc) {
528 return GetPageCount();
529 }
530 return 0;
531}
532int32_t CPDFXFA_Document::GetCurrentPage(IXFA_Doc* hDoc) {
533 if (hDoc != m_pXFADoc || !m_pSDKDoc)
534 return -1;
535 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
536 return -1;
537
538 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
539 if (pEnv == NULL)
540 return -1;
541
542 return pEnv->FFI_GetCurrentPageIndex(this);
543}
544void CPDFXFA_Document::SetCurrentPage(IXFA_Doc* hDoc, int32_t iCurPage) {
Jun Fang88780292016-02-02 17:19:57 -0800545 if (hDoc != m_pXFADoc || !m_pSDKDoc || m_iDocType != DOCTYPE_DYNAMIC_XFA ||
546 iCurPage < 0 || iCurPage >= m_pSDKDoc->GetPageCount()) {
Lei Zhang94293682016-01-27 18:27:56 -0800547 return;
Jun Fang88780292016-02-02 17:19:57 -0800548 }
Lei Zhang94293682016-01-27 18:27:56 -0800549 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Jun Fang88780292016-02-02 17:19:57 -0800550 if (!pEnv)
Lei Zhang94293682016-01-27 18:27:56 -0800551 return;
Lei Zhang94293682016-01-27 18:27:56 -0800552 pEnv->FFI_SetCurrentPage(this, iCurPage);
553}
554FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(IXFA_Doc* hDoc) {
555 if (hDoc != m_pXFADoc || !m_pSDKDoc)
556 return FALSE;
557 if (m_pSDKDoc->GetInterForm())
558 return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled();
559
560 return FALSE;
561}
562void CPDFXFA_Document::SetCalculationsEnabled(IXFA_Doc* hDoc,
563 FX_BOOL bEnabled) {
564 if (hDoc != m_pXFADoc || !m_pSDKDoc)
565 return;
566 if (m_pSDKDoc->GetInterForm())
567 m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled);
568}
569
570void CPDFXFA_Document::GetTitle(IXFA_Doc* hDoc, CFX_WideString& wsTitle) {
571 if (hDoc != m_pXFADoc)
572 return;
573 if (m_pPDFDoc == NULL)
574 return;
575 CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo();
576
577 if (pInfoDict == NULL)
578 return;
579
Wei Li9b761132016-01-29 15:44:20 -0800580 CFX_ByteString csTitle = pInfoDict->GetStringBy("Title");
Lei Zhang94293682016-01-27 18:27:56 -0800581 wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));
582 csTitle.ReleaseBuffer(csTitle.GetLength());
583}
584void CPDFXFA_Document::SetTitle(IXFA_Doc* hDoc,
585 const CFX_WideStringC& wsTitle) {
586 if (hDoc != m_pXFADoc)
587 return;
588 if (m_pPDFDoc == NULL)
589 return;
590 CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo();
591
592 if (pInfoDict == NULL)
593 return;
594 pInfoDict->SetAt("Title", new CPDF_String(wsTitle));
595}
596void CPDFXFA_Document::ExportData(IXFA_Doc* hDoc,
597 const CFX_WideStringC& wsFilePath,
598 FX_BOOL bXDP) {
599 if (hDoc != m_pXFADoc)
600 return;
601 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
602 return;
603 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
604 if (pEnv == NULL)
605 return;
606 int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML;
607 CFX_ByteString bs = CFX_WideString(wsFilePath).UTF16LE_Encode();
608
609 if (wsFilePath.IsEmpty()) {
610 if (!pEnv->GetFormFillInfo() ||
611 pEnv->GetFormFillInfo()->m_pJsPlatform == NULL)
612 return;
613 CFX_WideString filepath = pEnv->JS_fieldBrowse();
614 bs = filepath.UTF16LE_Encode();
615 }
616 int len = bs.GetLength() / sizeof(unsigned short);
617 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile(
618 bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
619 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "wb");
620 bs.ReleaseBuffer(len * sizeof(unsigned short));
621
622 if (pFileHandler == NULL)
623 return;
624
625 CFPDF_FileStream fileWrite(pFileHandler);
626
627 IXFA_DocHandler* pXFADocHander = m_pApp->GetXFAApp()->GetDocHandler();
628 CFX_ByteString content;
629 if (fileType == FXFA_SAVEAS_XML) {
630 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
631 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
632 content.GetLength());
633 CFX_WideStringC data(L"data");
634 if (pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite)) {
635 // TODO: Maybe report error.
636 }
637 } else if (fileType == FXFA_SAVEAS_XDP) {
638 if (m_pPDFDoc == NULL)
639 return;
640 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
641 if (pRoot == NULL)
642 return;
Wei Li9b761132016-01-29 15:44:20 -0800643 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
Lei Zhang94293682016-01-27 18:27:56 -0800644 if (NULL == pAcroForm)
645 return;
646 CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
647 if (pXFA == NULL)
648 return;
649 if (!pXFA->IsArray())
650 return;
651 CPDF_Array* pArray = pXFA->GetArray();
652 if (NULL == pArray)
653 return;
654 int size = pArray->GetCount();
655 for (int i = 1; i < size; i += 2) {
656 CPDF_Object* pPDFObj = pArray->GetElement(i);
657 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
658 if (!pPrePDFObj->IsString())
659 continue;
660 if (!pPDFObj->IsReference())
661 continue;
662 CPDF_Object* pDirectObj = pPDFObj->GetDirect();
663 if (!pDirectObj->IsStream())
664 continue;
665 if (pPrePDFObj->GetString() == "form") {
666 CFX_WideStringC form(L"form");
667 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), form, &fileWrite);
668 } else if (pPrePDFObj->GetString() == "datasets") {
669 CFX_WideStringC datasets(L"datasets");
670 pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), datasets,
671 &fileWrite);
672 } else {
673 if (i == size - 1) {
674 CFX_WideString wPath = CFX_WideString::FromUTF16LE(
675 (unsigned short*)(const FX_CHAR*)bs,
676 bs.GetLength() / sizeof(unsigned short));
677 CFX_ByteString bPath = wPath.UTF8Encode();
678 CFX_ByteString szFormat =
679 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
680 content.Format(szFormat, (char*)(const FX_CHAR*)bPath);
681 fileWrite.WriteBlock((const FX_CHAR*)content, fileWrite.GetSize(),
682 content.GetLength());
683 }
684
685 CPDF_Stream* pStream = (CPDF_Stream*)pDirectObj;
686 CPDF_StreamAcc* pAcc = new CPDF_StreamAcc;
687 pAcc->LoadAllData(pStream);
688 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(),
689 pAcc->GetSize());
690 delete pAcc;
691 }
692 }
693 }
694 if (!fileWrite.Flush()) {
695 // TODO: Report error.
696 }
697}
698void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc,
699 const CFX_WideStringC& wsFilePath) {
700 // TODO...
701}
702
703void CPDFXFA_Document::GotoURL(IXFA_Doc* hDoc,
704 const CFX_WideStringC& bsURL,
705 FX_BOOL bAppend) {
706 if (hDoc != m_pXFADoc)
707 return;
708
709 if (m_iDocType != DOCTYPE_DYNAMIC_XFA)
710 return;
711
712 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
713 if (pEnv == NULL)
714 return;
715
716 CFX_WideStringC str(bsURL.GetPtr());
717
718 pEnv->FFI_GotoURL(this, str, bAppend);
719}
720
721FX_BOOL CPDFXFA_Document::IsValidationsEnabled(IXFA_Doc* hDoc) {
722 if (hDoc != m_pXFADoc || !m_pSDKDoc)
723 return FALSE;
724 if (m_pSDKDoc->GetInterForm())
725 return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled();
726
727 return TRUE;
728}
729void CPDFXFA_Document::SetValidationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled) {
730 if (hDoc != m_pXFADoc || !m_pSDKDoc)
731 return;
732 if (m_pSDKDoc->GetInterForm())
733 m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled);
734}
735void CPDFXFA_Document::SetFocusWidget(IXFA_Doc* hDoc, IXFA_Widget* hWidget) {
736 if (hDoc != m_pXFADoc)
737 return;
738
739 if (NULL == hWidget) {
740 m_pSDKDoc->SetFocusAnnot(NULL);
741 return;
742 }
743
744 int pageViewCount = m_pSDKDoc->GetPageViewCount();
745 for (int i = 0; i < pageViewCount; i++) {
746 CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i);
747 if (pPageView == NULL)
748 continue;
749 CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget);
750 if (pAnnot) {
751 m_pSDKDoc->SetFocusAnnot(pAnnot);
752 break;
753 }
754 }
755}
756void CPDFXFA_Document::Print(IXFA_Doc* hDoc,
757 int32_t nStartPage,
758 int32_t nEndPage,
759 FX_DWORD dwOptions) {
760 if (hDoc != m_pXFADoc)
761 return;
762
763 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
764 if (pEnv == NULL)
765 return;
766
767 if (!pEnv->GetFormFillInfo() ||
768 pEnv->GetFormFillInfo()->m_pJsPlatform == NULL)
769 return;
770 if (pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print == NULL)
771 return;
772 pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print(
773 pEnv->GetFormFillInfo()->m_pJsPlatform,
774 dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage,
775 dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage,
776 dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder,
777 dwOptions & XFA_PRINTOPT_PrintAnnot);
778}
779
780void CPDFXFA_Document::GetURL(IXFA_Doc* hDoc, CFX_WideString& wsDocURL) {
781 if (hDoc != m_pXFADoc)
782 return;
783
784 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
785 if (pEnv == NULL)
786 return;
787
788 pEnv->FFI_GetURL(this, wsDocURL);
789}
790
791FX_ARGB CPDFXFA_Document::GetHighlightColor(IXFA_Doc* hDoc) {
792 if (hDoc != m_pXFADoc)
793 return 0;
794 if (m_pSDKDoc) {
795 if (CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm()) {
796 FX_COLORREF color = pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA);
797 uint8_t alpha = pInterForm->GetHighlightAlpha();
798 FX_ARGB argb = ArgbEncode((int)alpha, color);
799 return argb;
800 }
801 }
802 return 0;
803}
804
805FX_BOOL CPDFXFA_Document::_NotifySubmit(FX_BOOL bPrevOrPost) {
806 if (bPrevOrPost)
807 return _OnBeforeNotifySumbit();
808
809 _OnAfterNotifySumbit();
810 return TRUE;
811}
812
813FX_BOOL CPDFXFA_Document::_OnBeforeNotifySumbit() {
814#ifdef PDF_ENABLE_XFA
815 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
816 return TRUE;
817 if (m_pXFADocView == NULL)
818 return TRUE;
819 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
820 if (pWidgetHandler == NULL)
821 return TRUE;
822 IXFA_WidgetAccIterator* pWidgetAccIterator =
823 m_pXFADocView->CreateWidgetAccIterator();
824 if (pWidgetAccIterator) {
825 CXFA_EventParam Param;
826 Param.m_eType = XFA_EVENT_PreSubmit;
827 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
828 while (pWidgetAcc) {
829 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
830 pWidgetAcc = pWidgetAccIterator->MoveToNext();
831 }
832 pWidgetAccIterator->Release();
833 }
834 pWidgetAccIterator = m_pXFADocView->CreateWidgetAccIterator();
835 if (pWidgetAccIterator) {
836 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
837 pWidgetAcc = pWidgetAccIterator->MoveToNext();
838 while (pWidgetAcc) {
839 int fRet = pWidgetAcc->ProcessValidate(-1);
840 if (fRet == XFA_EVENTERROR_Error) {
841 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
842 if (pEnv == NULL)
843 return FALSE;
844 CFX_WideString ws;
845 ws.FromLocal(IDS_XFA_Validate_Input);
846 CFX_ByteString bs = ws.UTF16LE_Encode();
847 int len = bs.GetLength() / sizeof(unsigned short);
848 pEnv->FFI_Alert(
849 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)),
850 (FPDF_WIDESTRING)L"", 0, 1);
851 bs.ReleaseBuffer(len * sizeof(unsigned short));
852 pWidgetAccIterator->Release();
853 return FALSE;
854 }
855 pWidgetAcc = pWidgetAccIterator->MoveToNext();
856 }
857 pWidgetAccIterator->Release();
858 m_pXFADocView->UpdateDocView();
859 }
860#endif
861 return TRUE;
862}
863void CPDFXFA_Document::_OnAfterNotifySumbit() {
864 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
865 return;
866 if (m_pXFADocView == NULL)
867 return;
868 IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
869 if (pWidgetHandler == NULL)
870 return;
871 IXFA_WidgetAccIterator* pWidgetAccIterator =
872 m_pXFADocView->CreateWidgetAccIterator();
873 if (pWidgetAccIterator == NULL)
874 return;
875 CXFA_EventParam Param;
876 Param.m_eType = XFA_EVENT_PostSubmit;
877
878 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
879 while (pWidgetAcc) {
880 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
881 pWidgetAcc = pWidgetAccIterator->MoveToNext();
882 }
883 pWidgetAccIterator->Release();
884 m_pXFADocView->UpdateDocView();
885}
886
887FX_BOOL CPDFXFA_Document::SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit) {
888 if (!_NotifySubmit(TRUE))
889 return FALSE;
890 if (NULL == m_pXFADocView)
891 return FALSE;
892 m_pXFADocView->UpdateDocView();
893
894 FX_BOOL ret = _SubmitData(hDoc, submit);
895 _NotifySubmit(FALSE);
896 return ret;
897}
898
899IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(IXFA_Doc* hDoc,
900 const CFX_WideString& wsLink) {
901 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
902 if (pEnv == NULL)
903 return FALSE;
904 CFX_ByteString bs = wsLink.UTF16LE_Encode();
905 int len = bs.GetLength() / sizeof(unsigned short);
906 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile(
907 0, (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "rb");
908 bs.ReleaseBuffer(len * sizeof(unsigned short));
909
910 if (pFileHandler == NULL)
911 return NULL;
912 return new CFPDF_FileStream(pFileHandler);
913}
914FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler,
915 int fileType,
916 FPDF_DWORD encodeType,
917 FPDF_DWORD flag) {
918 if (NULL == m_pXFADocView)
919 return FALSE;
920 IXFA_DocHandler* pDocHandler = m_pApp->GetXFAApp()->GetDocHandler();
921 CFX_ByteString content;
922
923 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
924 if (pEnv == NULL)
925 return FALSE;
926
927 CFPDF_FileStream fileStream(pFileHandler);
928
929 if (fileType == FXFA_SAVEAS_XML) {
930 CFX_WideString ws;
931 ws.FromLocal("data");
932 CFX_ByteString content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
933 fileStream.WriteBlock((const FX_CHAR*)content, 0, content.GetLength());
934 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
935 } else if (fileType == FXFA_SAVEAS_XDP) {
936 if (flag == 0)
937 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
938 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
939 if (m_pPDFDoc == NULL) {
940 fileStream.Flush();
941 return FALSE;
942 }
943 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
944 if (pRoot == NULL) {
945 fileStream.Flush();
946 return FALSE;
947 }
Wei Li9b761132016-01-29 15:44:20 -0800948 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm");
Lei Zhang94293682016-01-27 18:27:56 -0800949 if (NULL == pAcroForm) {
950 fileStream.Flush();
951 return FALSE;
952 }
953 CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
954 if (pXFA == NULL) {
955 fileStream.Flush();
956 return FALSE;
957 }
958 if (!pXFA->IsArray()) {
959 fileStream.Flush();
960 return FALSE;
961 }
962 CPDF_Array* pArray = pXFA->GetArray();
963 if (NULL == pArray) {
964 fileStream.Flush();
965 return FALSE;
966 }
967 int size = pArray->GetCount();
968 for (int i = 1; i < size; i += 2) {
969 CPDF_Object* pPDFObj = pArray->GetElement(i);
970 CPDF_Object* pPrePDFObj = pArray->GetElement(i - 1);
971 if (!pPrePDFObj->IsString())
972 continue;
973 if (!pPDFObj->IsReference())
974 continue;
975 CPDF_Object* pDirectObj = pPDFObj->GetDirect();
976 if (!pDirectObj->IsStream())
977 continue;
978 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG))
979 continue;
980 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE))
981 continue;
982 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET))
983 continue;
984 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS))
985 continue;
986 if (pPrePDFObj->GetString() == "xmpmeta" && !(flag & FXFA_XMPMETA))
987 continue;
988 if (pPrePDFObj->GetString() == "xfdf" && !(flag & FXFA_XFDF))
989 continue;
990 if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM))
991 continue;
992 if (pPrePDFObj->GetString() == "form") {
993 CFX_WideString ws;
994 ws.FromLocal("form");
995 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
996 } else if (pPrePDFObj->GetString() == "datasets") {
997 CFX_WideString ws;
998 ws.FromLocal("datasets");
999 pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
1000 } else {
1001 // PDF,creator.
1002 // TODO:
1003 }
1004 }
1005 }
1006 return TRUE;
1007}
1008
1009void CPDFXFA_Document::_ClearChangeMark() {
1010 if (m_pSDKDoc)
1011 m_pSDKDoc->ClearChangeMark();
1012}
1013
1014void CPDFXFA_Document::_ToXFAContentFlags(CFX_WideString csSrcContent,
1015 FPDF_DWORD& flag) {
1016 if (csSrcContent.Find(L" config ", 0) != -1)
1017 flag |= FXFA_CONFIG;
1018 if (csSrcContent.Find(L" template ", 0) != -1)
1019 flag |= FXFA_TEMPLATE;
1020 if (csSrcContent.Find(L" localeSet ", 0) != -1)
1021 flag |= FXFA_LOCALESET;
1022 if (csSrcContent.Find(L" datasets ", 0) != -1)
1023 flag |= FXFA_DATASETS;
1024 if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
1025 flag |= FXFA_XMPMETA;
1026 if (csSrcContent.Find(L" xfdf ", 0) != -1)
1027 flag |= FXFA_XFDF;
1028 if (csSrcContent.Find(L" form ", 0) != -1)
1029 flag |= FXFA_FORM;
1030 if (flag == 0)
1031 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS |
1032 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM;
1033}
1034FX_BOOL CPDFXFA_Document::_MailToInfo(CFX_WideString& csURL,
1035 CFX_WideString& csToAddress,
1036 CFX_WideString& csCCAddress,
1037 CFX_WideString& csBCCAddress,
1038 CFX_WideString& csSubject,
1039 CFX_WideString& csMsg) {
1040 CFX_WideString srcURL = csURL;
1041 srcURL.TrimLeft();
1042 if (0 != srcURL.Left(7).CompareNoCase(L"mailto:"))
1043 return FALSE;
1044 int pos = srcURL.Find(L'?', 0);
1045 CFX_WideString tmp;
1046 if (pos == -1) {
1047 pos = srcURL.Find(L'@', 0);
1048 if (pos == -1)
1049 return FALSE;
1050 else {
1051 tmp = srcURL.Right(csURL.GetLength() - 7);
1052 tmp.TrimLeft();
1053 tmp.TrimRight();
1054 }
1055 } else {
1056 tmp = srcURL.Left(pos);
1057 tmp = tmp.Right(tmp.GetLength() - 7);
1058 tmp.TrimLeft();
1059 tmp.TrimRight();
1060 }
1061
1062 csToAddress = tmp;
1063
1064 srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1));
1065 while (!srcURL.IsEmpty()) {
1066 srcURL.TrimLeft();
1067 srcURL.TrimRight();
1068 pos = srcURL.Find(L'&', 0);
1069 if (pos == -1)
1070 tmp = srcURL;
1071 else
1072 tmp = srcURL.Left(pos);
1073
1074 tmp.TrimLeft();
1075 tmp.TrimRight();
1076 if (tmp.GetLength() >= 3 && 0 == tmp.Left(3).CompareNoCase(L"cc=")) {
1077 tmp = tmp.Right(tmp.GetLength() - 3);
1078 if (!csCCAddress.IsEmpty())
1079 csCCAddress += L';';
1080 csCCAddress += tmp;
1081
1082 } else if (tmp.GetLength() >= 4 &&
1083 0 == tmp.Left(4).CompareNoCase(L"bcc=")) {
1084 tmp = tmp.Right(tmp.GetLength() - 4);
1085 if (!csBCCAddress.IsEmpty())
1086 csBCCAddress += L';';
1087 csBCCAddress += tmp;
1088 } else if (tmp.GetLength() >= 8 &&
1089 0 == tmp.Left(8).CompareNoCase(L"subject=")) {
1090 tmp = tmp.Right(tmp.GetLength() - 8);
1091 csSubject += tmp;
1092 } else if (tmp.GetLength() >= 5 &&
1093 0 == tmp.Left(5).CompareNoCase(L"body=")) {
1094 tmp = tmp.Right(tmp.GetLength() - 5);
1095 csMsg += tmp;
1096 }
1097 if (pos == -1)
1098 srcURL = L"";
1099 else
1100 srcURL = srcURL.Right(csURL.GetLength() - (pos + 1));
1101 }
1102 csToAddress.Replace(L",", L";");
1103 csCCAddress.Replace(L",", L";");
1104 csBCCAddress.Replace(L",", L";");
1105 return TRUE;
1106}
1107
1108FX_BOOL CPDFXFA_Document::_SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit) {
1109#ifdef PDF_ENABLE_XFA
1110 CFX_WideStringC csURLC;
1111 submit.GetSubmitTarget(csURLC);
1112 CFX_WideString csURL = csURLC;
1113 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1114 if (pEnv == NULL)
1115 return FALSE;
1116 if (csURL.IsEmpty()) {
1117 CFX_WideString ws;
1118 ws.FromLocal("Submit cancelled.");
1119 CFX_ByteString bs = ws.UTF16LE_Encode();
1120 int len = bs.GetLength() / sizeof(unsigned short);
1121 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)),
1122 (FPDF_WIDESTRING)L"", 0, 4);
1123 bs.ReleaseBuffer(len * sizeof(unsigned short));
1124 return FALSE;
1125 }
1126
1127 FPDF_BOOL bRet = TRUE;
1128 FPDF_FILEHANDLER* pFileHandler = NULL;
1129 int fileFlag = -1;
1130
1131 if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xdp) {
1132 CFX_WideStringC csContentC;
1133 submit.GetSubmitXDPContent(csContentC);
1134 CFX_WideString csContent;
1135 csContent = csContentC.GetPtr();
1136 csContent.TrimLeft();
1137 csContent.TrimRight();
1138 CFX_WideString space;
1139 space.FromLocal(" ");
1140 csContent = space + csContent + space;
1141 FPDF_DWORD flag = 0;
1142 if (submit.IsSubmitEmbedPDF())
1143 flag |= FXFA_PDF;
1144 _ToXFAContentFlags(csContent, flag);
1145 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, NULL, "wb");
1146 fileFlag = FXFA_SAVEAS_XDP;
1147 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag);
1148 } else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xml) {
1149 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, NULL, "wb");
1150 fileFlag = FXFA_SAVEAS_XML;
1151 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0);
1152 } else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Pdf) {
1153 // csfilename = csDocName;
1154 } else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Formdata) {
1155 return FALSE;
1156 } else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Urlencoded) {
1157 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, NULL, "wb");
1158 fileFlag = FXFA_SAVEAS_XML;
1159 _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0);
1160 } else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xfd) {
1161 return FALSE;
1162 } else {
1163 return FALSE;
1164 }
1165 if (pFileHandler == NULL)
1166 return FALSE;
1167 if (0 == csURL.Left(7).CompareNoCase(L"mailto:")) {
1168 CFX_WideString csToAddress;
1169 CFX_WideString csCCAddress;
1170 CFX_WideString csBCCAddress;
1171 CFX_WideString csSubject;
1172 CFX_WideString csMsg;
1173
1174 bRet = _MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject,
1175 csMsg);
1176 if (FALSE == bRet)
1177 return FALSE;
1178
1179 CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode();
1180 CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode();
1181 CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode();
1182 CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode();
1183 CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode();
1184
1185 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
1186 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
1187 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
1188 FPDF_WIDESTRING pSubject =
1189 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
1190 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
1191
1192 pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
1193 bsTo.ReleaseBuffer();
1194 bsCC.ReleaseBuffer();
1195 bsBcc.ReleaseBuffer();
1196 bsSubject.ReleaseBuffer();
1197 bsMsg.ReleaseBuffer();
1198 } else {
1199 // http¡¢ftp
1200 CFX_WideString ws;
1201 CFX_ByteString bs = csURL.UTF16LE_Encode();
1202 int len = bs.GetLength() / sizeof(unsigned short);
1203 pEnv->FFI_UploadTo(
1204 pFileHandler, fileFlag,
1205 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)));
1206 bs.ReleaseBuffer(len * sizeof(unsigned short));
1207 }
1208
1209 return bRet;
1210#else
1211 return TRUE;
1212#endif
1213}
1214
1215FX_BOOL CPDFXFA_Document::SetGlobalProperty(IXFA_Doc* hDoc,
1216 const CFX_ByteStringC& szPropName,
1217 FXJSE_HVALUE hValue) {
1218 if (hDoc != m_pXFADoc)
1219 return FALSE;
1220
1221 if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime())
1222 return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetHValueByName(szPropName,
1223 hValue);
1224 return FALSE;
1225}
1226FX_BOOL CPDFXFA_Document::GetPDFScriptObject(IXFA_Doc* hDoc,
1227 const CFX_ByteStringC& utf8Name,
1228 FXJSE_HVALUE hValue) {
1229 if (hDoc != m_pXFADoc)
1230 return FALSE;
1231
1232 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime())
1233 return FALSE;
1234
1235 if (!m_pJSContext) {
1236 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc);
1237 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext();
1238 }
1239
1240 return _GetHValueByName(utf8Name, hValue,
1241 m_pSDKDoc->GetEnv()->GetJSRuntime());
1242}
1243FX_BOOL CPDFXFA_Document::GetGlobalProperty(IXFA_Doc* hDoc,
1244 const CFX_ByteStringC& szPropName,
1245 FXJSE_HVALUE hValue) {
1246 if (hDoc != m_pXFADoc)
1247 return FALSE;
1248 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime())
1249 return FALSE;
1250
1251 if (!m_pJSContext) {
1252 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc);
1253 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext();
1254 }
1255
1256 return _GetHValueByName(szPropName, hValue,
1257 m_pSDKDoc->GetEnv()->GetJSRuntime());
1258}
1259FX_BOOL CPDFXFA_Document::_GetHValueByName(const CFX_ByteStringC& utf8Name,
1260 FXJSE_HVALUE hValue,
1261 IJS_Runtime* runTime) {
1262 return runTime->GetHValueByName(utf8Name, hValue);
1263}