FX_BOOL CPDFSDK_Document::ProcOpenAction() { if (!m_pDoc) return FALSE; CPDF_Dictionary* pRoot = m_pDoc->GetRoot(); if (!pRoot) return FALSE; CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction"); if (!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction"); if (!pOpenAction) return FALSE; if (pOpenAction->IsArray()) return TRUE; if (CPDF_Dictionary* pDict = pOpenAction->AsDictionary()) { CPDF_Action action(pDict); if (m_pEnv->GetActionHander()) m_pEnv->GetActionHander()->DoAction_DocOpen(action, this); return TRUE; } return FALSE; }
bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return false; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return false; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, true); if (!(m_Flags & kFormListMultiSelect)) { m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false); } else { CPDF_Array* pArray = m_pDict->SetNewFor<CPDF_Array>("V"); for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false); } } } } else { m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false); CPDF_Array* pI = m_pDict->SetNewFor<CPDF_Array>("I"); pI->AddNew<CPDF_Number>(index); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, false); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveFor("V"); } else if (pValue->IsArray()) { std::unique_ptr<CPDF_Array> pArray(new CPDF_Array); for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false); } } if (pArray->GetCount() > 0) m_pDict->SetFor("V", std::move(pArray)); } } else { m_pDict->RemoveFor("V"); m_pDict->RemoveFor("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return true; }
FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return FALSE; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return FALSE; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, TRUE); if (!(m_Flags & FORMLIST_MULTISELECT)) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); } else { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } m_pDict->SetAt("V", pArray); } } else { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetAt("I", pI); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveAt("V"); } else if (pValue->IsArray()) { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } if (pArray->GetCount() < 1) pArray->Release(); else m_pDict->SetAt("V", pArray); } } else { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return TRUE; }
FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) return FALSE; CFX_WideString opt_value = GetOptionValue(index); if (bNotify && !NotifyListOrComboBoxBeforeChange(opt_value)) return FALSE; if (bSelected) { if (GetType() == ListBox) { SelectOption(index, TRUE); if (!(m_Flags & kFormListMultiSelect)) { m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); } else { CPDF_Array* pArray = new CPDF_Array; for (int i = 0; i < CountOptions(); i++) { if (i == index || IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } m_pDict->SetFor("V", pArray); } } else { m_pDict->SetStringFor("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetFor("I", pI); } } else { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (GetType() == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveFor("V"); } else if (pValue->IsArray()) { std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( new CPDF_Array); for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } if (pArray->GetCount() > 0) m_pDict->SetFor("V", pArray.release()); // std::move someday } } else { m_pDict->RemoveFor("V"); m_pDict->RemoveFor("I"); } } } if (bNotify) NotifyListOrComboBoxAfterChange(); return TRUE; }
FX_BOOL CPDF_FormField::SetItemSelection(int index, FX_BOOL bSelected, FX_BOOL bNotify) { ASSERT(GetType() == ComboBox || GetType() == ListBox); if (index < 0 || index >= CountOptions()) { return FALSE; } CFX_WideString opt_value = GetOptionValue(index); if (bNotify && m_pForm->m_pFormNotify) { int iRet = 0; if (GetType() == ListBox) { iRet = m_pForm->m_pFormNotify->BeforeSelectionChange(this, opt_value); } if (GetType() == ComboBox) { iRet = m_pForm->m_pFormNotify->BeforeValueChange(this, opt_value); } if (iRet < 0) { return FALSE; } } if (!bSelected) { CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V"); if (pValue) { if (m_Type == ListBox) { SelectOption(index, FALSE); if (pValue->IsString()) { if (pValue->GetUnicodeText() == opt_value) { m_pDict->RemoveAt("V"); } } else if (pValue->IsArray()) { CPDF_Array* pArray = new CPDF_Array; int iCount = CountOptions(); for (int i = 0; i < iCount; i++) { if (i != index) { if (IsItemSelected(i)) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } } if (pArray->GetCount() < 1) { pArray->Release(); } else { m_pDict->SetAt("V", pArray); } } } else if (m_Type == ComboBox) { m_pDict->RemoveAt("V"); m_pDict->RemoveAt("I"); } } } else { if (m_Type == ListBox) { SelectOption(index, TRUE); if (!(m_Flags & FORMLIST_MULTISELECT)) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); } else { CPDF_Array* pArray = new CPDF_Array; int iCount = CountOptions(); for (int i = 0; i < iCount; i++) { FX_BOOL bSelected; if (i != index) { bSelected = IsItemSelected(i); } else { bSelected = TRUE; } if (bSelected) { opt_value = GetOptionValue(i); pArray->AddString(PDF_EncodeText(opt_value)); } } m_pDict->SetAt("V", pArray); } } else if (m_Type == ComboBox) { m_pDict->SetAtString("V", PDF_EncodeText(opt_value)); CPDF_Array* pI = new CPDF_Array; pI->AddInteger(index); m_pDict->SetAt("I", pI); } } if (bNotify && m_pForm->m_pFormNotify) { if (GetType() == ListBox) { m_pForm->m_pFormNotify->AfterSelectionChange(this); } if (GetType() == ComboBox) { m_pForm->m_pFormNotify->AfterValueChange(this); } } if (CPDF_InterForm::m_bUpdateAP) { UpdateAP(NULL); } m_pForm->m_bUpdated = TRUE; return TRUE; }