2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2010-12-17 09:02:23 +01:00
|
|
|
#include "switerator.hxx"
|
2000-09-18 23:08:29 +00:00
|
|
|
#include "editsh.hxx"
|
|
|
|
#include "doc.hxx"
|
|
|
|
#include <docary.hxx>
|
|
|
|
#include <fmtfld.hxx>
|
|
|
|
#include <txtfld.hxx>
|
|
|
|
#include "edimp.hxx"
|
|
|
|
#include "expfld.hxx"
|
|
|
|
#include "pam.hxx"
|
|
|
|
#include "docfld.hxx"
|
|
|
|
#include "ndtxt.hxx"
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// sort input values
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
SwInputFieldList::SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst )
|
2000-09-18 23:08:29 +00:00
|
|
|
: pSh(pShell)
|
|
|
|
{
|
2013-06-10 21:54:04 +02:00
|
|
|
// create sorted list of all input fields
|
2000-09-18 23:08:29 +00:00
|
|
|
pSrtLst = new _SetGetExpFlds();
|
|
|
|
|
|
|
|
const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
|
2012-05-21 17:01:56 +02:00
|
|
|
const sal_uInt16 nSize = rFldTypes.size();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// iterate over all types
|
2011-01-17 15:06:54 +01:00
|
|
|
for(sal_uInt16 i=0; i < nSize; ++i)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nType = pFldType->Which();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2003-06-30 14:51:01 +00:00
|
|
|
if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType || RES_DROPDOWN == nType )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2010-12-17 09:02:23 +01:00
|
|
|
SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
|
2013-09-24 15:03:38 +00:00
|
|
|
for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2013-09-24 15:03:38 +00:00
|
|
|
const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// only process InputFields, interactive SetExpFlds and DropDown fields
|
2000-09-18 23:08:29 +00:00
|
|
|
if( !pTxtFld || ( RES_SETEXPFLD == nType &&
|
2013-09-24 15:03:38 +00:00
|
|
|
!((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
|
2000-09-18 23:08:29 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
|
|
|
|
if( rTxtNode.GetNodes().IsDocNodes() )
|
|
|
|
{
|
|
|
|
if( bBuildTmpLst )
|
|
|
|
{
|
2012-06-25 16:09:52 +02:00
|
|
|
aTmpLst.insert( pTxtFld );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SwNodeIndex aIdx( rTxtNode );
|
|
|
|
_SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
|
2012-07-13 15:42:51 +02:00
|
|
|
pSrtLst->insert( pNew );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SwInputFieldList::~SwInputFieldList()
|
|
|
|
{
|
|
|
|
delete pSrtLst;
|
|
|
|
}
|
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 SwInputFieldList::Count() const
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2012-07-13 15:42:51 +02:00
|
|
|
return pSrtLst->size();
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// get field from list in sorted order
|
2011-01-17 15:06:54 +01:00
|
|
|
SwField* SwInputFieldList::GetField(sal_uInt16 nId)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2013-09-24 15:03:38 +00:00
|
|
|
const SwTxtFld* pTxtFld = (*pSrtLst)[ nId ]->GetTxtFld();
|
2013-06-10 21:54:04 +02:00
|
|
|
OSL_ENSURE( pTxtFld, "no TextFld" );
|
2013-09-24 15:03:38 +00:00
|
|
|
return (SwField*)pTxtFld->GetFmtFld().GetField();
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
/// save cursor
|
2000-09-18 23:08:29 +00:00
|
|
|
void SwInputFieldList::PushCrsr()
|
|
|
|
{
|
|
|
|
pSh->Push();
|
|
|
|
pSh->ClearMark();
|
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
/// get cursor
|
2000-09-18 23:08:29 +00:00
|
|
|
void SwInputFieldList::PopCrsr()
|
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
pSh->Pop(sal_False);
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
/// go to position of a field
|
2011-01-17 15:06:54 +01:00
|
|
|
void SwInputFieldList::GotoFieldPos(sal_uInt16 nId)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
pSh->StartAllAction();
|
|
|
|
(*pSrtLst)[ nId ]->GetPosOfContent( *pSh->GetCrsr()->GetPoint() );
|
|
|
|
pSh->EndAllAction();
|
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
/** Compare TmpLst with current fields.
|
|
|
|
*
|
|
|
|
* All new ones are added to SortList so that they can be updated.
|
|
|
|
* For text blocks: update only input fields.
|
|
|
|
*
|
|
|
|
* @return count
|
|
|
|
*/
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 SwInputFieldList::BuildSortLst()
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
const SwFldTypes& rFldTypes = *pSh->GetDoc()->GetFldTypes();
|
2012-05-21 17:01:56 +02:00
|
|
|
sal_uInt16 nSize = rFldTypes.size();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// iterate over all types
|
2011-01-17 15:06:54 +01:00
|
|
|
for( sal_uInt16 i = 0; i < nSize; ++i )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
SwFieldType* pFldType = (SwFieldType*)rFldTypes[ i ];
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nType = pFldType->Which();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
|
|
|
if( RES_SETEXPFLD == nType || RES_INPUTFLD == nType )
|
|
|
|
{
|
2010-12-17 09:02:23 +01:00
|
|
|
SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
|
2013-09-24 15:03:38 +00:00
|
|
|
for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2013-09-24 15:03:38 +00:00
|
|
|
const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// process only InputFields and interactive SetExpFlds
|
2000-09-18 23:08:29 +00:00
|
|
|
if( !pTxtFld || ( RES_SETEXPFLD == nType &&
|
2013-09-24 15:03:38 +00:00
|
|
|
!((SwSetExpField*)pFmtFld->GetField())->GetInputFlag()))
|
2000-09-18 23:08:29 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
|
|
|
|
if( rTxtNode.GetNodes().IsDocNodes() )
|
|
|
|
{
|
2013-06-10 21:54:04 +02:00
|
|
|
// not in TempList, thus add to SortList
|
2012-06-25 16:09:52 +02:00
|
|
|
std::set<const SwTxtFld*>::iterator it = aTmpLst.find( pTxtFld );
|
|
|
|
if( aTmpLst.end() == it )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
SwNodeIndex aIdx( rTxtNode );
|
|
|
|
_SetGetExpFld* pNew = new _SetGetExpFld(aIdx, pTxtFld );
|
2012-07-13 15:42:51 +02:00
|
|
|
pSrtLst->insert( pNew );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
else
|
2012-06-25 16:09:52 +02:00
|
|
|
aTmpLst.erase( it );
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
// the pointers are not needed anymore
|
2012-06-25 16:09:52 +02:00
|
|
|
aTmpLst.clear();
|
2012-07-13 15:42:51 +02:00
|
|
|
return pSrtLst->size();
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 21:54:04 +02:00
|
|
|
/// remove all fields outside of any selections from list
|
2000-09-18 23:08:29 +00:00
|
|
|
void SwInputFieldList::RemoveUnselectedFlds()
|
|
|
|
{
|
|
|
|
_SetGetExpFlds* pNewLst = new _SetGetExpFlds();
|
|
|
|
|
2013-09-21 13:57:41 +02:00
|
|
|
FOREACHPAM_START(pSh->GetCrsr())
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2011-01-17 15:06:54 +01:00
|
|
|
for (sal_uInt16 i = 0; i < Count();)
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
|
|
|
_SetGetExpFld* pFld = (*pSrtLst)[i];
|
|
|
|
SwPosition aPos(*PCURCRSR->GetPoint());
|
|
|
|
|
|
|
|
pFld->GetPos( aPos );
|
|
|
|
|
|
|
|
if (aPos >= *PCURCRSR->Start() && aPos < *PCURCRSR->End())
|
|
|
|
{
|
2013-06-10 21:54:04 +02:00
|
|
|
// field in selection
|
2012-07-13 15:42:51 +02:00
|
|
|
pNewLst->insert( (*pSrtLst)[i] );
|
2012-07-25 16:21:05 +02:00
|
|
|
pSrtLst->erase(i);
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FOREACHPAM_END()
|
|
|
|
|
|
|
|
delete pSrtLst;
|
|
|
|
pSrtLst = pNewLst;
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:30:41 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|