1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../include/fpdfdoc/fpdf_doc.h"
8 CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict);
9 void SaveCheckedFieldStatus(CPDF_FormField* pField, CFX_ByteArray& statusArray);
10 FX_BOOL PDF_FormField_IsUnison(CPDF_FormField *pField)
12 FX_BOOL bUnison = FALSE;
13 if (pField->GetType() == CPDF_FormField::CheckBox) {
16 FX_DWORD dwFlags = pField->GetFieldFlags();
17 bUnison = ((dwFlags & 0x2000000) != 0);
21 CPDF_FormField::CPDF_FormField(CPDF_InterForm* pForm, CPDF_Dictionary* pDict)
30 CPDF_FormField::~CPDF_FormField()
33 void CPDF_FormField::SyncFieldFlags()
35 CFX_ByteString type_name = FPDF_GetFieldAttr(m_pDict, "FT") ? FPDF_GetFieldAttr(m_pDict, "FT")->GetString() : CFX_ByteString();
36 FX_DWORD flags = FPDF_GetFieldAttr(m_pDict, "Ff")? FPDF_GetFieldAttr(m_pDict, "Ff")->GetInteger() : 0;
39 m_Flags |= FORMFIELD_READONLY;
42 m_Flags |= FORMFIELD_REQUIRED;
45 m_Flags |= FORMFIELD_NOEXPORT;
47 if (type_name == "Btn") {
51 m_Flags |= FORMRADIO_NOTOGGLEOFF;
53 if (flags & 0x2000000) {
54 m_Flags |= FORMRADIO_UNISON;
56 } else if (flags & 0x10000) {
61 } else if (type_name == "Tx") {
62 if (flags & 0x100000) {
64 } else if (flags & 0x2000000) {
69 m_Flags |= FORMTEXT_MULTILINE;
72 m_Flags |= FORMTEXT_PASSWORD;
74 if (flags & 0x800000) {
75 m_Flags |= FORMTEXT_NOSCROLL;
77 if (flags & 0x100000) {
78 m_Flags |= FORMTEXT_COMB;
82 } else if (type_name == "Ch") {
83 if (flags & 0x20000) {
85 if (flags & 0x40000) {
86 m_Flags |= FORMCOMBO_EDIT;
90 if (flags & 0x200000) {
91 m_Flags |= FORMLIST_MULTISELECT;
95 } else if (type_name == "Sig") {
99 CFX_WideString CPDF_FormField::GetFullName()
101 return ::GetFullName(m_pDict);
103 FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify)
106 case CPDF_FormField::CheckBox:
107 case CPDF_FormField::RadioButton: {
108 CFX_ByteArray statusArray;
109 if (bNotify && m_pForm->m_pFormNotify != NULL) {
110 SaveCheckedFieldStatus(this, statusArray);
112 int iCount = CountControls();
114 if (PDF_FormField_IsUnison(this)) {
115 for(int i = 0; i < iCount; i++) {
116 CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE);
119 for (int i = 0; i < iCount; i ++) {
120 CPDF_FormControl* pControl = GetControl(i);
121 FX_BOOL bChecked = pControl->IsDefaultChecked();
122 CheckControl(i, bChecked, FALSE);
126 if (bNotify && m_pForm->m_pFormNotify != NULL) {
127 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
131 case CPDF_FormField::ComboBox: {
132 CFX_WideString csValue;
134 int iIndex = GetDefaultSelectedItem();
136 csValue = GetOptionLabel(iIndex);
138 if (bNotify && m_pForm->m_pFormNotify != NULL) {
139 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
144 SetItemSelection(iIndex, TRUE);
145 if (bNotify && m_pForm->m_pFormNotify != NULL) {
146 m_pForm->m_pFormNotify->AfterValueChange(this);
150 case CPDF_FormField::ListBox: {
151 CFX_WideString csValue;
153 int iIndex = GetDefaultSelectedItem();
155 csValue = GetOptionLabel(iIndex);
157 if (bNotify && m_pForm->m_pFormNotify != NULL) {
158 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
163 SetItemSelection(iIndex, TRUE);
164 if (bNotify && m_pForm->m_pFormNotify != NULL) {
165 m_pForm->m_pFormNotify->AfterSelectionChange(this);
169 case CPDF_FormField::Text:
170 case CPDF_FormField::RichText:
171 case CPDF_FormField::File:
173 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV");
174 CFX_WideString csDValue;
176 csDValue = pDV->GetUnicodeText();
178 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
179 CFX_WideString csValue;
181 csValue = pV->GetUnicodeText();
183 CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV");
184 if (!pRV && (csDValue == csValue)) {
187 if (bNotify && m_pForm->m_pFormNotify != NULL) {
188 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue);
194 m_pDict->RemoveAt("V");
195 m_pDict->RemoveAt("RV");
197 CPDF_Object* pClone = pDV->Clone();
198 if (pClone == NULL) {
201 m_pDict->SetAt("V", pClone);
203 CPDF_Object* pCloneR = pDV->Clone();
204 m_pDict->SetAt("RV", pCloneR);
207 if (bNotify && m_pForm->m_pFormNotify != NULL) {
208 m_pForm->m_pFormNotify->AfterValueChange(this);
210 m_pForm->m_bUpdated = TRUE;
216 int CPDF_FormField::GetControlIndex(const CPDF_FormControl* pControl)
218 if (pControl == NULL) {
221 int iCount = m_ControlList.GetSize();
222 for (int i = 0; i < iCount; i ++) {
223 CPDF_FormControl* pFind = (CPDF_FormControl*)m_ControlList.GetAt(i);
224 if (pFind == pControl) {
230 int CPDF_FormField::GetFieldType()
234 return FIELDTYPE_PUSHBUTTON;
236 return FIELDTYPE_CHECKBOX;
238 return FIELDTYPE_RADIOBUTTON;
240 return FIELDTYPE_COMBOBOX;
242 return FIELDTYPE_LISTBOX;
246 return FIELDTYPE_TEXTFIELD;
248 return FIELDTYPE_SIGNATURE;
252 return FIELDTYPE_UNKNOWN;
254 CPDF_AAction CPDF_FormField::GetAdditionalAction()
256 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "AA");
260 return pObj->GetDict();
262 CFX_WideString CPDF_FormField::GetAlternateName()
264 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TU");
268 return pObj->GetUnicodeText();
270 CFX_WideString CPDF_FormField::GetMappingName()
272 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TM");
276 return pObj->GetUnicodeText();
278 FX_DWORD CPDF_FormField::GetFieldFlags()
280 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff");
284 return pObj->GetInteger();
286 CFX_ByteString CPDF_FormField::GetDefaultStyle()
288 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DS");
292 return pObj->GetString();
294 CFX_WideString CPDF_FormField::GetRichTextString()
296 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "RV");
300 return pObj->GetUnicodeText();
302 CFX_WideString CPDF_FormField::GetValue(FX_BOOL bDefault)
304 if (GetType() == CheckBox || GetType() == RadioButton) {
305 return GetCheckValue(bDefault);
307 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, bDefault ? "DV" : "V");
308 if (pValue == NULL) {
310 if (m_Type == RichText) {
311 pValue = FPDF_GetFieldAttr(m_pDict, "V");
313 if (pValue == NULL && m_Type != Text) {
314 pValue = FPDF_GetFieldAttr(m_pDict, "DV");
317 if (pValue == NULL) {
318 return CFX_WideString();
321 switch (pValue->GetType()) {
324 return pValue->GetUnicodeText();
326 pValue = ((CPDF_Array*)pValue)->GetElementValue(0);
328 return pValue->GetUnicodeText();
332 return CFX_WideString();
334 CFX_WideString CPDF_FormField::GetValue()
336 return GetValue(FALSE);
338 CFX_WideString CPDF_FormField::GetDefaultValue()
340 return GetValue(TRUE);
342 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify)
347 SetCheckValue(value, bDefault, bNotify);
354 CFX_WideString csValue = value;
355 if (bNotify && m_pForm->m_pFormNotify != NULL) {
356 int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
361 int iIndex = FindOptionValue(csValue);
363 CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
364 m_pDict->SetAtString(bDefault ? "DV" : "V", bsEncodeText);
365 if (m_Type == RichText && !bDefault) {
366 m_pDict->SetAtString("RV", bsEncodeText);
368 m_pDict->RemoveAt("I");
370 m_pDict->SetAtString(bDefault ? "DV" : "V", PDF_EncodeText(csValue));
374 SetItemSelection(iIndex, TRUE);
377 if (bNotify && m_pForm->m_pFormNotify != NULL) {
378 m_pForm->m_pFormNotify->AfterValueChange(this);
380 m_pForm->m_bUpdated = TRUE;
384 int iIndex = FindOptionValue(value);
388 if (bDefault && iIndex == GetDefaultSelectedItem()) {
391 if (bNotify && m_pForm->m_pFormNotify != NULL) {
392 CFX_WideString csValue = value;
393 int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
401 SetItemSelection(iIndex, TRUE);
403 if (bNotify && m_pForm->m_pFormNotify != NULL) {
404 m_pForm->m_pFormNotify->AfterSelectionChange(this);
406 m_pForm->m_bUpdated = TRUE;
412 if (CPDF_InterForm::m_bUpdateAP) {
417 FX_BOOL CPDF_FormField::SetValue(const CFX_WideString& value, FX_BOOL bNotify)
419 return SetValue(value, FALSE, bNotify);
421 int CPDF_FormField::GetMaxLen()
423 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen");
425 int iCount = m_ControlList.GetSize();
426 for (int i = 0; i < iCount; i ++) {
427 CPDF_FormControl* pControl = (CPDF_FormControl*)m_ControlList.GetAt(i);
428 if (pControl == NULL) {
431 CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
432 if (pWidgetDict->KeyExist("MaxLen")) {
433 return pWidgetDict->GetInteger("MaxLen");
438 return pObj->GetInteger();
440 int CPDF_FormField::CountSelectedItems()
442 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
443 if (pValue == NULL) {
444 pValue = FPDF_GetFieldAttr(m_pDict, "I");
445 if (pValue == NULL) {
449 if (pValue->GetType() == PDFOBJ_STRING) {
450 if (pValue->GetString().IsEmpty()) {
455 if (pValue->GetType() == PDFOBJ_NUMBER) {
456 if (pValue->GetString().IsEmpty()) {
461 if (pValue->GetType() != PDFOBJ_ARRAY) {
464 return ((CPDF_Array*)pValue)->GetCount();
466 int CPDF_FormField::GetSelectedIndex(int index)
468 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
469 if (pValue == NULL) {
470 pValue = FPDF_GetFieldAttr(m_pDict, "I");
471 if (pValue == NULL) {
475 CFX_WideString sel_value;
476 if (pValue->GetType() == PDFOBJ_STRING) {
480 sel_value = pValue->GetUnicodeText();
481 } else if (pValue->GetType() == PDFOBJ_NUMBER) {
482 return pValue->GetInteger();
484 if (pValue->GetType() != PDFOBJ_ARRAY) {
490 CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
491 sel_value = elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
493 if (index < CountSelectedOptions()) {
494 int iOptIndex = GetSelectedOptionIndex(index);
495 CFX_WideString csOpt = GetOptionValue(iOptIndex);
496 if (csOpt == sel_value) {
500 int nOpts = CountOptions();
501 for (int i = 0; i < nOpts; i ++) {
502 if (sel_value == GetOptionValue(i)) {
508 FX_BOOL CPDF_FormField::ClearSelection(FX_BOOL bNotify)
510 if (bNotify && m_pForm->m_pFormNotify != NULL) {
512 CFX_WideString csValue;
513 int iIndex = GetSelectedIndex(0);
515 csValue = GetOptionLabel(iIndex);
517 if (GetType() == ListBox) {
518 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
520 if (GetType() == ComboBox) {
521 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
527 m_pDict->RemoveAt("V");
528 m_pDict->RemoveAt("I");
529 if (bNotify && m_pForm->m_pFormNotify != NULL) {
530 if (GetType() == ListBox) {
531 m_pForm->m_pFormNotify->AfterSelectionChange(this);
533 if (GetType() == ComboBox) {
534 m_pForm->m_pFormNotify->AfterValueChange(this);
537 if (CPDF_InterForm::m_bUpdateAP) {
540 m_pForm->m_bUpdated = TRUE;
543 FX_BOOL CPDF_FormField::IsItemSelected(int index)
545 ASSERT(GetType() == ComboBox || GetType() == ListBox);
546 if (index < 0 || index >= CountOptions()) {
549 if (IsOptionSelected(index)) {
552 CFX_WideString opt_value = GetOptionValue(index);
553 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
554 if (pValue == NULL) {
555 pValue = FPDF_GetFieldAttr(m_pDict, "I");
556 if (pValue == NULL) {
560 if (pValue->GetType() == PDFOBJ_STRING) {
561 if (pValue->GetUnicodeText() == opt_value) {
566 if (pValue->GetType() == PDFOBJ_NUMBER) {
567 if (pValue->GetString().IsEmpty()) {
570 if (pValue->GetInteger() == index) {
575 if (pValue->GetType() != PDFOBJ_ARRAY) {
578 CPDF_Array* pArray = (CPDF_Array*)pValue;
580 for (int j = 0; j < CountSelectedOptions(); j ++) {
581 if (GetSelectedOptionIndex(j) == index) {
586 for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
587 if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) {
592 FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify)
594 ASSERT(GetType() == ComboBox || GetType() == ListBox);
595 if (index < 0 || index >= CountOptions()) {
598 CFX_WideString opt_value = GetOptionValue(index);
599 if (bNotify && m_pForm->m_pFormNotify != NULL) {
601 if (GetType() == ListBox) {
602 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value);
604 if (GetType() == ComboBox) {
605 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value);
612 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
613 if (pValue != NULL) {
614 if (m_Type == ListBox) {
615 SelectOption(index, FALSE);
616 if (pValue->GetType() == PDFOBJ_STRING) {
617 if (pValue->GetUnicodeText() == opt_value) {
618 m_pDict->RemoveAt("V");
620 } else if (pValue->GetType() == PDFOBJ_ARRAY) {
621 CPDF_Array* pArray = CPDF_Array::Create();
622 if (pArray == NULL) {
625 int iCount = CountOptions();
626 for (int i = 0; i < iCount; i ++) {
628 if (IsItemSelected(i)) {
629 opt_value = GetOptionValue(i);
630 pArray->AddString(PDF_EncodeText(opt_value));
634 if (pArray->GetCount() < 1) {
637 m_pDict->SetAt("V", pArray);
640 } else if (m_Type == ComboBox) {
641 m_pDict->RemoveAt("V");
642 m_pDict->RemoveAt("I");
646 if (m_Type == ListBox) {
647 SelectOption(index, TRUE);
648 if (!(m_Flags & FORMLIST_MULTISELECT)) {
649 m_pDict->SetAtString("V", PDF_EncodeText(opt_value, opt_value.GetLength()));
651 CPDF_Array* pArray = CPDF_Array::Create();
652 if (pArray == NULL) {
656 int iCount = CountOptions();
657 for (int i = 0; i < iCount; i ++) {
659 bSelected = IsItemSelected(i);
664 opt_value = GetOptionValue(i);
665 pArray->AddString(PDF_EncodeText(opt_value));
668 m_pDict->SetAt("V", pArray);
670 } else if (m_Type == ComboBox) {
671 m_pDict->SetAtString("V", PDF_EncodeText(opt_value, opt_value.GetLength()));
672 CPDF_Array* pI = CPDF_Array::Create();
676 pI->AddInteger(index);
677 m_pDict->SetAt("I", pI);
680 if (bNotify && m_pForm->m_pFormNotify != NULL) {
681 if (GetType() == ListBox) {
682 m_pForm->m_pFormNotify->AfterSelectionChange(this);
684 if (GetType() == ComboBox) {
685 m_pForm->m_pFormNotify->AfterValueChange(this);
688 if (CPDF_InterForm::m_bUpdateAP) {
691 m_pForm->m_bUpdated = TRUE;
694 FX_BOOL CPDF_FormField::IsItemDefaultSelected(int index)
696 ASSERT(GetType() == ComboBox || GetType() == ListBox);
697 if (index < 0 || index >= CountOptions()) {
700 int iDVIndex = GetDefaultSelectedItem();
704 return (iDVIndex == index);
706 int CPDF_FormField::GetDefaultSelectedItem()
708 ASSERT(GetType() == ComboBox || GetType() == ListBox);
709 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "DV");
710 if (pValue == NULL) {
713 CFX_WideString csDV = pValue->GetUnicodeText();
714 if (csDV.IsEmpty()) {
717 int iCount = CountOptions();
718 for (int i = 0; i < iCount; i ++) {
719 if (csDV == GetOptionValue(i)) {
725 void CPDF_FormField::UpdateAP(CPDF_FormControl* pControl)
727 if (m_Type == PushButton) {
730 if (m_Type == RadioButton || m_Type == CheckBox) {
733 if (!m_pForm->m_bGenerateAP) {
736 for (int i = 0; i < CountControls(); i ++) {
737 CPDF_FormControl* pControl = GetControl(i);
738 FPDF_GenerateAP(m_pForm->m_pDocument, pControl->m_pWidgetDict);
741 int CPDF_FormField::CountOptions()
743 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
744 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
747 return ((CPDF_Array*)pValue)->GetCount();
749 CFX_WideString CPDF_FormField::GetOptionText(int index, int sub_index)
751 CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
752 if (pValue == NULL || pValue->GetType() != PDFOBJ_ARRAY) {
753 return CFX_WideString();
755 CPDF_Object* pOption = ((CPDF_Array*)pValue)->GetElementValue(index);
756 if (pOption == NULL) {
757 return CFX_WideString();
759 if (pOption->GetType() == PDFOBJ_ARRAY) {
760 pOption = ((CPDF_Array*)pOption)->GetElementValue(sub_index);
762 if (pOption == NULL || pOption->GetType() != PDFOBJ_STRING) {
763 return CFX_WideString();
765 return ((CPDF_String*)pOption)->GetUnicodeText();
767 CFX_WideString CPDF_FormField::GetOptionLabel(int index)
769 return GetOptionText(index, 1);
771 CFX_WideString CPDF_FormField::GetOptionValue(int index)
773 return GetOptionText(index, 0);
775 int CPDF_FormField::FindOption(CFX_WideString csOptLabel)
777 int iCount = CountOptions();
778 for (int i = 0; i < iCount; i ++) {
779 CFX_WideString csValue = GetOptionValue(i);
780 if (csValue == csOptLabel) {
786 int CPDF_FormField::FindOptionValue(FX_LPCWSTR csOptValue, int iStartIndex)
788 if (iStartIndex < 0) {
791 int iCount = CountOptions();
792 for (; iStartIndex < iCount; iStartIndex ++) {
793 CFX_WideString csValue = GetOptionValue(iStartIndex);
794 if (csValue == csOptValue) {
800 FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, FX_BOOL bChecked, FX_BOOL bNotify)
802 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
803 CPDF_FormControl* pControl = GetControl(iControlIndex);
804 if (pControl == NULL) {
807 if (!bChecked && pControl->IsChecked() == bChecked) {
810 CFX_ByteArray statusArray;
811 if (bNotify && m_pForm->m_pFormNotify != NULL) {
812 SaveCheckedFieldStatus(this, statusArray);
814 CFX_WideString csWExport = pControl->GetExportValue();
815 CFX_ByteString csBExport = PDF_EncodeText(csWExport);
816 int iCount = CountControls();
817 FX_BOOL bUnison = PDF_FormField_IsUnison(this);
818 for (int i = 0; i < iCount; i ++) {
819 CPDF_FormControl* pCtrl = GetControl(i);
821 CFX_WideString csEValue = pCtrl->GetExportValue();
822 if (csEValue == csWExport) {
823 if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) {
824 pCtrl->CheckControl(bChecked);
825 } else if (bChecked) {
826 pCtrl->CheckControl(FALSE);
828 } else if (bChecked) {
829 pCtrl->CheckControl(FALSE);
832 if (i == iControlIndex) {
833 pCtrl->CheckControl(bChecked);
834 } else if (bChecked) {
835 pCtrl->CheckControl(FALSE);
839 CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
840 if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) {
842 m_pDict->SetAtName("V", csBExport);
845 CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
847 csV = pV->GetString();
849 if (csV == csBExport) {
850 m_pDict->SetAtName("V", "Off");
853 } else if (bChecked) {
854 CFX_ByteString csIndex;
855 csIndex.Format("%d", iControlIndex);
856 m_pDict->SetAtName("V", csIndex);
858 if (bNotify && m_pForm->m_pFormNotify != NULL) {
859 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
861 m_pForm->m_bUpdated = TRUE;
864 CFX_WideString CPDF_FormField::GetCheckValue(FX_BOOL bDefault)
866 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
867 CFX_WideString csExport = L"Off";
869 int iCount = CountControls();
870 for (int i = 0; i < iCount; i ++) {
871 CPDF_FormControl* pControl = GetControl(i);
873 bChecked = pControl->IsDefaultChecked();
875 bChecked = pControl->IsChecked();
878 csExport = pControl->GetExportValue();
884 FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify)
886 ASSERT(GetType() == CheckBox || GetType() == RadioButton);
887 CFX_ByteArray statusArray;
888 if (bNotify && m_pForm->m_pFormNotify != NULL) {
889 SaveCheckedFieldStatus(this, statusArray);
891 int iCount = CountControls();
892 for (int i = 0; i < iCount; i ++) {
893 CPDF_FormControl* pControl = GetControl(i);
894 CFX_WideString csExport = pControl->GetExportValue();
895 if (csExport == value) {
898 CheckControl(GetControlIndex(pControl), TRUE);
904 CheckControl(GetControlIndex(pControl), FALSE);
908 if (bNotify && m_pForm->m_pFormNotify != NULL) {
909 m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray);
911 m_pForm->m_bUpdated = TRUE;
914 int CPDF_FormField::GetTopVisibleIndex()
916 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
920 return pObj->GetInteger();
922 int CPDF_FormField::CountSelectedOptions()
924 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
928 CPDF_Array* pArray = pObj->GetArray();
929 if (pArray == NULL) {
932 return (int)pArray->GetCount();
934 int CPDF_FormField::GetSelectedOptionIndex(int index)
936 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
940 CPDF_Array* pArray = pObj->GetArray();
941 if (pArray == NULL) {
944 int iCount = (int)pArray->GetCount();
945 if (iCount > 0 && index < iCount) {
946 return pArray->GetInteger(index);
950 FX_BOOL CPDF_FormField::IsOptionSelected(int iOptIndex)
952 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "I");
956 CPDF_Array* pArray = pObj->GetArray();
957 if (pArray == NULL) {
960 int iCount = (int)pArray->GetCount();
961 for (int i = 0; i < iCount; i ++) {
962 if (pArray->GetInteger(i) == iOptIndex) {
968 FX_BOOL CPDF_FormField::SelectOption(int iOptIndex, FX_BOOL bSelected, FX_BOOL bNotify)
970 CPDF_Array* pArray = m_pDict->GetArray("I");
971 if (pArray == NULL) {
975 pArray = CPDF_Array::Create();
976 if (pArray == NULL) {
979 m_pDict->SetAt("I", pArray);
981 FX_BOOL bReturn = FALSE;
982 for (int i = 0; i < (int)pArray->GetCount(); i ++) {
983 int iFind = pArray->GetInteger(i);
984 if (iFind == iOptIndex) {
988 if (bNotify && m_pForm->m_pFormNotify != NULL) {
990 CFX_WideString csValue = GetOptionLabel(iOptIndex);
991 if (GetType() == ListBox) {
992 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
994 if (GetType() == ComboBox) {
995 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1001 pArray->RemoveAt(i);
1004 } else if (iFind > iOptIndex) {
1008 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1010 CFX_WideString csValue = GetOptionLabel(iOptIndex);
1011 if (GetType() == ListBox) {
1012 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1014 if (GetType() == ComboBox) {
1015 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1021 CPDF_Number* pNum = CPDF_Number::Create(iOptIndex);
1025 pArray->InsertAt(i, pNum);
1032 pArray->AddInteger(iOptIndex);
1034 if (pArray->GetCount() == 0) {
1035 m_pDict->RemoveAt("I");
1038 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1039 if (GetType() == ListBox) {
1040 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1042 if (GetType() == ComboBox) {
1043 m_pForm->m_pFormNotify->AfterValueChange(this);
1046 m_pForm->m_bUpdated = TRUE;
1049 FX_BOOL CPDF_FormField::ClearSelectedOptions(FX_BOOL bNotify)
1051 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1053 CFX_WideString csValue;
1054 int iIndex = GetSelectedIndex(0);
1056 csValue = GetOptionLabel(iIndex);
1058 if (GetType() == ListBox) {
1059 iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue);
1061 if (GetType() == ComboBox) {
1062 iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue);
1068 m_pDict->RemoveAt("I");
1069 if (bNotify && m_pForm->m_pFormNotify != NULL) {
1070 if (GetType() == ListBox) {
1071 m_pForm->m_pFormNotify->AfterSelectionChange(this);
1073 if (GetType() == ComboBox) {
1074 m_pForm->m_pFormNotify->AfterValueChange(this);
1077 m_pForm->m_bUpdated = TRUE;
1080 void CPDF_FormField::LoadDA()
1083 if (CPDF_Object* pObj_t = FPDF_GetFieldAttr(m_pDict, "DA")) {
1084 DA = pObj_t->GetString();
1086 if (DA.IsEmpty() && m_pForm->m_pFormDict) {
1087 DA = m_pForm->m_pFormDict->GetString("DA");
1092 CPDF_SimpleParser syntax(DA);
1093 syntax.FindTagParam("Tf", 2);
1094 CFX_ByteString font_name = syntax.GetWord();
1095 CPDF_Dictionary* pFontDict = NULL;
1096 if (m_pForm->m_pFormDict && m_pForm->m_pFormDict->GetDict("DR") &&
1097 m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font") )
1098 pFontDict = m_pForm->m_pFormDict->GetDict("DR")->GetDict("Font")->GetDict(font_name);
1100 if (pFontDict == NULL) {
1103 m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
1104 m_FontSize = FX_atof(syntax.GetWord());