/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/// count field types with a ResId, if SwFieldIds::Unknown count all
size_t SwEditShell::GetFieldTypeCount(SwFieldIds nResId ) const
{ const SwFieldTypes* pFieldTypes = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
// all types with the same ResId
size_t nIdx = 0; for(constauto & pFieldType : *pFieldTypes)
{ // same ResId -> increment index if(pFieldType->Which() == nResId)
nIdx++;
} return nIdx;
}
/// get field types with a ResId, if 0 get all
SwFieldType* SwEditShell::GetFieldType(size_t nField, SwFieldIds nResId ) const
{ const SwFieldTypes* pFieldTypes = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
/// get first type with given ResId and name
SwFieldType* SwEditShell::GetFieldType(SwFieldIds nResId, const OUString& rName) const
{ return GetDoc()->getIDocumentFieldsAccess().GetFieldType( nResId, rName, false );
}
/// delete field type void SwEditShell::RemoveFieldType(size_t nField)
{
GetDoc()->getIDocumentFieldsAccess().RemoveFieldType(nField);
}
/// delete field type based on its name void SwEditShell::RemoveFieldType(SwFieldIds nResId, const OUString& rStr)
{ const SwFieldTypes* pFieldTypes = GetDoc()->getIDocumentFieldsAccess().GetFieldTypes(); const SwFieldTypes::size_type nSize = pFieldTypes->size(); const CharClass& rCC = GetAppCharClass();
OUString aTmp( rCC.lowercase( rStr ));
for(SwFieldTypes::size_type i = 0; i < nSize; ++i)
{ // same ResId -> increment index
SwFieldType* pFieldType = (*pFieldTypes)[i].get(); if( pFieldType->Which() == nResId )
{ if( aTmp == rCC.lowercase( pFieldType->GetName().toString() ) )
{
GetDoc()->getIDocumentFieldsAccess().RemoveFieldType(i); return;
}
}
}
}
/// add a field at the cursor position bool SwEditShell::InsertField(SwField const & rField, constbool bForceExpandHints)
{
CurrShell aCurr( this );
StartAllAction();
SwFormatField aField( rField );
/// Are the PaMs positioned on fields? static SwTextField* lcl_FindInputField( const SwDoc* pDoc, const SwField& rField )
{ // Search field via its address. For input fields this needs to be done in protected fields.
SwTextField* pTField = nullptr; if (SwFieldIds::Input == rField.Which()
|| (SwFieldIds::SetExp == rField.Which()
&& static_cast<const SwSetExpField&>(rField).GetInputFlag()
&& (static_cast<SwSetExpFieldType*>(rField.GetTyp())->GetType()
& nsSwGetSetExpType::GSE_STRING)))
{
pDoc->ForEachFormatField(RES_TXTATR_INPUTFIELD,
[&rField, &pTField] (const SwFormatField& rFormatField) -> bool
{ if( rFormatField.GetField() == &rField )
{
pTField = const_cast<SwFormatField&>(rFormatField).GetTextField(); returnfalse;
} returntrue;
});
} elseif( SwFieldIds::SetExp == rField.Which()
&& static_cast<const SwSetExpField&>(rField).GetInputFlag() )
{
pDoc->ForEachFormatField(RES_TXTATR_FIELD,
[&rField, &pTField] (const SwFormatField& rFormatField) -> bool
{ if( rFormatField.GetField() == &rField )
{
pTField = const_cast<SwFormatField&>(rFormatField).GetTextField(); returnfalse;
} returntrue;
});
} return pTField;
}
void SwEditShell::UpdateOneField(SwField &rField)
{
CurrShell aCurr( this );
StartAllAction();
{ // If there are no selections so take the value of the current cursor position.
SwPaM* pCursor = GetCursor();
SwTextField *pTextField;
SwFormatField *pFormatField;
if ( !pCursor->IsMultiSelection() && !pCursor->HasMark())
{
pTextField = GetTextFieldAtPos(pCursor->Start(), ::sw::GetTextAttrMode::Default);
if (!pTextField) // #i30221#
pTextField = lcl_FindInputField( GetDoc(), rField);
// bOkay (instead of return because of EndAllAction) becomes false, // 1) if only one PaM has more than one field or // 2) if there are mixed field types bool bOkay = true; bool bTableSelBreak = false;
SwMsgPoolItem aFieldHint( RES_TXTATR_FIELD ); // Search-Hint
SwMsgPoolItem aAnnotationFieldHint( RES_TXTATR_ANNOTATION );
SwMsgPoolItem aInputFieldHint( RES_TXTATR_INPUTFIELD ); for(SwPaM& rPaM : GetCursor()->GetRingContainer()) // for each PaM
{ if( rPaM.HasMark() && bOkay ) // ... with selection
{ // copy of the PaM
SwPaM aCurPam( *rPaM.GetMark(), *rPaM.GetPoint() );
SwPaM aPam( *rPaM.GetPoint() );
SwPosition *pCurStt = aCurPam.Start(), *pCurEnd =
aCurPam.End(); /* * In case that there are two contiguous fields in a PaM, the aPam goes step by step * to the end. aCurPam is reduced in each loop. If aCurPam was searched completely, * the loop terminates because Start = End.
*/
// Search for SwTextField ... while( bOkay
&& pCurStt->GetContentIndex() != pCurEnd->GetContentIndex()
&& (sw::FindAttrImpl(aPam, aFieldHint, fnMoveForward, aCurPam, true, GetLayout())
|| sw::FindAttrImpl(aPam, aAnnotationFieldHint, fnMoveForward, aCurPam, false, GetLayout())
|| sw::FindAttrImpl(aPam, aInputFieldHint, fnMoveForward, aCurPam, false, GetLayout())))
{ // if only one PaM has more than one field ... if( aPam.Start()->GetContentIndex() != pCurStt->GetContentIndex() )
bOkay = false;
// if there are mixed field types if( pCurField->GetTyp()->Which() !=
rField.GetTyp()->Which() )
bOkay = false;
bTableSelBreak = GetDoc()->getIDocumentFieldsAccess().UpdateField(
pTextField,
rField, false);
} // The search area is reduced by the found area:
pCurStt->AdjustContent(+1);
}
}
if( bTableSelBreak ) // If table section and table formula are updated -> finish break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.