Chromium Code Reviews| 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/fpdfxfa/include/fpdfxfa_doc.h" | 7 #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #define FXFA_XMPMETA 0x00010000 | 38 #define FXFA_XMPMETA 0x00010000 |
| 39 #define FXFA_XFDF 0x00100000 | 39 #define FXFA_XFDF 0x00100000 |
| 40 #define FXFA_FORM 0x01000000 | 40 #define FXFA_FORM 0x01000000 |
| 41 #define FXFA_PDF 0x10000000 | 41 #define FXFA_PDF 0x10000000 |
| 42 | 42 |
| 43 #ifndef _WIN32 | 43 #ifndef _WIN32 |
| 44 extern void SetLastError(int err); | 44 extern void SetLastError(int err); |
| 45 extern int GetLastError(); | 45 extern int GetLastError(); |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 namespace { | |
| 49 | |
| 50 CFX_FloatRect FXRect2PDFRect(const CFX_RectF& fxRectF) { | |
| 51 return CFX_FloatRect(fxRectF.left, fxRectF.bottom(), fxRectF.right(), | |
|
Tom Sepez
2016/09/08 16:53:36
The code at old line 220 flipped top and bottom. D
dsinclair
2016/09/12 13:25:49
Done.
| |
| 52 fxRectF.top); | |
| 53 } | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 48 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, | 57 CPDFXFA_Document::CPDFXFA_Document(std::unique_ptr<CPDF_Document> pPDFDoc, |
| 49 CPDFXFA_App* pProvider) | 58 CPDFXFA_App* pProvider) |
| 50 : m_iDocType(DOCTYPE_PDF), | 59 : m_iDocType(DOCTYPE_PDF), |
| 51 m_pPDFDoc(std::move(pPDFDoc)), | 60 m_pPDFDoc(std::move(pPDFDoc)), |
| 52 m_pXFADocView(nullptr), | 61 m_pXFADocView(nullptr), |
| 53 m_pApp(pProvider), | 62 m_pApp(pProvider), |
| 54 m_pJSContext(nullptr), | 63 m_pJSContext(nullptr), |
| 55 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), | 64 m_nLoadStatus(FXFA_LOADSTATUS_PRELOAD), |
| 56 m_nPageCount(0) {} | 65 m_nPageCount(0) {} |
| 57 | 66 |
| 58 CPDFXFA_Document::~CPDFXFA_Document() { | 67 CPDFXFA_Document::~CPDFXFA_Document() { |
| 59 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; | 68 m_nLoadStatus = FXFA_LOADSTATUS_CLOSING; |
| 60 | 69 |
| 61 if (m_pXFADoc) { | 70 if (m_pXFADoc) { |
| 62 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); | 71 CXFA_FFApp* pApp = m_pApp->GetXFAApp(); |
| 63 if (pApp) { | 72 if (pApp) { |
| 64 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); | 73 CXFA_FFDocHandler* pDocHandler = pApp->GetDocHandler(); |
| 65 if (pDocHandler) { | 74 if (pDocHandler) |
| 66 CloseXFADoc(pDocHandler); | 75 CloseXFADoc(pDocHandler); |
| 67 } | |
| 68 } | 76 } |
| 69 m_pXFADoc.reset(); | 77 m_pXFADoc.reset(); |
| 70 } | 78 } |
| 71 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) | 79 if (m_pJSContext && m_pSDKDoc && m_pSDKDoc->GetEnv()) |
| 72 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); | 80 m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext); |
| 73 | 81 |
| 74 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; | 82 m_nLoadStatus = FXFA_LOADSTATUS_CLOSED; |
| 75 } | 83 } |
| 76 | 84 |
| 77 FX_BOOL CPDFXFA_Document::LoadXFADoc() { | 85 FX_BOOL CPDFXFA_Document::LoadXFADoc() { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); | 218 m_XFAPageList.SetAt(page->GetPageIndex(), nullptr); |
| 211 } | 219 } |
| 212 | 220 |
| 213 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( | 221 CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument( |
| 214 CPDFDoc_Environment* pFormFillEnv) { | 222 CPDFDoc_Environment* pFormFillEnv) { |
| 215 if (!m_pSDKDoc && pFormFillEnv) | 223 if (!m_pSDKDoc && pFormFillEnv) |
| 216 m_pSDKDoc.reset(new CPDFSDK_Document(this, pFormFillEnv)); | 224 m_pSDKDoc.reset(new CPDFSDK_Document(this, pFormFillEnv)); |
| 217 return m_pSDKDoc.get(); | 225 return m_pSDKDoc.get(); |
| 218 } | 226 } |
| 219 | 227 |
| 220 void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, | |
| 221 CFX_FloatRect& pdfRect) { | |
| 222 pdfRect.left = fxRectF.left; | |
| 223 pdfRect.top = fxRectF.bottom(); | |
| 224 pdfRect.right = fxRectF.right(); | |
| 225 pdfRect.bottom = fxRectF.top; | |
| 226 } | |
| 227 | |
| 228 void CPDFXFA_Document::SetChangeMark(CXFA_FFDoc* hDoc) { | 228 void CPDFXFA_Document::SetChangeMark(CXFA_FFDoc* hDoc) { |
| 229 if (hDoc == m_pXFADoc.get() && m_pSDKDoc) { | 229 if (hDoc == m_pXFADoc.get() && m_pSDKDoc) |
| 230 m_pSDKDoc->SetChangeMark(); | 230 m_pSDKDoc->SetChangeMark(); |
| 231 } | |
| 232 } | 231 } |
| 233 | 232 |
| 234 void CPDFXFA_Document::InvalidateRect(CXFA_FFPageView* pPageView, | 233 void CPDFXFA_Document::InvalidateRect(CXFA_FFPageView* pPageView, |
| 235 const CFX_RectF& rt, | 234 const CFX_RectF& rt, |
| 236 uint32_t dwFlags /* = 0 */) { | 235 uint32_t dwFlags /* = 0 */) { |
| 237 if (!m_pXFADoc || !m_pSDKDoc) | 236 if (!m_pXFADoc || !m_pSDKDoc) |
| 238 return; | 237 return; |
| 239 | 238 |
| 240 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | 239 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) |
| 241 return; | 240 return; |
| 242 | 241 |
| 243 CFX_FloatRect rcPage; | |
| 244 FXRect2PDFRect(rt, rcPage); | |
| 245 | |
| 246 CPDFXFA_Page* pPage = GetPage(pPageView); | 242 CPDFXFA_Page* pPage = GetPage(pPageView); |
| 247 if (!pPage) | 243 if (!pPage) |
| 248 return; | 244 return; |
| 249 | 245 |
| 250 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 246 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 251 if (!pEnv) | 247 if (!pEnv) |
| 252 return; | 248 return; |
| 253 | 249 |
| 250 CFX_FloatRect rcPage = FXRect2PDFRect(rt); | |
| 254 pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, | 251 pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, |
| 255 rcPage.right, rcPage.top); | 252 rcPage.right, rcPage.top); |
| 256 } | 253 } |
| 257 | 254 |
| 258 void CPDFXFA_Document::DisplayCaret(CXFA_FFWidget* hWidget, | 255 void CPDFXFA_Document::DisplayCaret(CXFA_FFWidget* hWidget, |
| 259 FX_BOOL bVisible, | 256 FX_BOOL bVisible, |
| 260 const CFX_RectF* pRtAnchor) { | 257 const CFX_RectF* pRtAnchor) { |
| 261 if (!hWidget || !pRtAnchor || !m_pXFADoc || !m_pSDKDoc || !m_pXFADocView) | 258 if (!hWidget || !pRtAnchor || !m_pXFADoc || !m_pSDKDoc || !m_pXFADocView) |
| 262 return; | 259 return; |
| 263 | 260 |
| 264 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) | 261 if (m_iDocType != DOCTYPE_DYNAMIC_XFA) |
| 265 return; | 262 return; |
| 266 | 263 |
| 267 CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); | 264 CXFA_FFWidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler(); |
| 268 if (!pWidgetHandler) | 265 if (!pWidgetHandler) |
| 269 return; | 266 return; |
| 270 | 267 |
| 271 CXFA_FFPageView* pPageView = hWidget->GetPageView(); | 268 CXFA_FFPageView* pPageView = hWidget->GetPageView(); |
| 272 if (!pPageView) | 269 if (!pPageView) |
| 273 return; | 270 return; |
| 274 | 271 |
| 275 CPDFXFA_Page* pPage = GetPage(pPageView); | 272 CPDFXFA_Page* pPage = GetPage(pPageView); |
| 276 if (!pPage) | 273 if (!pPage) |
| 277 return; | 274 return; |
| 278 | 275 |
| 279 CFX_FloatRect rcCaret; | |
| 280 FXRect2PDFRect(*pRtAnchor, rcCaret); | |
| 281 | |
| 282 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 276 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 283 if (!pEnv) | 277 if (!pEnv) |
| 284 return; | 278 return; |
| 285 | 279 |
| 280 CFX_FloatRect rcCaret = FXRect2PDFRect(*pRtAnchor); | |
| 286 pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top, | 281 pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top, |
| 287 rcCaret.right, rcCaret.bottom); | 282 rcCaret.right, rcCaret.bottom); |
| 288 } | 283 } |
| 289 | 284 |
| 290 FX_BOOL CPDFXFA_Document::GetPopupPos(CXFA_FFWidget* hWidget, | 285 FX_BOOL CPDFXFA_Document::GetPopupPos(CXFA_FFWidget* hWidget, |
| 291 FX_FLOAT fMinPopup, | 286 FX_FLOAT fMinPopup, |
| 292 FX_FLOAT fMaxPopup, | 287 FX_FLOAT fMaxPopup, |
| 293 const CFX_RectF& rtAnchor, | 288 const CFX_RectF& rtAnchor, |
| 294 CFX_RectF& rtPopup) { | 289 CFX_RectF& rtPopup) { |
| 295 if (!hWidget) | 290 if (!hWidget) |
| 296 return FALSE; | 291 return FALSE; |
| 297 | 292 |
| 298 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); | 293 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 299 if (!pXFAPageView) | 294 if (!pXFAPageView) |
| 300 return FALSE; | 295 return FALSE; |
| 301 | 296 |
| 302 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | 297 CPDFXFA_Page* pPage = GetPage(pXFAPageView); |
| 303 if (!pPage) | 298 if (!pPage) |
| 304 return FALSE; | 299 return FALSE; |
| 305 | 300 |
| 306 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); | 301 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
| 307 int nRotate = pWidgetAcc->GetRotate(); | 302 int nRotate = pWidgetAcc->GetRotate(); |
| 308 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 303 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 309 if (!pEnv) | 304 if (!pEnv) |
| 310 return FALSE; | 305 return FALSE; |
| 306 | |
| 311 FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f}; | 307 FS_RECTF pageViewRect = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 312 pEnv->FFI_GetPageViewRect(pPage, pageViewRect); | 308 pEnv->FFI_GetPageViewRect(pPage, pageViewRect); |
| 313 | 309 |
| 314 CFX_FloatRect rcAnchor; | 310 int t1; |
| 315 rcAnchor.left = rtAnchor.left; | 311 int t2; |
| 316 rcAnchor.top = rtAnchor.bottom(); | 312 CFX_FloatRect rcAnchor = FXRect2PDFRect(rtAnchor); |
| 317 rcAnchor.right = rtAnchor.right(); | |
| 318 rcAnchor.bottom = rtAnchor.top; | |
| 319 | |
| 320 int t1, t2, t; | |
| 321 uint32_t dwPos; | |
| 322 FX_FLOAT fPoupHeight; | |
| 323 switch (nRotate) { | 313 switch (nRotate) { |
| 324 case 90: { | 314 case 90: { |
| 325 t1 = (int)(pageViewRect.right - rcAnchor.right); | 315 t1 = (int)(pageViewRect.right - rcAnchor.right); |
| 326 t2 = (int)(rcAnchor.left - pageViewRect.left); | 316 t2 = (int)(rcAnchor.left - pageViewRect.left); |
| 327 if (rcAnchor.bottom < pageViewRect.bottom) { | 317 if (rcAnchor.bottom < pageViewRect.bottom) |
| 328 rtPopup.left += rcAnchor.bottom - pageViewRect.bottom; | 318 rtPopup.left += rcAnchor.bottom - pageViewRect.bottom; |
| 329 } | |
| 330 | |
| 331 break; | 319 break; |
| 332 } | 320 } |
| 333 | |
| 334 case 180: { | 321 case 180: { |
| 335 t2 = (int)(pageViewRect.top - rcAnchor.top); | 322 t2 = (int)(pageViewRect.top - rcAnchor.top); |
| 336 t1 = (int)(rcAnchor.bottom - pageViewRect.bottom); | 323 t1 = (int)(rcAnchor.bottom - pageViewRect.bottom); |
| 337 if (rcAnchor.left < pageViewRect.left) { | 324 if (rcAnchor.left < pageViewRect.left) |
| 338 rtPopup.left += rcAnchor.left - pageViewRect.left; | 325 rtPopup.left += rcAnchor.left - pageViewRect.left; |
| 339 } | |
| 340 break; | 326 break; |
| 341 } | 327 } |
| 342 case 270: { | 328 case 270: { |
| 343 t1 = (int)(rcAnchor.left - pageViewRect.left); | 329 t1 = (int)(rcAnchor.left - pageViewRect.left); |
| 344 t2 = (int)(pageViewRect.right - rcAnchor.right); | 330 t2 = (int)(pageViewRect.right - rcAnchor.right); |
| 345 | 331 if (rcAnchor.top > pageViewRect.top) |
| 346 if (rcAnchor.top > pageViewRect.top) { | |
| 347 rtPopup.left -= rcAnchor.top - pageViewRect.top; | 332 rtPopup.left -= rcAnchor.top - pageViewRect.top; |
| 348 } | |
| 349 break; | 333 break; |
| 350 } | 334 } |
| 351 case 0: | 335 case 0: |
| 352 default: { | 336 default: { |
| 353 t1 = (int)(pageViewRect.top - rcAnchor.top); | 337 t1 = (int)(pageViewRect.top - rcAnchor.top); |
| 354 t2 = (int)(rcAnchor.bottom - pageViewRect.bottom); | 338 t2 = (int)(rcAnchor.bottom - pageViewRect.bottom); |
| 355 if (rcAnchor.right > pageViewRect.right) { | 339 if (rcAnchor.right > pageViewRect.right) |
| 356 rtPopup.left -= rcAnchor.right - pageViewRect.right; | 340 rtPopup.left -= rcAnchor.right - pageViewRect.right; |
| 357 } | |
| 358 break; | 341 break; |
| 359 } | 342 } |
| 360 } | 343 } |
| 361 | 344 |
| 362 if (t1 <= 0 && t2 <= 0) { | 345 int t; |
| 346 uint32_t dwPos; | |
| 347 if (t1 <= 0 && t2 <= 0) | |
| 363 return FALSE; | 348 return FALSE; |
| 364 } | |
| 365 if (t1 <= 0) { | 349 if (t1 <= 0) { |
| 366 t = t2; | 350 t = t2; |
| 367 dwPos = 1; | 351 dwPos = 1; |
| 368 } else if (t2 <= 0) { | 352 } else if (t2 <= 0) { |
| 369 t = t1; | 353 t = t1; |
| 370 dwPos = 0; | 354 dwPos = 0; |
| 371 } else if (t1 > t2) { | 355 } else if (t1 > t2) { |
| 372 t = t1; | 356 t = t1; |
| 373 dwPos = 0; | 357 dwPos = 0; |
| 374 } else { | 358 } else { |
| 375 t = t2; | 359 t = t2; |
| 376 dwPos = 1; | 360 dwPos = 1; |
| 377 } | 361 } |
| 378 if (t < fMinPopup) { | 362 |
| 379 fPoupHeight = fMinPopup; | 363 FX_FLOAT fPopupHeight; |
| 380 } else if (t > fMaxPopup) { | 364 if (t < fMinPopup) |
| 381 fPoupHeight = fMaxPopup; | 365 fPopupHeight = fMinPopup; |
| 382 } else { | 366 else if (t > fMaxPopup) |
| 383 fPoupHeight = (FX_FLOAT)t; | 367 fPopupHeight = fMaxPopup; |
| 384 } | 368 else |
| 369 fPopupHeight = static_cast<FX_FLOAT>(t); | |
| 385 | 370 |
| 386 switch (nRotate) { | 371 switch (nRotate) { |
| 387 case 0: | 372 case 0: |
| 388 case 180: { | 373 case 180: { |
| 389 if (dwPos == 0) { | 374 if (dwPos == 0) { |
| 390 rtPopup.top = rtAnchor.height; | 375 rtPopup.top = rtAnchor.height; |
| 391 rtPopup.height = fPoupHeight; | 376 rtPopup.height = fPopupHeight; |
| 392 } else { | 377 } else { |
| 393 rtPopup.top = -fPoupHeight; | 378 rtPopup.top = -fPopupHeight; |
| 394 rtPopup.height = fPoupHeight; | 379 rtPopup.height = fPopupHeight; |
| 395 } | 380 } |
| 396 break; | 381 break; |
| 397 } | 382 } |
| 398 case 90: | 383 case 90: |
| 399 case 270: { | 384 case 270: { |
| 400 if (dwPos == 0) { | 385 if (dwPos == 0) { |
| 401 rtPopup.top = rtAnchor.width; | 386 rtPopup.top = rtAnchor.width; |
| 402 rtPopup.height = fPoupHeight; | 387 rtPopup.height = fPopupHeight; |
| 403 } else { | 388 } else { |
| 404 rtPopup.top = -fPoupHeight; | 389 rtPopup.top = -fPopupHeight; |
| 405 rtPopup.height = fPoupHeight; | 390 rtPopup.height = fPopupHeight; |
| 406 } | 391 } |
| 407 break; | 392 break; |
| 408 } | 393 } |
| 409 default: | 394 default: |
| 410 break; | 395 break; |
| 411 } | 396 } |
| 412 | 397 |
| 413 return TRUE; | 398 return TRUE; |
| 414 } | 399 } |
| 415 | 400 |
| 416 FX_BOOL CPDFXFA_Document::PopupMenu(CXFA_FFWidget* hWidget, | 401 FX_BOOL CPDFXFA_Document::PopupMenu(CXFA_FFWidget* hWidget, |
| 417 CFX_PointF ptPopup, | 402 CFX_PointF ptPopup) { |
| 418 const CFX_RectF* pRectExclude) { | |
| 419 if (!hWidget) | 403 if (!hWidget) |
| 420 return FALSE; | 404 return FALSE; |
| 421 | 405 |
| 422 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); | 406 CXFA_FFPageView* pXFAPageView = hWidget->GetPageView(); |
| 423 if (!pXFAPageView) | 407 if (!pXFAPageView) |
| 424 return FALSE; | 408 return FALSE; |
| 425 | 409 |
| 426 CPDFXFA_Page* pPage = GetPage(pXFAPageView); | 410 CPDFXFA_Page* pPage = GetPage(pXFAPageView); |
| 427 if (!pPage) | 411 if (!pPage) |
| 428 return FALSE; | 412 return FALSE; |
| 429 | 413 |
| 414 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 415 if (!pEnv) | |
| 416 return FALSE; | |
| 417 | |
| 430 int menuFlag = 0; | 418 int menuFlag = 0; |
| 431 | |
| 432 if (hWidget->CanUndo()) | 419 if (hWidget->CanUndo()) |
| 433 menuFlag |= FXFA_MEMU_UNDO; | 420 menuFlag |= FXFA_MEMU_UNDO; |
|
Tom Sepez
2016/09/08 16:53:36
nit: MEMU is apparently a train in India, and is n
dsinclair
2016/09/12 13:25:48
Done.
| |
| 434 if (hWidget->CanRedo()) | 421 if (hWidget->CanRedo()) |
| 435 menuFlag |= FXFA_MEMU_REDO; | 422 menuFlag |= FXFA_MEMU_REDO; |
| 436 if (hWidget->CanPaste()) | 423 if (hWidget->CanPaste()) |
| 437 menuFlag |= FXFA_MEMU_PASTE; | 424 menuFlag |= FXFA_MEMU_PASTE; |
| 438 if (hWidget->CanCopy()) | 425 if (hWidget->CanCopy()) |
| 439 menuFlag |= FXFA_MEMU_COPY; | 426 menuFlag |= FXFA_MEMU_COPY; |
| 440 if (hWidget->CanCut()) | 427 if (hWidget->CanCut()) |
| 441 menuFlag |= FXFA_MEMU_CUT; | 428 menuFlag |= FXFA_MEMU_CUT; |
| 442 if (hWidget->CanSelectAll()) | 429 if (hWidget->CanSelectAll()) |
| 443 menuFlag |= FXFA_MEMU_SELECTALL; | 430 menuFlag |= FXFA_MEMU_SELECTALL; |
| 444 | 431 |
| 445 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 432 return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, nullptr); |
| 446 return pEnv && | |
| 447 pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, nullptr); | |
| 448 } | 433 } |
| 449 | 434 |
| 450 void CPDFXFA_Document::PageViewEvent(CXFA_FFPageView* pPageView, | 435 void CPDFXFA_Document::PageViewEvent(CXFA_FFPageView* pPageView, |
| 451 uint32_t dwFlags) { | 436 uint32_t dwFlags) { |
| 452 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 437 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 453 if (!pEnv) | 438 if (!pEnv) |
| 454 return; | 439 return; |
| 455 | 440 |
| 456 if (m_nLoadStatus != FXFA_LOADSTATUS_LOADING && | 441 if (m_nLoadStatus == FXFA_LOADSTATUS_LOADING || |
| 457 m_nLoadStatus != FXFA_LOADSTATUS_CLOSING && | 442 m_nLoadStatus == FXFA_LOADSTATUS_CLOSING || |
| 458 XFA_PAGEVIEWEVENT_StopLayout == dwFlags) { | 443 XFA_PAGEVIEWEVENT_StopLayout != dwFlags) |
| 459 int nNewCount = GetPageCount(); | 444 return; |
| 460 if (nNewCount == m_nPageCount) | |
| 461 return; | |
| 462 | 445 |
| 463 CXFA_FFDocView* pXFADocView = GetXFADocView(); | 446 int nNewCount = GetPageCount(); |
| 464 if (!pXFADocView) | 447 if (nNewCount == m_nPageCount) |
| 465 return; | 448 return; |
| 466 for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) { | |
| 467 CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter); | |
| 468 if (!pPage) | |
| 469 continue; | |
| 470 m_pSDKDoc->RemovePageView(pPage); | |
| 471 CXFA_FFPageView* pXFAPageView = pXFADocView->GetPageView(iPageIter); | |
| 472 pPage->SetXFAPageView(pXFAPageView); | |
| 473 } | |
| 474 | 449 |
| 475 int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED | 450 CXFA_FFDocView* pXFADocView = GetXFADocView(); |
| 476 : FXFA_PAGEVIEWEVENT_POSTADDED; | 451 if (!pXFADocView) |
| 477 int count = FXSYS_abs(nNewCount - m_nPageCount); | 452 return; |
| 478 m_nPageCount = nNewCount; | 453 |
| 479 m_XFAPageList.SetSize(nNewCount); | 454 for (int iPageIter = 0; iPageIter < m_nPageCount; iPageIter++) { |
| 480 pEnv->FFI_PageEvent(count, flag); | 455 CPDFXFA_Page* pPage = m_XFAPageList.GetAt(iPageIter); |
| 456 if (!pPage) | |
| 457 continue; | |
| 458 | |
| 459 m_pSDKDoc->RemovePageView(pPage); | |
| 460 pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); | |
| 481 } | 461 } |
| 462 | |
| 463 int flag = (nNewCount < m_nPageCount) ? FXFA_PAGEVIEWEVENT_POSTREMOVED | |
| 464 : FXFA_PAGEVIEWEVENT_POSTADDED; | |
| 465 int count = FXSYS_abs(nNewCount - m_nPageCount); | |
| 466 m_nPageCount = nNewCount; | |
| 467 m_XFAPageList.SetSize(nNewCount); | |
| 468 pEnv->FFI_PageEvent(count, flag); | |
| 482 } | 469 } |
| 483 | 470 |
| 484 void CPDFXFA_Document::WidgetPostAdd(CXFA_FFWidget* hWidget, | 471 void CPDFXFA_Document::WidgetPostAdd(CXFA_FFWidget* hWidget, |
| 485 CXFA_WidgetAcc* pWidgetData) { | 472 CXFA_WidgetAcc* pWidgetData) { |
| 486 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) | 473 if (m_iDocType != DOCTYPE_DYNAMIC_XFA || !hWidget) |
| 487 return; | 474 return; |
| 488 | 475 |
| 489 CXFA_FFPageView* pPageView = hWidget->GetPageView(); | 476 CXFA_FFPageView* pPageView = hWidget->GetPageView(); |
| 490 if (!pPageView) | 477 if (!pPageView) |
| 491 return; | 478 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 520 |
| 534 return pEnv->FFI_GetCurrentPageIndex(this); | 521 return pEnv->FFI_GetCurrentPageIndex(this); |
| 535 } | 522 } |
| 536 | 523 |
| 537 void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { | 524 void CPDFXFA_Document::SetCurrentPage(CXFA_FFDoc* hDoc, int32_t iCurPage) { |
| 538 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc || | 525 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc || |
| 539 m_iDocType != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || | 526 m_iDocType != DOCTYPE_DYNAMIC_XFA || iCurPage < 0 || |
| 540 iCurPage >= m_pSDKDoc->GetPageCount()) { | 527 iCurPage >= m_pSDKDoc->GetPageCount()) { |
| 541 return; | 528 return; |
| 542 } | 529 } |
| 530 | |
| 543 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 531 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 544 if (!pEnv) | 532 if (!pEnv) |
| 545 return; | 533 return; |
| 546 pEnv->FFI_SetCurrentPage(this, iCurPage); | 534 pEnv->FFI_SetCurrentPage(this, iCurPage); |
| 547 } | 535 } |
| 548 | 536 |
| 549 FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { | 537 FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(CXFA_FFDoc* hDoc) { |
| 550 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | 538 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) |
| 551 return FALSE; | 539 return FALSE; |
| 552 if (m_pSDKDoc->GetInterForm()) | 540 if (m_pSDKDoc->GetInterForm()) |
| 553 return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled(); | 541 return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled(); |
| 554 | |
| 555 return FALSE; | 542 return FALSE; |
| 556 } | 543 } |
| 557 | 544 |
| 558 void CPDFXFA_Document::SetCalculationsEnabled(CXFA_FFDoc* hDoc, | 545 void CPDFXFA_Document::SetCalculationsEnabled(CXFA_FFDoc* hDoc, |
| 559 FX_BOOL bEnabled) { | 546 FX_BOOL bEnabled) { |
| 560 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | 547 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) |
| 561 return; | 548 return; |
| 562 if (m_pSDKDoc->GetInterForm()) | 549 if (m_pSDKDoc->GetInterForm()) |
| 563 m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled); | 550 m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled); |
| 564 } | 551 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 | 583 |
| 597 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 584 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 598 if (!pEnv) | 585 if (!pEnv) |
| 599 return; | 586 return; |
| 600 | 587 |
| 601 int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; | 588 int fileType = bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML; |
| 602 CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); | 589 CFX_ByteString bs = wsFilePath.UTF16LE_Encode(); |
| 603 if (wsFilePath.IsEmpty()) { | 590 if (wsFilePath.IsEmpty()) { |
| 604 if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform) | 591 if (!pEnv->GetFormFillInfo() || !pEnv->GetFormFillInfo()->m_pJsPlatform) |
| 605 return; | 592 return; |
| 593 | |
| 606 CFX_WideString filepath = pEnv->JS_fieldBrowse(); | 594 CFX_WideString filepath = pEnv->JS_fieldBrowse(); |
| 607 bs = filepath.UTF16LE_Encode(); | 595 bs = filepath.UTF16LE_Encode(); |
| 608 } | 596 } |
| 609 int len = bs.GetLength() / sizeof(unsigned short); | 597 int len = bs.GetLength(); |
|
dsinclair
2016/09/08 15:13:51
This pattern is repeated a few times in this file.
Tom Sepez
2016/09/08 16:53:36
Maybe we don't want to pass an odd number of bytes
Tom Sepez
2016/09/08 16:55:07
No, actually if it's smakller, getbuffer just leav
dsinclair
2016/09/12 13:25:48
So, is there anything to be done here?
| |
| 610 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile( | 598 FPDF_FILEHANDLER* pFileHandler = |
| 611 bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, | 599 pEnv->FFI_OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, |
| 612 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "wb"); | 600 (FPDF_WIDESTRING)bs.GetBuffer(len), "wb"); |
| 613 bs.ReleaseBuffer(len * sizeof(unsigned short)); | 601 bs.ReleaseBuffer(len); |
| 614 if (!pFileHandler) | 602 if (!pFileHandler) |
| 615 return; | 603 return; |
| 616 | 604 |
| 617 CFPDF_FileStream fileWrite(pFileHandler); | 605 CFPDF_FileStream fileWrite(pFileHandler); |
| 618 CFX_ByteString content; | 606 CFX_ByteString content; |
| 619 if (fileType == FXFA_SAVEAS_XML) { | 607 if (fileType == FXFA_SAVEAS_XML) { |
| 620 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 608 content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 621 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | 609 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), |
| 622 content.GetLength()); | 610 content.GetLength()); |
| 623 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, | 611 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, |
| 624 nullptr); | 612 nullptr); |
| 625 } else if (fileType == FXFA_SAVEAS_XDP) { | 613 } else if (fileType == FXFA_SAVEAS_XDP) { |
| 626 if (!m_pPDFDoc) | 614 if (!m_pPDFDoc) |
| 627 return; | 615 return; |
| 616 | |
| 628 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | 617 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); |
| 629 if (!pRoot) | 618 if (!pRoot) |
| 630 return; | 619 return; |
| 620 | |
| 631 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 621 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 632 if (!pAcroForm) | 622 if (!pAcroForm) |
| 633 return; | 623 return; |
| 624 | |
| 634 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); | 625 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); |
| 635 if (!pArray) | 626 if (!pArray) |
| 636 return; | 627 return; |
| 637 | 628 |
| 638 int size = pArray->GetCount(); | 629 int size = pArray->GetCount(); |
| 639 for (int i = 1; i < size; i += 2) { | 630 for (int i = 1; i < size; i += 2) { |
| 640 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | 631 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 641 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | 632 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 642 if (!pPrePDFObj->IsString()) | 633 if (!pPrePDFObj->IsString()) |
| 643 continue; | 634 continue; |
| 644 if (!pPDFObj->IsReference()) | 635 if (!pPDFObj->IsReference()) |
| 645 continue; | 636 continue; |
| 637 | |
| 646 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); | 638 CPDF_Stream* pStream = ToStream(pPDFObj->GetDirect()); |
| 647 if (!pStream) | 639 if (!pStream) |
| 648 continue; | 640 continue; |
| 649 if (pPrePDFObj->GetString() == "form") { | 641 if (pPrePDFObj->GetString() == "form") { |
| 650 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, &fileWrite, | 642 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, &fileWrite, |
| 651 nullptr); | 643 nullptr); |
| 652 } else if (pPrePDFObj->GetString() == "datasets") { | 644 continue; |
| 645 } | |
| 646 if (pPrePDFObj->GetString() == "datasets") { | |
| 653 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, &fileWrite, | 647 m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, &fileWrite, |
| 654 nullptr); | 648 nullptr); |
| 655 } else { | 649 continue; |
| 656 if (i == size - 1) { | |
| 657 CFX_WideString wPath = CFX_WideString::FromUTF16LE( | |
| 658 reinterpret_cast<const unsigned short*>(bs.c_str()), | |
| 659 bs.GetLength() / sizeof(unsigned short)); | |
| 660 CFX_ByteString bPath = wPath.UTF8Encode(); | |
| 661 const char* szFormat = | |
| 662 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; | |
| 663 content.Format(szFormat, bPath.c_str()); | |
| 664 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | |
| 665 content.GetLength()); | |
| 666 } | |
| 667 std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); | |
| 668 pAcc->LoadAllData(pStream); | |
| 669 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), | |
| 670 pAcc->GetSize()); | |
| 671 } | 650 } |
| 651 if (i == size - 1) { | |
| 652 CFX_WideString wPath = CFX_WideString::FromUTF16LE( | |
| 653 reinterpret_cast<const unsigned short*>(bs.c_str()), | |
| 654 bs.GetLength() / sizeof(unsigned short)); | |
| 655 CFX_ByteString bPath = wPath.UTF8Encode(); | |
| 656 const char* szFormat = | |
| 657 "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>"; | |
| 658 content.Format(szFormat, bPath.c_str()); | |
| 659 fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), | |
| 660 content.GetLength()); | |
| 661 } | |
| 662 std::unique_ptr<CPDF_StreamAcc> pAcc(new CPDF_StreamAcc); | |
| 663 pAcc->LoadAllData(pStream); | |
| 664 fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), | |
| 665 pAcc->GetSize()); | |
| 672 } | 666 } |
| 673 } | 667 } |
| 674 if (!fileWrite.Flush()) { | 668 if (!fileWrite.Flush()) { |
| 675 // Ignoring flush error. | 669 // Ignoring flush error. |
| 676 } | 670 } |
| 677 } | 671 } |
| 678 | 672 |
| 679 void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc, | 673 void CPDFXFA_Document::GotoURL(CXFA_FFDoc* hDoc, |
| 680 const CFX_WideString& bsURL, | 674 const CFX_WideString& bsURL, |
| 681 FX_BOOL bAppend) { | 675 FX_BOOL bAppend) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 692 CFX_WideStringC str(bsURL.c_str()); | 686 CFX_WideStringC str(bsURL.c_str()); |
| 693 | 687 |
| 694 pEnv->FFI_GotoURL(this, str, bAppend); | 688 pEnv->FFI_GotoURL(this, str, bAppend); |
| 695 } | 689 } |
| 696 | 690 |
| 697 FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) { | 691 FX_BOOL CPDFXFA_Document::IsValidationsEnabled(CXFA_FFDoc* hDoc) { |
| 698 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | 692 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) |
| 699 return FALSE; | 693 return FALSE; |
| 700 if (m_pSDKDoc->GetInterForm()) | 694 if (m_pSDKDoc->GetInterForm()) |
| 701 return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled(); | 695 return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled(); |
| 702 | |
| 703 return TRUE; | 696 return TRUE; |
| 704 } | 697 } |
| 705 | 698 |
| 706 void CPDFXFA_Document::SetValidationsEnabled(CXFA_FFDoc* hDoc, | 699 void CPDFXFA_Document::SetValidationsEnabled(CXFA_FFDoc* hDoc, |
| 707 FX_BOOL bEnabled) { | 700 FX_BOOL bEnabled) { |
| 708 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) | 701 if (hDoc != m_pXFADoc.get() || !m_pSDKDoc) |
| 709 return; | 702 return; |
| 710 if (m_pSDKDoc->GetInterForm()) | 703 if (m_pSDKDoc->GetInterForm()) |
| 711 m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled); | 704 m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled); |
| 712 } | 705 } |
| 713 | 706 |
| 714 void CPDFXFA_Document::SetFocusWidget(CXFA_FFDoc* hDoc, | 707 void CPDFXFA_Document::SetFocusWidget(CXFA_FFDoc* hDoc, |
| 715 CXFA_FFWidget* hWidget) { | 708 CXFA_FFWidget* hWidget) { |
| 716 if (hDoc != m_pXFADoc.get()) | 709 if (hDoc != m_pXFADoc.get()) |
| 717 return; | 710 return; |
| 718 | 711 |
| 719 if (!hWidget) { | 712 if (!hWidget) { |
| 720 m_pSDKDoc->SetFocusAnnot(nullptr); | 713 m_pSDKDoc->SetFocusAnnot(nullptr); |
| 721 return; | 714 return; |
| 722 } | 715 } |
| 723 | 716 |
| 724 int pageViewCount = m_pSDKDoc->GetPageViewCount(); | 717 int pageViewCount = m_pSDKDoc->GetPageViewCount(); |
| 725 for (int i = 0; i < pageViewCount; i++) { | 718 for (int i = 0; i < pageViewCount; i++) { |
| 726 CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i); | 719 CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i); |
| 727 if (!pPageView) | 720 if (!pPageView) |
| 728 continue; | 721 continue; |
| 722 | |
| 729 CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget); | 723 CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget); |
| 730 if (pAnnot) { | 724 if (pAnnot) { |
| 731 m_pSDKDoc->SetFocusAnnot(pAnnot); | 725 m_pSDKDoc->SetFocusAnnot(pAnnot); |
| 732 break; | 726 break; |
| 733 } | 727 } |
| 734 } | 728 } |
| 735 } | 729 } |
| 736 | 730 |
| 737 void CPDFXFA_Document::Print(CXFA_FFDoc* hDoc, | 731 void CPDFXFA_Document::Print(CXFA_FFDoc* hDoc, |
| 738 int32_t nStartPage, | 732 int32_t nStartPage, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 749 } | 743 } |
| 750 | 744 |
| 751 pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print( | 745 pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print( |
| 752 pEnv->GetFormFillInfo()->m_pJsPlatform, | 746 pEnv->GetFormFillInfo()->m_pJsPlatform, |
| 753 dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage, | 747 dwOptions & XFA_PRINTOPT_ShowDialog, nStartPage, nEndPage, |
| 754 dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage, | 748 dwOptions & XFA_PRINTOPT_CanCancel, dwOptions & XFA_PRINTOPT_ShrinkPage, |
| 755 dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder, | 749 dwOptions & XFA_PRINTOPT_AsImage, dwOptions & XFA_PRINTOPT_ReverseOrder, |
| 756 dwOptions & XFA_PRINTOPT_PrintAnnot); | 750 dwOptions & XFA_PRINTOPT_PrintAnnot); |
| 757 } | 751 } |
| 758 | 752 |
| 759 void CPDFXFA_Document::GetURL(CXFA_FFDoc* hDoc, CFX_WideString& wsDocURL) { | |
| 760 if (hDoc != m_pXFADoc.get()) | |
| 761 return; | |
| 762 | |
| 763 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 764 if (!pEnv) | |
| 765 return; | |
| 766 | |
| 767 pEnv->FFI_GetURL(this, wsDocURL); | |
| 768 } | |
| 769 | |
| 770 FX_ARGB CPDFXFA_Document::GetHighlightColor(CXFA_FFDoc* hDoc) { | 753 FX_ARGB CPDFXFA_Document::GetHighlightColor(CXFA_FFDoc* hDoc) { |
| 771 if (hDoc != m_pXFADoc.get()) | 754 if (hDoc != m_pXFADoc.get()) |
| 772 return 0; | 755 return 0; |
| 773 if (m_pSDKDoc) { | 756 if (!m_pSDKDoc) |
|
Tom Sepez
2016/09/08 16:53:36
nit: maybe combine with 754
dsinclair
2016/09/12 13:25:49
Done.
| |
| 774 if (CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm()) { | 757 return 0; |
| 775 FX_COLORREF color = pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA); | 758 |
| 776 uint8_t alpha = pInterForm->GetHighlightAlpha(); | 759 CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm(); |
| 777 FX_ARGB argb = ArgbEncode((int)alpha, color); | 760 if (!pInterForm) |
| 778 return argb; | 761 return 0; |
| 779 } | 762 |
| 780 } | 763 FX_COLORREF color = pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA); |
| 781 return 0; | 764 uint8_t alpha = pInterForm->GetHighlightAlpha(); |
| 765 FX_ARGB argb = ArgbEncode((int)alpha, color); | |
|
Tom Sepez
2016/09/08 16:53:36
nit: local argb not needed (nor are the others, bu
dsinclair
2016/09/12 13:25:48
Done.
| |
| 766 return argb; | |
| 782 } | 767 } |
| 783 | 768 |
| 784 FX_BOOL CPDFXFA_Document::NotifySubmit(FX_BOOL bPrevOrPost) { | 769 FX_BOOL CPDFXFA_Document::NotifySubmit(FX_BOOL bPrevOrPost) { |
| 785 if (bPrevOrPost) | 770 if (bPrevOrPost) |
| 786 return OnBeforeNotifySubmit(); | 771 return OnBeforeNotifySubmit(); |
| 787 | 772 |
| 788 OnAfterNotifySubmit(); | 773 OnAfterNotifySubmit(); |
| 789 return TRUE; | 774 return TRUE; |
| 790 } | 775 } |
| 791 | 776 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 803 std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( | 788 std::unique_ptr<CXFA_WidgetAccIterator> pWidgetAccIterator( |
| 804 m_pXFADocView->CreateWidgetAccIterator()); | 789 m_pXFADocView->CreateWidgetAccIterator()); |
| 805 if (pWidgetAccIterator) { | 790 if (pWidgetAccIterator) { |
| 806 CXFA_EventParam Param; | 791 CXFA_EventParam Param; |
| 807 Param.m_eType = XFA_EVENT_PreSubmit; | 792 Param.m_eType = XFA_EVENT_PreSubmit; |
| 808 while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) | 793 while (CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext()) |
| 809 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | 794 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 810 } | 795 } |
| 811 | 796 |
| 812 pWidgetAccIterator.reset(m_pXFADocView->CreateWidgetAccIterator()); | 797 pWidgetAccIterator.reset(m_pXFADocView->CreateWidgetAccIterator()); |
| 813 if (pWidgetAccIterator) { | 798 if (!pWidgetAccIterator) |
| 814 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 799 return TRUE; |
| 800 | |
| 801 CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 802 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 803 while (pWidgetAcc) { | |
| 804 int fRet = pWidgetAcc->ProcessValidate(-1); | |
| 805 if (fRet == XFA_EVENTERROR_Error) { | |
| 806 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 807 if (!pEnv) | |
| 808 return FALSE; | |
| 809 | |
| 810 CFX_WideString ws; | |
| 811 ws.FromLocal(IDS_XFA_Validate_Input); | |
| 812 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 813 int len = bs.GetLength(); | |
| 814 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", | |
| 815 0, 1); | |
| 816 bs.ReleaseBuffer(len); | |
| 817 return FALSE; | |
| 818 } | |
| 815 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 819 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 816 while (pWidgetAcc) { | |
| 817 int fRet = pWidgetAcc->ProcessValidate(-1); | |
| 818 if (fRet == XFA_EVENTERROR_Error) { | |
| 819 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | |
| 820 if (!pEnv) | |
| 821 return FALSE; | |
| 822 CFX_WideString ws; | |
| 823 ws.FromLocal(IDS_XFA_Validate_Input); | |
| 824 CFX_ByteString bs = ws.UTF16LE_Encode(); | |
| 825 int len = bs.GetLength() / sizeof(unsigned short); | |
| 826 pEnv->FFI_Alert( | |
| 827 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), | |
| 828 (FPDF_WIDESTRING)L"", 0, 1); | |
| 829 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 830 return FALSE; | |
| 831 } | |
| 832 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | |
| 833 } | |
| 834 m_pXFADocView->UpdateDocView(); | |
| 835 } | 820 } |
| 821 m_pXFADocView->UpdateDocView(); | |
| 822 | |
| 836 return TRUE; | 823 return TRUE; |
| 837 } | 824 } |
| 838 | 825 |
| 839 void CPDFXFA_Document::OnAfterNotifySubmit() { | 826 void CPDFXFA_Document::OnAfterNotifySubmit() { |
| 840 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) | 827 if (m_iDocType != DOCTYPE_DYNAMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA) |
| 841 return; | 828 return; |
| 842 | 829 |
| 843 if (!m_pXFADocView) | 830 if (!m_pXFADocView) |
| 844 return; | 831 return; |
| 845 | 832 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 858 while (pWidgetAcc) { | 845 while (pWidgetAcc) { |
| 859 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); | 846 pWidgetHandler->ProcessEvent(pWidgetAcc, &Param); |
| 860 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 847 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 861 } | 848 } |
| 862 m_pXFADocView->UpdateDocView(); | 849 m_pXFADocView->UpdateDocView(); |
| 863 } | 850 } |
| 864 | 851 |
| 865 FX_BOOL CPDFXFA_Document::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { | 852 FX_BOOL CPDFXFA_Document::SubmitData(CXFA_FFDoc* hDoc, CXFA_Submit submit) { |
| 866 if (!NotifySubmit(TRUE) || !m_pXFADocView) | 853 if (!NotifySubmit(TRUE) || !m_pXFADocView) |
| 867 return FALSE; | 854 return FALSE; |
| 855 | |
| 868 m_pXFADocView->UpdateDocView(); | 856 m_pXFADocView->UpdateDocView(); |
| 869 | |
| 870 FX_BOOL ret = SubmitDataInternal(hDoc, submit); | 857 FX_BOOL ret = SubmitDataInternal(hDoc, submit); |
| 871 NotifySubmit(FALSE); | 858 NotifySubmit(FALSE); |
| 872 return ret; | 859 return ret; |
| 873 } | 860 } |
| 874 | 861 |
| 875 IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(CXFA_FFDoc* hDoc, | 862 IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(CXFA_FFDoc* hDoc, |
| 876 const CFX_WideString& wsLink) { | 863 const CFX_WideString& wsLink) { |
| 877 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 864 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 878 if (!pEnv) | 865 if (!pEnv) |
| 879 return FALSE; | 866 return FALSE; |
| 867 | |
| 880 CFX_ByteString bs = wsLink.UTF16LE_Encode(); | 868 CFX_ByteString bs = wsLink.UTF16LE_Encode(); |
| 881 int len = bs.GetLength() / sizeof(unsigned short); | 869 int len = bs.GetLength(); |
| 882 FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile( | 870 FPDF_FILEHANDLER* pFileHandler = |
| 883 0, (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), "rb"); | 871 pEnv->FFI_OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb"); |
|
Tom Sepez
2016/09/08 16:53:36
pre-existing: casting a buffer of bytestring to w
dsinclair
2016/09/12 13:25:49
Acknowledged.
| |
| 884 bs.ReleaseBuffer(len * sizeof(unsigned short)); | 872 bs.ReleaseBuffer(len); |
| 885 | 873 |
| 886 if (!pFileHandler) | 874 if (!pFileHandler) |
| 887 return nullptr; | 875 return nullptr; |
| 888 return new CFPDF_FileStream(pFileHandler); | 876 return new CFPDF_FileStream(pFileHandler); |
| 889 } | 877 } |
| 890 | 878 |
| 891 FX_BOOL CPDFXFA_Document::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, | 879 FX_BOOL CPDFXFA_Document::ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, |
| 892 int fileType, | 880 int fileType, |
| 893 FPDF_DWORD encodeType, | 881 FPDF_DWORD encodeType, |
| 894 FPDF_DWORD flag) { | 882 FPDF_DWORD flag) { |
| 895 if (!m_pXFADocView) | 883 if (!m_pXFADocView) |
| 896 return FALSE; | 884 return FALSE; |
| 897 | 885 |
| 898 CFX_ByteString content; | 886 CFX_ByteString content; |
| 899 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 887 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 900 if (!pEnv) | 888 if (!pEnv) |
| 901 return FALSE; | 889 return FALSE; |
| 902 | 890 |
| 903 CFPDF_FileStream fileStream(pFileHandler); | 891 CFPDF_FileStream fileStream(pFileHandler); |
| 904 | |
| 905 if (fileType == FXFA_SAVEAS_XML) { | 892 if (fileType == FXFA_SAVEAS_XML) { |
| 906 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; | 893 const char kContent[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; |
| 907 fileStream.WriteBlock(kContent, 0, strlen(kContent)); | 894 fileStream.WriteBlock(kContent, 0, strlen(kContent)); |
| 908 m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); | 895 m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); |
| 909 return TRUE; | 896 return TRUE; |
| 910 } | 897 } |
| 911 | 898 |
| 912 if (fileType != FXFA_SAVEAS_XDP) | 899 if (fileType != FXFA_SAVEAS_XDP) |
| 913 return TRUE; | 900 return TRUE; |
| 914 | 901 |
| 915 if (!flag) { | 902 if (!flag) { |
| 916 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | 903 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 917 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | 904 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 918 } | 905 } |
| 919 if (!m_pPDFDoc) { | 906 if (!m_pPDFDoc) { |
| 920 fileStream.Flush(); | 907 fileStream.Flush(); |
| 921 return FALSE; | 908 return FALSE; |
| 922 } | 909 } |
| 910 | |
| 923 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); | 911 CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot(); |
| 924 if (!pRoot) { | 912 if (!pRoot) { |
| 925 fileStream.Flush(); | 913 fileStream.Flush(); |
| 926 return FALSE; | 914 return FALSE; |
| 927 } | 915 } |
| 916 | |
| 928 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 917 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 929 if (!pAcroForm) { | 918 if (!pAcroForm) { |
| 930 fileStream.Flush(); | 919 fileStream.Flush(); |
| 931 return FALSE; | 920 return FALSE; |
| 932 } | 921 } |
| 922 | |
| 933 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); | 923 CPDF_Array* pArray = ToArray(pAcroForm->GetObjectBy("XFA")); |
| 934 if (!pArray) { | 924 if (!pArray) { |
| 935 fileStream.Flush(); | 925 fileStream.Flush(); |
| 936 return FALSE; | 926 return FALSE; |
| 937 } | 927 } |
| 938 | 928 |
| 939 int size = pArray->GetCount(); | 929 int size = pArray->GetCount(); |
| 940 for (int i = 1; i < size; i += 2) { | 930 for (int i = 1; i < size; i += 2) { |
| 941 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); | 931 CPDF_Object* pPDFObj = pArray->GetObjectAt(i); |
| 942 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); | 932 CPDF_Object* pPrePDFObj = pArray->GetObjectAt(i - 1); |
| 943 if (!pPrePDFObj->IsString()) | 933 if (!pPrePDFObj->IsString()) |
| 944 continue; | 934 continue; |
| 945 if (!pPDFObj->IsReference()) | 935 if (!pPDFObj->IsReference()) |
| 946 continue; | 936 continue; |
| 937 | |
| 947 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); | 938 CPDF_Object* pDirectObj = pPDFObj->GetDirect(); |
| 948 if (!pDirectObj->IsStream()) | 939 if (!pDirectObj->IsStream()) |
| 949 continue; | 940 continue; |
| 950 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) | 941 if (pPrePDFObj->GetString() == "config" && !(flag & FXFA_CONFIG)) |
| 951 continue; | 942 continue; |
| 952 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) | 943 if (pPrePDFObj->GetString() == "template" && !(flag & FXFA_TEMPLATE)) |
| 953 continue; | 944 continue; |
| 954 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) | 945 if (pPrePDFObj->GetString() == "localeSet" && !(flag & FXFA_LOCALESET)) |
| 955 continue; | 946 continue; |
| 956 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) | 947 if (pPrePDFObj->GetString() == "datasets" && !(flag & FXFA_DATASETS)) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 986 if (csSrcContent.Find(L" localeSet ", 0) != -1) | 977 if (csSrcContent.Find(L" localeSet ", 0) != -1) |
| 987 flag |= FXFA_LOCALESET; | 978 flag |= FXFA_LOCALESET; |
| 988 if (csSrcContent.Find(L" datasets ", 0) != -1) | 979 if (csSrcContent.Find(L" datasets ", 0) != -1) |
| 989 flag |= FXFA_DATASETS; | 980 flag |= FXFA_DATASETS; |
| 990 if (csSrcContent.Find(L" xmpmeta ", 0) != -1) | 981 if (csSrcContent.Find(L" xmpmeta ", 0) != -1) |
| 991 flag |= FXFA_XMPMETA; | 982 flag |= FXFA_XMPMETA; |
| 992 if (csSrcContent.Find(L" xfdf ", 0) != -1) | 983 if (csSrcContent.Find(L" xfdf ", 0) != -1) |
| 993 flag |= FXFA_XFDF; | 984 flag |= FXFA_XFDF; |
| 994 if (csSrcContent.Find(L" form ", 0) != -1) | 985 if (csSrcContent.Find(L" form ", 0) != -1) |
| 995 flag |= FXFA_FORM; | 986 flag |= FXFA_FORM; |
| 996 if (flag == 0) | 987 if (flag == 0) { |
| 997 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | | 988 flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | |
| 998 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; | 989 FXFA_XMPMETA | FXFA_XFDF | FXFA_FORM; |
| 990 } | |
| 999 } | 991 } |
| 1000 | 992 |
| 1001 FX_BOOL CPDFXFA_Document::MailToInfo(CFX_WideString& csURL, | 993 FX_BOOL CPDFXFA_Document::MailToInfo(CFX_WideString& csURL, |
| 1002 CFX_WideString& csToAddress, | 994 CFX_WideString& csToAddress, |
| 1003 CFX_WideString& csCCAddress, | 995 CFX_WideString& csCCAddress, |
| 1004 CFX_WideString& csBCCAddress, | 996 CFX_WideString& csBCCAddress, |
| 1005 CFX_WideString& csSubject, | 997 CFX_WideString& csSubject, |
| 1006 CFX_WideString& csMsg) { | 998 CFX_WideString& csMsg) { |
| 1007 CFX_WideString srcURL = csURL; | 999 CFX_WideString srcURL = csURL; |
| 1008 srcURL.TrimLeft(); | 1000 srcURL.TrimLeft(); |
| 1009 if (0 != srcURL.Left(7).CompareNoCase(L"mailto:")) | 1001 if (srcURL.Left(7).CompareNoCase(L"mailto:") != 0) |
| 1010 return FALSE; | 1002 return FALSE; |
| 1003 | |
| 1011 int pos = srcURL.Find(L'?', 0); | 1004 int pos = srcURL.Find(L'?', 0); |
| 1012 CFX_WideString tmp; | 1005 CFX_WideString tmp; |
| 1013 if (pos == -1) { | 1006 if (pos == -1) { |
| 1014 pos = srcURL.Find(L'@', 0); | 1007 pos = srcURL.Find(L'@', 0); |
| 1015 if (pos == -1) | 1008 if (pos == -1) |
| 1016 return FALSE; | 1009 return FALSE; |
| 1017 | 1010 |
| 1018 tmp = srcURL.Right(csURL.GetLength() - 7); | 1011 tmp = srcURL.Right(csURL.GetLength() - 7); |
| 1019 tmp.TrimLeft(); | |
| 1020 tmp.TrimRight(); | |
| 1021 } else { | 1012 } else { |
| 1022 tmp = srcURL.Left(pos); | 1013 tmp = srcURL.Left(pos); |
| 1023 tmp = tmp.Right(tmp.GetLength() - 7); | 1014 tmp = tmp.Right(tmp.GetLength() - 7); |
| 1024 tmp.TrimLeft(); | |
| 1025 tmp.TrimRight(); | |
| 1026 } | 1015 } |
| 1016 tmp.TrimLeft(); | |
| 1017 tmp.TrimRight(); | |
| 1027 | 1018 |
| 1028 csToAddress = tmp; | 1019 csToAddress = tmp; |
| 1029 | 1020 |
| 1030 srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); | 1021 srcURL = srcURL.Right(srcURL.GetLength() - (pos + 1)); |
| 1031 while (!srcURL.IsEmpty()) { | 1022 while (!srcURL.IsEmpty()) { |
| 1032 srcURL.TrimLeft(); | 1023 srcURL.TrimLeft(); |
| 1033 srcURL.TrimRight(); | 1024 srcURL.TrimRight(); |
| 1034 pos = srcURL.Find(L'&', 0); | 1025 pos = srcURL.Find(L'&', 0); |
| 1035 if (pos == -1) | |
| 1036 tmp = srcURL; | |
| 1037 else | |
| 1038 tmp = srcURL.Left(pos); | |
| 1039 | 1026 |
| 1027 tmp = (pos == -1) ? srcURL : srcURL.Left(pos); | |
|
dsinclair
2016/09/08 15:13:51
()'s aren't strictly needed but seems a bit easier
| |
| 1040 tmp.TrimLeft(); | 1028 tmp.TrimLeft(); |
| 1041 tmp.TrimRight(); | 1029 tmp.TrimRight(); |
| 1042 if (tmp.GetLength() >= 3 && 0 == tmp.Left(3).CompareNoCase(L"cc=")) { | 1030 if (tmp.GetLength() >= 3 && tmp.Left(3).CompareNoCase(L"cc=") == 0) { |
| 1043 tmp = tmp.Right(tmp.GetLength() - 3); | 1031 tmp = tmp.Right(tmp.GetLength() - 3); |
| 1044 if (!csCCAddress.IsEmpty()) | 1032 if (!csCCAddress.IsEmpty()) |
| 1045 csCCAddress += L';'; | 1033 csCCAddress += L';'; |
| 1046 csCCAddress += tmp; | 1034 csCCAddress += tmp; |
| 1047 | |
| 1048 } else if (tmp.GetLength() >= 4 && | 1035 } else if (tmp.GetLength() >= 4 && |
| 1049 0 == tmp.Left(4).CompareNoCase(L"bcc=")) { | 1036 tmp.Left(4).CompareNoCase(L"bcc=") == 0) { |
| 1050 tmp = tmp.Right(tmp.GetLength() - 4); | 1037 tmp = tmp.Right(tmp.GetLength() - 4); |
| 1051 if (!csBCCAddress.IsEmpty()) | 1038 if (!csBCCAddress.IsEmpty()) |
| 1052 csBCCAddress += L';'; | 1039 csBCCAddress += L';'; |
| 1053 csBCCAddress += tmp; | 1040 csBCCAddress += tmp; |
| 1054 } else if (tmp.GetLength() >= 8 && | 1041 } else if (tmp.GetLength() >= 8 && |
| 1055 0 == tmp.Left(8).CompareNoCase(L"subject=")) { | 1042 tmp.Left(8).CompareNoCase(L"subject=") == 0) { |
| 1056 tmp = tmp.Right(tmp.GetLength() - 8); | 1043 tmp = tmp.Right(tmp.GetLength() - 8); |
| 1057 csSubject += tmp; | 1044 csSubject += tmp; |
| 1058 } else if (tmp.GetLength() >= 5 && | 1045 } else if (tmp.GetLength() >= 5 && |
| 1059 0 == tmp.Left(5).CompareNoCase(L"body=")) { | 1046 tmp.Left(5).CompareNoCase(L"body=") == 0) { |
| 1060 tmp = tmp.Right(tmp.GetLength() - 5); | 1047 tmp = tmp.Right(tmp.GetLength() - 5); |
| 1061 csMsg += tmp; | 1048 csMsg += tmp; |
| 1062 } | 1049 } |
| 1063 if (pos == -1) | 1050 srcURL = (pos == -1) ? L"" : srcURL.Right(csURL.GetLength() - (pos + 1)); |
| 1064 srcURL = L""; | |
| 1065 else | |
| 1066 srcURL = srcURL.Right(csURL.GetLength() - (pos + 1)); | |
| 1067 } | 1051 } |
| 1068 csToAddress.Replace(L",", L";"); | 1052 csToAddress.Replace(L",", L";"); |
| 1069 csCCAddress.Replace(L",", L";"); | 1053 csCCAddress.Replace(L",", L";"); |
| 1070 csBCCAddress.Replace(L",", L";"); | 1054 csBCCAddress.Replace(L",", L";"); |
| 1071 return TRUE; | 1055 return TRUE; |
| 1072 } | 1056 } |
| 1073 | 1057 |
| 1074 FX_BOOL CPDFXFA_Document::SubmitDataInternal(CXFA_FFDoc* hDoc, | 1058 FX_BOOL CPDFXFA_Document::SubmitDataInternal(CXFA_FFDoc* hDoc, |
| 1075 CXFA_Submit submit) { | 1059 CXFA_Submit submit) { |
| 1076 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 1060 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 1077 if (!pEnv) | 1061 if (!pEnv) |
| 1078 return FALSE; | 1062 return FALSE; |
| 1063 | |
| 1079 CFX_WideStringC csURLC; | 1064 CFX_WideStringC csURLC; |
| 1080 submit.GetSubmitTarget(csURLC); | 1065 submit.GetSubmitTarget(csURLC); |
| 1081 CFX_WideString csURL(csURLC); | 1066 CFX_WideString csURL(csURLC); |
| 1082 if (csURL.IsEmpty()) { | 1067 if (csURL.IsEmpty()) { |
| 1083 CFX_WideString ws; | 1068 CFX_WideString ws; |
| 1084 ws.FromLocal("Submit cancelled."); | 1069 ws.FromLocal("Submit cancelled."); |
| 1085 CFX_ByteString bs = ws.UTF16LE_Encode(); | 1070 CFX_ByteString bs = ws.UTF16LE_Encode(); |
| 1086 int len = bs.GetLength() / sizeof(unsigned short); | 1071 int len = bs.GetLength(); |
| 1087 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short)), | 1072 pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len), (FPDF_WIDESTRING)L"", 0, |
|
dsinclair
2016/09/08 15:13:51
These can't static_cast because it's a unsigned sh
Tom Sepez
2016/09/08 16:53:36
ok, pre-existing, but casting bs to FPDF_Widestrin
dsinclair
2016/09/12 13:25:49
Followup.
| |
| 1088 (FPDF_WIDESTRING)L"", 0, 4); | 1073 4); |
| 1089 bs.ReleaseBuffer(len * sizeof(unsigned short)); | 1074 bs.ReleaseBuffer(len); |
|
Tom Sepez
2016/09/08 16:53:36
ReleaseBuffer isn't required as |bs| still owns th
dsinclair
2016/09/12 13:25:49
Done.
| |
| 1090 return FALSE; | 1075 return FALSE; |
| 1091 } | 1076 } |
| 1077 | |
| 1092 FPDF_BOOL bRet = TRUE; | 1078 FPDF_BOOL bRet = TRUE; |
| 1093 FPDF_FILEHANDLER* pFileHandler = nullptr; | 1079 FPDF_FILEHANDLER* pFileHandler = nullptr; |
| 1094 int fileFlag = -1; | 1080 int fileFlag = -1; |
| 1095 switch (submit.GetSubmitFormat()) { | 1081 switch (submit.GetSubmitFormat()) { |
| 1096 case XFA_ATTRIBUTEENUM_Xdp: { | 1082 case XFA_ATTRIBUTEENUM_Xdp: { |
| 1097 CFX_WideStringC csContentC; | 1083 CFX_WideStringC csContentC; |
| 1098 submit.GetSubmitXDPContent(csContentC); | 1084 submit.GetSubmitXDPContent(csContentC); |
| 1099 CFX_WideString csContent; | 1085 CFX_WideString csContent; |
| 1100 csContent = csContentC; | 1086 csContent = csContentC; |
| 1101 csContent.TrimLeft(); | 1087 csContent.TrimLeft(); |
| 1102 csContent.TrimRight(); | 1088 csContent.TrimRight(); |
| 1103 CFX_WideString space; | 1089 CFX_WideString space; |
| 1104 space.FromLocal(" "); | 1090 space.FromLocal(" "); |
| 1105 csContent = space + csContent + space; | 1091 csContent = space + csContent + space; |
| 1106 FPDF_DWORD flag = 0; | 1092 FPDF_DWORD flag = 0; |
| 1107 if (submit.IsSubmitEmbedPDF()) | 1093 if (submit.IsSubmitEmbedPDF()) |
| 1108 flag |= FXFA_PDF; | 1094 flag |= FXFA_PDF; |
| 1095 | |
| 1109 ToXFAContentFlags(csContent, flag); | 1096 ToXFAContentFlags(csContent, flag); |
| 1110 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); | 1097 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, nullptr, "wb"); |
| 1111 fileFlag = FXFA_SAVEAS_XDP; | 1098 fileFlag = FXFA_SAVEAS_XDP; |
| 1112 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); | 1099 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag); |
| 1113 break; | 1100 break; |
| 1114 } | 1101 } |
| 1115 case XFA_ATTRIBUTEENUM_Xml: | 1102 case XFA_ATTRIBUTEENUM_Xml: |
| 1116 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | 1103 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
| 1117 fileFlag = FXFA_SAVEAS_XML; | 1104 fileFlag = FXFA_SAVEAS_XML; |
| 1118 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, 0x01111111); | 1105 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, 0x01111111); |
| 1119 break; | 1106 break; |
| 1120 case XFA_ATTRIBUTEENUM_Pdf: | 1107 case XFA_ATTRIBUTEENUM_Pdf: |
| 1121 break; | 1108 break; |
| 1122 case XFA_ATTRIBUTEENUM_Urlencoded: | 1109 case XFA_ATTRIBUTEENUM_Urlencoded: |
| 1123 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); | 1110 pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, nullptr, "wb"); |
| 1124 fileFlag = FXFA_SAVEAS_XML; | 1111 fileFlag = FXFA_SAVEAS_XML; |
| 1125 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, 0x01111111); | 1112 ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0, 0x01111111); |
| 1126 break; | 1113 break; |
| 1127 default: | 1114 default: |
| 1128 return false; | 1115 return false; |
| 1129 } | 1116 } |
| 1130 if (!pFileHandler) | 1117 if (!pFileHandler) |
| 1131 return FALSE; | 1118 return FALSE; |
| 1132 if (0 == csURL.Left(7).CompareNoCase(L"mailto:")) { | 1119 if (csURL.Left(7).CompareNoCase(L"mailto:") == 0) { |
| 1133 CFX_WideString csToAddress; | 1120 CFX_WideString csToAddress; |
| 1134 CFX_WideString csCCAddress; | 1121 CFX_WideString csCCAddress; |
| 1135 CFX_WideString csBCCAddress; | 1122 CFX_WideString csBCCAddress; |
| 1136 CFX_WideString csSubject; | 1123 CFX_WideString csSubject; |
| 1137 CFX_WideString csMsg; | 1124 CFX_WideString csMsg; |
| 1138 bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, | 1125 bRet = MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, |
| 1139 csMsg); | 1126 csMsg); |
| 1140 if (!bRet) | 1127 if (!bRet) |
| 1141 return FALSE; | 1128 return FALSE; |
| 1129 | |
| 1142 CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); | 1130 CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode(); |
| 1143 CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); | 1131 CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode(); |
| 1144 CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); | 1132 CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode(); |
| 1145 CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); | 1133 CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode(); |
| 1146 CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); | 1134 CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode(); |
| 1147 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); | 1135 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength()); |
| 1148 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); | 1136 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength()); |
| 1149 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); | 1137 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength()); |
| 1150 FPDF_WIDESTRING pSubject = | 1138 FPDF_WIDESTRING pSubject = |
| 1151 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); | 1139 (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength()); |
| 1152 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); | 1140 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength()); |
| 1153 pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); | 1141 pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg); |
| 1154 bsTo.ReleaseBuffer(); | 1142 bsTo.ReleaseBuffer(); |
| 1155 bsCC.ReleaseBuffer(); | 1143 bsCC.ReleaseBuffer(); |
| 1156 bsBcc.ReleaseBuffer(); | 1144 bsBcc.ReleaseBuffer(); |
| 1157 bsSubject.ReleaseBuffer(); | 1145 bsSubject.ReleaseBuffer(); |
| 1158 bsMsg.ReleaseBuffer(); | 1146 bsMsg.ReleaseBuffer(); |
| 1159 } else { | 1147 } else { |
| 1160 // HTTP or FTP | 1148 // HTTP or FTP |
| 1161 CFX_WideString ws; | 1149 CFX_WideString ws; |
| 1162 CFX_ByteString bs = csURL.UTF16LE_Encode(); | 1150 CFX_ByteString bs = csURL.UTF16LE_Encode(); |
| 1163 int len = bs.GetLength() / sizeof(unsigned short); | 1151 int len = bs.GetLength(); |
| 1164 pEnv->FFI_UploadTo( | 1152 pEnv->FFI_UploadTo(pFileHandler, fileFlag, |
| 1165 pFileHandler, fileFlag, | 1153 (FPDF_WIDESTRING)bs.GetBuffer(len)); |
| 1166 (FPDF_WIDESTRING)bs.GetBuffer(len * sizeof(unsigned short))); | 1154 bs.ReleaseBuffer(len); |
| 1167 bs.ReleaseBuffer(len * sizeof(unsigned short)); | |
| 1168 } | 1155 } |
| 1169 return bRet; | 1156 return bRet; |
| 1170 } | 1157 } |
| 1171 | 1158 |
| 1172 FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc, | 1159 FX_BOOL CPDFXFA_Document::SetGlobalProperty(CXFA_FFDoc* hDoc, |
| 1173 const CFX_ByteStringC& szPropName, | 1160 const CFX_ByteStringC& szPropName, |
| 1174 CFXJSE_Value* pValue) { | 1161 CFXJSE_Value* pValue) { |
| 1175 if (hDoc != m_pXFADoc.get()) | 1162 if (hDoc != m_pXFADoc.get()) |
| 1176 return FALSE; | 1163 return FALSE; |
| 1177 | 1164 |
| 1178 if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime()) | 1165 if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime()) |
| 1179 return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetValueByName(szPropName, | 1166 return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetValueByName(szPropName, |
| 1180 pValue); | 1167 pValue); |
| 1181 return FALSE; | 1168 return FALSE; |
| 1182 } | 1169 } |
| 1183 FX_BOOL CPDFXFA_Document::GetPDFScriptObject(CXFA_FFDoc* hDoc, | |
| 1184 const CFX_ByteStringC& utf8Name, | |
| 1185 CFXJSE_Value* pValue) { | |
| 1186 if (hDoc != m_pXFADoc.get()) | |
| 1187 return FALSE; | |
| 1188 | 1170 |
| 1189 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) | |
| 1190 return FALSE; | |
| 1191 | |
| 1192 if (!m_pJSContext) { | |
| 1193 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); | |
| 1194 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); | |
| 1195 } | |
| 1196 | |
| 1197 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(utf8Name, pValue); | |
| 1198 } | |
| 1199 FX_BOOL CPDFXFA_Document::GetGlobalProperty(CXFA_FFDoc* hDoc, | 1171 FX_BOOL CPDFXFA_Document::GetGlobalProperty(CXFA_FFDoc* hDoc, |
| 1200 const CFX_ByteStringC& szPropName, | 1172 const CFX_ByteStringC& szPropName, |
| 1201 CFXJSE_Value* pValue) { | 1173 CFXJSE_Value* pValue) { |
| 1202 if (hDoc != m_pXFADoc.get()) | 1174 if (hDoc != m_pXFADoc.get()) |
| 1203 return FALSE; | 1175 return FALSE; |
| 1204 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) | 1176 if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime()) |
| 1205 return FALSE; | 1177 return FALSE; |
| 1206 | 1178 |
| 1207 if (!m_pJSContext) { | 1179 if (!m_pJSContext) { |
| 1208 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); | 1180 m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc.get()); |
| 1209 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); | 1181 m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext(); |
| 1210 } | 1182 } |
| 1211 | 1183 |
| 1212 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName, | 1184 return m_pSDKDoc->GetEnv()->GetJSRuntime()->GetValueByName(szPropName, |
| 1213 pValue); | 1185 pValue); |
| 1214 } | 1186 } |
| OLD | NEW |