Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: fpdfsdk/src/fpdfformfill.cpp

Issue 1153553003: Make CPDFXFA_App / IXFA_AppProvider saner (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Address comments. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdfeditpage.cpp ('k') | fpdfsdk/src/fpdfsave.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../public/fpdf_formfill.h" 7 #include "../../public/fpdf_formfill.h"
8 #include "../../public/fpdfview.h" 8 #include "../../public/fpdfview.h"
9 #include "../include/fsdk_define.h" 9 #include "../include/fsdk_define.h"
10 #include "../include/fpdfxfa/fpdfxfa_doc.h" 10 #include "../include/fpdfxfa/fpdfxfa_doc.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 { 89 {
90 if(!document || !formInfo || formInfo->version!=2) 90 if(!document || !formInfo || formInfo->version!=2)
91 return NULL; 91 return NULL;
92 CPDFXFA_Document * pDocument = (CPDFXFA_Document*) document; 92 CPDFXFA_Document * pDocument = (CPDFXFA_Document*) document;
93 CPDFDoc_Environment * pEnv = NULL; 93 CPDFDoc_Environment * pEnv = NULL;
94 pEnv = new CPDFDoc_Environment(pDocument); 94 pEnv = new CPDFDoc_Environment(pDocument);
95 if (!pEnv) 95 if (!pEnv)
96 return NULL; 96 return NULL;
97 pEnv->RegAppHandle(formInfo); 97 pEnv->RegAppHandle(formInfo);
98 98
99 » CPDFXFA_App* pApp = FPDFXFA_GetApp(); 99 » CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
100 pApp->AddFormFillEnv(pEnv); 100 pApp->AddFormFillEnv(pEnv);
101 101
102 if(pEnv->GetPDFXFADocument()) 102 if(pEnv->GetPDFXFADocument())
103 { 103 {
104 //CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFX FADocument(), pEnv); 104 //CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFX FADocument(), pEnv);
105 CPDFSDK_Document* pSDKDoc = pDocument->GetSDKDocument(pEnv); 105 CPDFSDK_Document* pSDKDoc = pDocument->GetSDKDocument(pEnv);
106 if(pSDKDoc) { 106 if(pSDKDoc) {
107 pEnv->SetCurrentDoc(pSDKDoc); 107 pEnv->SetCurrentDoc(pSDKDoc);
108 } 108 }
109 } 109 }
110 return pEnv; 110 return pEnv;
111 } 111 }
112 112
113 DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) 113 DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle)
114 { 114 {
115 if (!hHandle) 115 if (!hHandle)
116 » » return; 116 » » return;
117 » //CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurren tDoc(); 117 » CPDFXFA_App* pApp = CPDFXFA_App::GetInstance();
118 » //if(pSDKDoc)
119 » //{
120 » » //((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
121 » » //CPDFXFA_Document* pDoc = ((CPDFDoc_Environment*)hHandle)->GetP DFXFADocument();
122 » » //if (pDoc)
123 » » //» pDoc->ReleaseSDKDoc();
124 » //}
125 » CPDFXFA_App* pApp = FPDFXFA_GetApp();
126 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); 118 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle);
127 delete (CPDFDoc_Environment*)hHandle; 119 delete (CPDFDoc_Environment*)hHandle;
128 hHandle = NULL; 120 hHandle = NULL;
129 } 121 }
130 122
131 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y) 123 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
132 { 124 {
133 if (!hHandle || !page) 125 if (!hHandle || !page)
134 return FALSE; 126 return FALSE;
135 // CPDF_Page * pPage = (CPDF_Page*) page; 127 // CPDF_Page * pPage = (CPDF_Page*) page;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 { 336 {
345 delete pDevice; 337 delete pDevice;
346 pDevice = NULL; 338 pDevice = NULL;
347 } 339 }
348 340
349 } 341 }
350 DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, FPDF_WIDGET hWid get) 342 DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, FPDF_WIDGET hWid get)
351 { 343 {
352 if (NULL == hWidget || NULL == document) 344 if (NULL == hWidget || NULL == document)
353 return; 345 return;
354
355 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
356 346
347 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
357 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 348 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
358 return; 349 return;
359 350
360 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 351 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
361
362 if (pXFAMenuHander == NULL) 352 if (pXFAMenuHander == NULL)
363 return; 353 return;
364 354
365 pXFAMenuHander->Undo((XFA_HWIDGET)hWidget); 355 pXFAMenuHander->Undo((XFA_HWIDGET)hWidget);
366 356
367 } 357 }
368 DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, FPDF_WIDGET hWid get) 358 DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, FPDF_WIDGET hWid get)
369 { 359 {
370 if (NULL == hWidget || NULL == document) 360 if (NULL == hWidget || NULL == document)
371 return; 361 return;
372 » 362
373 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 363 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
374 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 364 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
375 return; 365 return;
376 366
377 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 367 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
378
379 if (pXFAMenuHander == NULL) 368 if (pXFAMenuHander == NULL)
380 return; 369 return;
381 370
382 pXFAMenuHander->Redo((XFA_HWIDGET)hWidget); 371 pXFAMenuHander->Redo((XFA_HWIDGET)hWidget);
383 } 372 }
384 373
385 DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) 374 DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
386 { 375 {
387 if (NULL == hWidget || NULL == document) 376 if (NULL == hWidget || NULL == document)
388 return; 377 return;
389 » 378
390 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 379 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
391 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 380 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
392 return; 381 return;
393 382
394 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 383 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
395
396 if (pXFAMenuHander == NULL) 384 if (pXFAMenuHander == NULL)
397 return; 385 return;
398 386
399 pXFAMenuHander->SelectAll((XFA_HWIDGET)hWidget); 387 pXFAMenuHander->SelectAll((XFA_HWIDGET)hWidget);
400 } 388 }
401 DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, FPDF_WIDGET hWid get, FPDF_WIDESTRING wsText, FPDF_DWORD* size) 389 DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, FPDF_WIDGET hWid get, FPDF_WIDESTRING wsText, FPDF_DWORD* size)
402 { 390 {
403 if (NULL == hWidget || NULL == document) 391 if (NULL == hWidget || NULL == document)
404 return; 392 return;
405 » 393
406 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 394 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
407 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 395 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
408 return; 396 return;
409 397
410 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 398 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
411
412 if (pXFAMenuHander == NULL) 399 if (pXFAMenuHander == NULL)
413 return; 400 return;
414 401
415 CFX_WideString wsCpText; 402 CFX_WideString wsCpText;
416 pXFAMenuHander->Copy((XFA_HWIDGET)hWidget, wsCpText); 403 pXFAMenuHander->Copy((XFA_HWIDGET)hWidget, wsCpText);
417 404
418 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); 405 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
419
420 int len = bsCpText.GetLength()/sizeof(unsigned short); 406 int len = bsCpText.GetLength()/sizeof(unsigned short);
421
422 if (wsText == NULL) { 407 if (wsText == NULL) {
423 *size = len; 408 *size = len;
424 return; 409 return;
425 } 410 }
426 411
427 int real_size = len < *size ? len : *size; 412 int real_size = len < *size ? len : *size;
428 if (real_size > 0) 413 if (real_size > 0)
429 { 414 {
430 FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(u nsigned short)),real_size*sizeof(unsigned short)); 415 FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(u nsigned short)),real_size*sizeof(unsigned short));
431 bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); 416 bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short));
432 } 417 }
433 *size = real_size; 418 *size = real_size;
434 } 419 }
435 DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidg et, FPDF_WIDESTRING wsText, FPDF_DWORD* size) 420 DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidg et, FPDF_WIDESTRING wsText, FPDF_DWORD* size)
436 { 421 {
437 if (NULL == hWidget || NULL == document) 422 if (NULL == hWidget || NULL == document)
438 return; 423 return;
439 » 424 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
440 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;»
441 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 425 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
442 return; 426 return;
443 427
444 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 428 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
445
446 if (pXFAMenuHander == NULL) 429 if (pXFAMenuHander == NULL)
447 return; 430 return;
448 431
449 CFX_WideString wsCpText; 432 CFX_WideString wsCpText;
450 pXFAMenuHander->Cut((XFA_HWIDGET)hWidget, wsCpText); 433 pXFAMenuHander->Cut((XFA_HWIDGET)hWidget, wsCpText);
451 434
452 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); 435 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
453
454 int len = bsCpText.GetLength()/sizeof(unsigned short); 436 int len = bsCpText.GetLength()/sizeof(unsigned short);
455
456 if (wsText == NULL) { 437 if (wsText == NULL) {
457 *size = len; 438 *size = len;
458 return; 439 return;
459 } 440 }
460 441
461 int real_size = len < *size ? len : *size; 442 int real_size = len < *size ? len : *size;
462 if (real_size > 0) 443 if (real_size > 0)
463 { 444 {
464 FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(u nsigned short)),real_size*sizeof(unsigned short)); 445 FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(u nsigned short)),real_size*sizeof(unsigned short));
465 bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short)); 446 bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short));
466 } 447 }
467 *size = real_size; 448 *size = real_size;
468 } 449 }
469 DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWi dget, FPDF_WIDESTRING wsText, FPDF_DWORD size) 450 DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWi dget, FPDF_WIDESTRING wsText, FPDF_DWORD size)
470 { 451 {
471 if (NULL == hWidget || NULL == document) 452 if (NULL == hWidget || NULL == document)
472 return; 453 return;
473 » 454
474 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 455 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
475 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 456 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
476 return; 457 return;
477 458
478 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 459 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
479
480 if (pXFAMenuHander == NULL) 460 if (pXFAMenuHander == NULL)
481 return; 461 return;
482 462
483 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); 463 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
484
485 pXFAMenuHander->Paste((XFA_HWIDGET)hWidget, wstr); 464 pXFAMenuHander->Paste((XFA_HWIDGET)hWidget, wstr);
486 465
487 } 466 }
488 DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText) 467 DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText)
489 { 468 {
490 if (NULL == hWidget || NULL == document) 469 if (NULL == hWidget || NULL == document)
491 return; 470 return;
492 » 471
493 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 472 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
494 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 473 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
495 return; 474 return;
496 475
497 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 476 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
498
499 if (pXFAMenuHander == NULL) 477 if (pXFAMenuHander == NULL)
500 return; 478 return;
501 479
502 CFX_PointF ptPopup; 480 CFX_PointF ptPopup;
503 ptPopup.x = x; 481 ptPopup.x = x;
504 ptPopup.y = y; 482 ptPopup.y = y;
505 » CFX_ByteStringC bs(bsText); 483 » CFX_ByteStringC bs(bsText);
506 pXFAMenuHander->ReplaceSpellCheckWord((XFA_HWIDGET)hWidget,ptPopup,bs); 484 pXFAMenuHander->ReplaceSpellCheckWord((XFA_HWIDGET)hWidget,ptPopup,bs);
507 485
508 } 486 }
509 DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FP DF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle) 487 DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FP DF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle)
510 { 488 {
511 if (NULL == hWidget || NULL == document) 489 if (NULL == hWidget || NULL == document)
512 return; 490 return;
513 » 491
514 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;» 492 » CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
515 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static) 493 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocT ype() != XFA_DOCTYPE_Static)
516 return; 494 return;
517 495
518 » IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMen uHandler(); 496 » IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp ()->GetMenuHandler();
519
520 if (pXFAMenuHander == NULL) 497 if (pXFAMenuHander == NULL)
521 return; 498 return;
522 499
523 CFX_ByteStringArray* sSuggestWords = FX_NEW CFX_ByteStringArray; 500 CFX_ByteStringArray* sSuggestWords = FX_NEW CFX_ByteStringArray;
524 CFX_PointF ptPopup; 501 CFX_PointF ptPopup;
525 ptPopup.x = x; 502 ptPopup.x = x;
526 ptPopup.y = y; 503 ptPopup.y = y;
527 pXFAMenuHander->GetSuggestWords((XFA_HWIDGET)hWidget, ptPopup, *sSuggest Words); 504 pXFAMenuHander->GetSuggestWords((XFA_HWIDGET)hWidget, ptPopup, *sSuggest Words);
528 *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; 505 *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords;
529 } 506 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 if (bExistCAAction) 707 if (bExistCAAction)
731 { 708 {
732 CPDF_Action action = aa.GetAction(CPDF_AAction:: ClosePage); 709 CPDF_Action action = aa.GetAction(CPDF_AAction:: ClosePage);
733 pActionHandler->DoAction_Page(action, CPDF_AActi on::ClosePage, pSDKDoc); 710 pActionHandler->DoAction_Page(action, CPDF_AActi on::ClosePage, pSDKDoc);
734 } 711 }
735 } 712 }
736 } 713 }
737 } 714 }
738 715
739 716
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfeditpage.cpp ('k') | fpdfsdk/src/fpdfsave.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698