FX_BOOL CPDF_FormField::SetCheckValue(const CFX_WideString& value, FX_BOOL bDefault, FX_BOOL bNotify) { ASSERT(GetType() == CheckBox || GetType() == RadioButton); CFX_ByteArray statusArray; if (bNotify && m_pForm->m_pFormNotify != NULL) { SaveCheckedFieldStatus(this, statusArray); } int iCount = CountControls(); for (int i = 0; i < iCount; i ++) { CPDF_FormControl* pControl = GetControl(i); CFX_WideString csExport = pControl->GetExportValue(); if (csExport == value) { if (bDefault) { } else { CheckControl(GetControlIndex(pControl), TRUE); } break; } else { if (bDefault) { } else { CheckControl(GetControlIndex(pControl), FALSE); } } } if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); } m_pForm->m_bUpdated = TRUE; return TRUE; }
void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, const CFX_WideString& parent_name, FX_BOOL bNotify, int nLevel) { CFX_WideString name; if (!parent_name.IsEmpty()) { name = parent_name + L"."; } name += pFieldDict->GetUnicodeText("T"); CPDF_Array* pKids = pFieldDict->GetArray("Kids"); if (pKids) { for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { CPDF_Dictionary* pKid = pKids->GetDict(i); if (pKid == NULL) { continue; } if (nLevel <= nMaxRecursion) { FDF_ImportField(pKid, name, bNotify, nLevel + 1); } } return; } if (!pFieldDict->KeyExist("V")) { return; } CPDF_FormField* pField = m_pFieldTree->GetField(name); if (pField == NULL) { return; } CFX_WideString csWValue; FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); int iType = pField->GetFieldType(); if (bNotify && m_pFormNotify != NULL) { int iRet = 0; if (iType == FIELDTYPE_LISTBOX) { iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); } if (iRet < 0) { return; } } CFX_ByteArray statusArray; if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { SaveCheckedFieldStatus(pField, statusArray); } pField->SetValue(csWValue); CPDF_FormField::Type eType = pField->GetType(); if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && pFieldDict->KeyExist("Opt")) { pField->m_pDict->SetAt("Opt", pFieldDict->GetElementValue("Opt")->Clone(TRUE)); } if (bNotify && m_pFormNotify != NULL) { if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { m_pFormNotify->AfterCheckedStatusChange(pField, statusArray); } else if (iType == FIELDTYPE_LISTBOX) { m_pFormNotify->AfterSelectionChange(pField); } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { m_pFormNotify->AfterValueChange(pField); } } if (CPDF_InterForm::m_bUpdateAP) { pField->UpdateAP(NULL); } }
FX_BOOL CPDF_FormField::CheckControl(int iControlIndex, FX_BOOL bChecked, FX_BOOL bNotify) { ASSERT(GetType() == CheckBox || GetType() == RadioButton); CPDF_FormControl* pControl = GetControl(iControlIndex); if (pControl == NULL) { return FALSE; } if (!bChecked && pControl->IsChecked() == bChecked) { return FALSE; } CFX_ByteArray statusArray; if (bNotify && m_pForm->m_pFormNotify != NULL) { SaveCheckedFieldStatus(this, statusArray); } CFX_WideString csWExport = pControl->GetExportValue(); CFX_ByteString csBExport = PDF_EncodeText(csWExport); int iCount = CountControls(); FX_BOOL bUnison = PDF_FormField_IsUnison(this); for (int i = 0; i < iCount; i ++) { CPDF_FormControl* pCtrl = GetControl(i); if (bUnison) { CFX_WideString csEValue = pCtrl->GetExportValue(); if (csEValue == csWExport) { if (pCtrl->GetOnStateName() == pControl->GetOnStateName()) { pCtrl->CheckControl(bChecked); } else if (bChecked) { pCtrl->CheckControl(FALSE); } } else if (bChecked) { pCtrl->CheckControl(FALSE); } } else { if (i == iControlIndex) { pCtrl->CheckControl(bChecked); } else if (bChecked) { pCtrl->CheckControl(FALSE); } } } CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt"); if (pOpt == NULL || pOpt->GetType() != PDFOBJ_ARRAY) { if (bChecked) { m_pDict->SetAtName("V", csBExport); } else { CFX_ByteString csV; CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); if (pV != NULL) { csV = pV->GetString(); } if (csV == csBExport) { m_pDict->SetAtName("V", "Off"); } } } else if (bChecked) { CFX_ByteString csIndex; csIndex.Format("%d", iControlIndex); m_pDict->SetAtName("V", csIndex); } if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); } m_pForm->m_bUpdated = TRUE; return TRUE; }
FX_BOOL CPDF_FormField::ResetField(FX_BOOL bNotify) { switch (m_Type) { case CPDF_FormField::CheckBox: case CPDF_FormField::RadioButton: { CFX_ByteArray statusArray; if (bNotify && m_pForm->m_pFormNotify != NULL) { SaveCheckedFieldStatus(this, statusArray); } int iCount = CountControls(); if (iCount) { if (PDF_FormField_IsUnison(this)) { for(int i = 0; i < iCount; i++) { CheckControl(i, GetControl(i)->IsDefaultChecked(), FALSE); } } else { for (int i = 0; i < iCount; i ++) { CPDF_FormControl* pControl = GetControl(i); FX_BOOL bChecked = pControl->IsDefaultChecked(); CheckControl(i, bChecked, FALSE); } } } if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterCheckedStatusChange(this, statusArray); } } break; case CPDF_FormField::ComboBox: { CFX_WideString csValue; ClearSelection(); int iIndex = GetDefaultSelectedItem(); if (iIndex >= 0) { csValue = GetOptionLabel(iIndex); } if (bNotify && m_pForm->m_pFormNotify != NULL) { int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csValue); if (iRet < 0) { return FALSE; } } SetItemSelection(iIndex, TRUE); if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterValueChange(this); } } break; case CPDF_FormField::ListBox: { CFX_WideString csValue; ClearSelection(); int iIndex = GetDefaultSelectedItem(); if (iIndex >= 0) { csValue = GetOptionLabel(iIndex); } if (bNotify && m_pForm->m_pFormNotify != NULL) { int iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, csValue); if (iRet < 0) { return FALSE; } } SetItemSelection(iIndex, TRUE); if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterSelectionChange(this); } } break; case CPDF_FormField::Text: case CPDF_FormField::RichText: case CPDF_FormField::File: default: { CPDF_Object* pDV = FPDF_GetFieldAttr(m_pDict, "DV"); CFX_WideString csDValue; if (pDV != NULL) { csDValue = pDV->GetUnicodeText(); } CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V"); CFX_WideString csValue; if (pV != NULL) { csValue = pV->GetUnicodeText(); } CPDF_Object* pRV = FPDF_GetFieldAttr(m_pDict, "RV"); if (!pRV && (csDValue == csValue)) { return FALSE; } if (bNotify && m_pForm->m_pFormNotify != NULL) { int iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, csDValue); if (iRet < 0) { return FALSE; } } if (pDV == NULL) { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("RV"); } else { CPDF_Object* pClone = pDV->Clone(); if (pClone == NULL) { return FALSE; } m_pDict->SetAt("V", pClone); if(pRV) { CPDF_Object* pCloneR = pDV->Clone(); m_pDict->SetAt("RV", pCloneR); } } if (bNotify && m_pForm->m_pFormNotify != NULL) { m_pForm->m_pFormNotify->AfterValueChange(this); } m_pForm->m_bUpdated = TRUE; } break; } return TRUE; }