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 "xfa/fxfa/app/xfa_fftextedit.h" | 7 #include "xfa/fxfa/app/xfa_fftextedit.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "third_party/base/ptr_util.h" |
11 #include "xfa/fwl/core/cfwl_datetimepicker.h" | 12 #include "xfa/fwl/core/cfwl_datetimepicker.h" |
12 #include "xfa/fwl/core/cfwl_edit.h" | 13 #include "xfa/fwl/core/cfwl_edit.h" |
13 #include "xfa/fwl/core/cfwl_message.h" | 14 #include "xfa/fwl/core/cfwl_message.h" |
14 #include "xfa/fwl/core/fwl_noteimp.h" | 15 #include "xfa/fwl/core/fwl_noteimp.h" |
15 #include "xfa/fwl/core/ifwl_edit.h" | 16 #include "xfa/fwl/core/ifwl_edit.h" |
| 17 #include "xfa/fxfa/app/cxfa_ffdatetimeeditdelegate.h" |
| 18 #include "xfa/fxfa/app/cxfa_ffnumericeditdelegate.h" |
| 19 #include "xfa/fxfa/app/cxfa_fftexteditdelegate.h" |
16 #include "xfa/fxfa/app/xfa_fffield.h" | 20 #include "xfa/fxfa/app/xfa_fffield.h" |
17 #include "xfa/fxfa/app/xfa_fwladapter.h" | 21 #include "xfa/fxfa/app/xfa_fwladapter.h" |
18 #include "xfa/fxfa/app/xfa_textlayout.h" | 22 #include "xfa/fxfa/app/xfa_textlayout.h" |
19 #include "xfa/fxfa/cxfa_eventparam.h" | 23 #include "xfa/fxfa/cxfa_eventparam.h" |
20 #include "xfa/fxfa/parser/xfa_localevalue.h" | 24 #include "xfa/fxfa/parser/xfa_localevalue.h" |
21 #include "xfa/fxfa/xfa_ffapp.h" | 25 #include "xfa/fxfa/xfa_ffapp.h" |
22 #include "xfa/fxfa/xfa_ffdoc.h" | 26 #include "xfa/fxfa/xfa_ffdoc.h" |
23 #include "xfa/fxfa/xfa_ffdocview.h" | 27 #include "xfa/fxfa/xfa_ffdocview.h" |
24 #include "xfa/fxfa/xfa_ffpageview.h" | 28 #include "xfa/fxfa/xfa_ffpageview.h" |
25 #include "xfa/fxfa/xfa_ffwidget.h" | 29 #include "xfa/fxfa/xfa_ffwidget.h" |
26 | 30 |
27 CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_FFPageView* pPageView, | 31 CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_FFPageView* pPageView, |
28 CXFA_WidgetAcc* pDataAcc) | 32 CXFA_WidgetAcc* pDataAcc) |
29 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(nullptr) {} | 33 : CXFA_FFField(pPageView, pDataAcc) {} |
30 | 34 |
31 CXFA_FFTextEdit::~CXFA_FFTextEdit() { | 35 CXFA_FFTextEdit::~CXFA_FFTextEdit() { |
32 if (m_pNormalWidget) { | 36 if (m_pNormalWidget) { |
33 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 37 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
34 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 38 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
35 pNoteDriver->UnregisterEventTarget(pWidget); | 39 pNoteDriver->UnregisterEventTarget(pWidget); |
36 } | 40 } |
37 } | 41 } |
38 | 42 |
39 FX_BOOL CXFA_FFTextEdit::LoadWidget() { | 43 FX_BOOL CXFA_FFTextEdit::LoadWidget() { |
40 CFWL_Edit* pFWLEdit = new CFWL_Edit(GetFWLApp()); | 44 CFWL_Edit* pFWLEdit = new CFWL_Edit(GetFWLApp()); |
41 pFWLEdit->Initialize(); | 45 pFWLEdit->Initialize(); |
42 m_pNormalWidget = pFWLEdit; | 46 m_pNormalWidget = pFWLEdit; |
43 m_pNormalWidget->SetLayoutItem(this); | 47 m_pNormalWidget->SetLayoutItem(this); |
44 | 48 |
45 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 49 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
46 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 50 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
47 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | 51 pNoteDriver->RegisterEventTarget(pWidget, pWidget); |
48 | 52 |
49 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 53 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFTextEditDelegate>( |
50 m_pNormalWidget->SetCurrentDelegate(this); | 54 m_pNormalWidget->ReleaseDelegate(), this)); |
51 m_pNormalWidget->LockUpdate(); | 55 m_pNormalWidget->LockUpdate(); |
52 | 56 |
53 UpdateWidgetProperty(); | 57 UpdateWidgetProperty(); |
54 CFX_WideString wsText; | 58 CFX_WideString wsText; |
55 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); | 59 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
56 pFWLEdit->SetText(wsText); | 60 pFWLEdit->SetText(wsText); |
57 m_pNormalWidget->UnlockUpdate(); | 61 m_pNormalWidget->UnlockUpdate(); |
58 return CXFA_FFField::LoadWidget(); | 62 return CXFA_FFField::LoadWidget(); |
59 } | 63 } |
60 void CXFA_FFTextEdit::UpdateWidgetProperty() { | 64 void CXFA_FFTextEdit::UpdateWidgetProperty() { |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 eParam.m_pTarget = m_pDataAcc; | 395 eParam.m_pTarget = m_pDataAcc; |
392 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); | 396 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam); |
393 } | 397 } |
394 | 398 |
395 FX_BOOL CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { | 399 FX_BOOL CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) { |
396 if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit) | 400 if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit) |
397 return TRUE; | 401 return TRUE; |
398 return FALSE; | 402 return FALSE; |
399 } | 403 } |
400 | 404 |
401 void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) { | |
402 m_pOldDelegate->OnProcessMessage(pMessage); | |
403 } | |
404 | |
405 void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) { | |
406 CXFA_FFField::OnProcessEvent(pEvent); | |
407 switch (pEvent->GetClassID()) { | |
408 case CFWL_EventType::TextChanged: { | |
409 CFWL_EvtEdtTextChanged* event = (CFWL_EvtEdtTextChanged*)pEvent; | |
410 CFX_WideString wsChange; | |
411 OnTextChanged(m_pNormalWidget->GetWidget(), wsChange, event->wsPrevText); | |
412 break; | |
413 } | |
414 case CFWL_EventType::TextFull: { | |
415 OnTextFull(m_pNormalWidget->GetWidget()); | |
416 break; | |
417 } | |
418 case CFWL_EventType::CheckWord: { | |
419 CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged"); | |
420 CFWL_EvtEdtCheckWord* event = (CFWL_EvtEdtCheckWord*)pEvent; | |
421 event->bCheckWord = CheckWord(event->bsWord.AsStringC()); | |
422 break; | |
423 } | |
424 case CFWL_EventType::GetSuggestedWords: { | |
425 CFWL_EvtEdtGetSuggestWords* event = (CFWL_EvtEdtGetSuggestWords*)pEvent; | |
426 event->bSuggestWords = FALSE; | |
427 break; | |
428 } | |
429 default: | |
430 break; | |
431 } | |
432 m_pOldDelegate->OnProcessEvent(pEvent); | |
433 } | |
434 | |
435 void CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics* pGraphics, | |
436 const CFX_Matrix* pMatrix) { | |
437 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | |
438 } | |
439 | |
440 CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_FFPageView* pPageView, | 405 CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_FFPageView* pPageView, |
441 CXFA_WidgetAcc* pDataAcc) | 406 CXFA_WidgetAcc* pDataAcc) |
442 : CXFA_FFTextEdit(pPageView, pDataAcc) {} | 407 : CXFA_FFTextEdit(pPageView, pDataAcc) {} |
| 408 |
443 CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} | 409 CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {} |
| 410 |
444 FX_BOOL CXFA_FFNumericEdit::LoadWidget() { | 411 FX_BOOL CXFA_FFNumericEdit::LoadWidget() { |
445 CFWL_Edit* pWidget = new CFWL_Edit(GetFWLApp()); | 412 CFWL_Edit* pWidget = new CFWL_Edit(GetFWLApp()); |
446 pWidget->Initialize(); | 413 pWidget->Initialize(); |
447 m_pNormalWidget = pWidget; | 414 m_pNormalWidget = pWidget; |
448 | 415 |
449 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); | 416 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); |
450 m_pNormalWidget->SetLayoutItem(this); | 417 m_pNormalWidget->SetLayoutItem(this); |
451 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); | 418 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); |
452 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); | 419 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); |
453 | 420 |
454 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 421 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFNumericEditDelegate>( |
455 m_pNormalWidget->SetCurrentDelegate(this); | 422 m_pNormalWidget->ReleaseDelegate(), this)); |
456 m_pNormalWidget->LockUpdate(); | 423 m_pNormalWidget->LockUpdate(); |
457 | 424 |
458 CFX_WideString wsText; | 425 CFX_WideString wsText; |
459 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); | 426 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
460 pWidget->SetText(wsText); | 427 pWidget->SetText(wsText); |
461 UpdateWidgetProperty(); | 428 UpdateWidgetProperty(); |
462 m_pNormalWidget->UnlockUpdate(); | 429 m_pNormalWidget->UnlockUpdate(); |
463 return CXFA_FFField::LoadWidget(); | 430 return CXFA_FFField::LoadWidget(); |
464 } | 431 } |
465 void CXFA_FFNumericEdit::UpdateWidgetProperty() { | 432 void CXFA_FFNumericEdit::UpdateWidgetProperty() { |
(...skipping 15 matching lines...) Expand all Loading... |
481 pWidget->SetLimit(iNumCells); | 448 pWidget->SetLimit(iNumCells); |
482 } | 449 } |
483 dwExtendedStyle |= GetAlignment(); | 450 dwExtendedStyle |= GetAlignment(); |
484 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || | 451 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || |
485 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { | 452 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { |
486 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; | 453 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; |
487 } | 454 } |
488 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); | 455 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); |
489 } | 456 } |
490 | 457 |
491 void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) { | |
492 if (pEvent->GetClassID() == CFWL_EventType::Validate) { | |
493 CFWL_EvtEdtValidate* event = (CFWL_EvtEdtValidate*)pEvent; | |
494 CFX_WideString wsChange = event->wsInsert; | |
495 event->bValidate = OnValidate(m_pNormalWidget->GetWidget(), wsChange); | |
496 return; | |
497 } | |
498 CXFA_FFTextEdit::OnProcessEvent(pEvent); | |
499 } | |
500 | |
501 FX_BOOL CXFA_FFNumericEdit::OnValidate(IFWL_Widget* pWidget, | 458 FX_BOOL CXFA_FFNumericEdit::OnValidate(IFWL_Widget* pWidget, |
502 CFX_WideString& wsText) { | 459 CFX_WideString& wsText) { |
503 CFX_WideString wsPattern; | 460 CFX_WideString wsPattern; |
504 m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); | 461 m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); |
505 if (!wsPattern.IsEmpty()) { | 462 if (!wsPattern.IsEmpty()) { |
506 return TRUE; | 463 return TRUE; |
507 } | 464 } |
508 int32_t iLeads = 0; | 465 int32_t iLeads = 0; |
509 m_pDataAcc->GetLeadDigits(iLeads); | 466 m_pDataAcc->GetLeadDigits(iLeads); |
510 int32_t iFracs = 0; | 467 int32_t iFracs = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
524 FX_BOOL CXFA_FFPasswordEdit::LoadWidget() { | 481 FX_BOOL CXFA_FFPasswordEdit::LoadWidget() { |
525 CFWL_Edit* pWidget = new CFWL_Edit(GetFWLApp()); | 482 CFWL_Edit* pWidget = new CFWL_Edit(GetFWLApp()); |
526 pWidget->Initialize(); | 483 pWidget->Initialize(); |
527 m_pNormalWidget = pWidget; | 484 m_pNormalWidget = pWidget; |
528 m_pNormalWidget->SetLayoutItem(this); | 485 m_pNormalWidget->SetLayoutItem(this); |
529 | 486 |
530 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); | 487 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); |
531 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); | 488 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); |
532 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); | 489 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); |
533 | 490 |
534 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 491 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFTextEditDelegate>( |
535 m_pNormalWidget->SetCurrentDelegate(this); | 492 m_pNormalWidget->ReleaseDelegate(), this)); |
536 m_pNormalWidget->LockUpdate(); | 493 m_pNormalWidget->LockUpdate(); |
537 | 494 |
538 CFX_WideString wsText; | 495 CFX_WideString wsText; |
539 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); | 496 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
540 pWidget->SetText(wsText); | 497 pWidget->SetText(wsText); |
541 UpdateWidgetProperty(); | 498 UpdateWidgetProperty(); |
542 m_pNormalWidget->UnlockUpdate(); | 499 m_pNormalWidget->UnlockUpdate(); |
543 return CXFA_FFField::LoadWidget(); | 500 return CXFA_FFField::LoadWidget(); |
544 } | 501 } |
545 void CXFA_FFPasswordEdit::UpdateWidgetProperty() { | 502 void CXFA_FFPasswordEdit::UpdateWidgetProperty() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 } | 550 } |
594 FX_BOOL CXFA_FFDateTimeEdit::LoadWidget() { | 551 FX_BOOL CXFA_FFDateTimeEdit::LoadWidget() { |
595 CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp()); | 552 CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp()); |
596 pWidget->Initialize(); | 553 pWidget->Initialize(); |
597 m_pNormalWidget = pWidget; | 554 m_pNormalWidget = pWidget; |
598 m_pNormalWidget->SetLayoutItem(this); | 555 m_pNormalWidget->SetLayoutItem(this); |
599 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); | 556 IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget(); |
600 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); | 557 CFWL_NoteDriver* pNoteDriver = pIWidget->GetOwnerApp()->GetNoteDriver(); |
601 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); | 558 pNoteDriver->RegisterEventTarget(pIWidget, pIWidget); |
602 | 559 |
603 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 560 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFDateTimeEditDelegate>( |
604 m_pNormalWidget->SetCurrentDelegate(this); | 561 m_pNormalWidget->ReleaseDelegate(), this)); |
605 m_pNormalWidget->LockUpdate(); | 562 m_pNormalWidget->LockUpdate(); |
606 | 563 |
607 CFX_WideString wsText; | 564 CFX_WideString wsText; |
608 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); | 565 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display); |
609 pWidget->SetEditText(wsText); | 566 pWidget->SetEditText(wsText); |
610 if (CXFA_Value value = m_pDataAcc->GetFormValue()) { | 567 if (CXFA_Value value = m_pDataAcc->GetFormValue()) { |
611 switch (value.GetChildValueClassID()) { | 568 switch (value.GetChildValueClassID()) { |
612 case XFA_Element::Date: { | 569 case XFA_Element::Date: { |
613 if (!wsText.IsEmpty()) { | 570 if (!wsText.IsEmpty()) { |
614 CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); | 571 CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget; | 748 CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget; |
792 pDateTime->SetEditText(wsDate); | 749 pDateTime->SetEditText(wsDate); |
793 pDateTime->Update(); | 750 pDateTime->Update(); |
794 GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); | 751 GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr); |
795 CXFA_EventParam eParam; | 752 CXFA_EventParam eParam; |
796 eParam.m_eType = XFA_EVENT_Change; | 753 eParam.m_eType = XFA_EVENT_Change; |
797 eParam.m_pTarget = m_pDataAcc; | 754 eParam.m_pTarget = m_pDataAcc; |
798 m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); | 755 m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw); |
799 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); | 756 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); |
800 } | 757 } |
801 | |
802 void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) { | |
803 if (pEvent->GetClassID() == CFWL_EventType::SelectChanged) { | |
804 CFWL_Event_DtpSelectChanged* event = (CFWL_Event_DtpSelectChanged*)pEvent; | |
805 OnSelectChanged(m_pNormalWidget->GetWidget(), event->iYear, event->iMonth, | |
806 event->iDay); | |
807 return; | |
808 } | |
809 CXFA_FFTextEdit::OnProcessEvent(pEvent); | |
810 } | |
OLD | NEW |