fdo#69416: make footnote positions available to XProofreader

- ModelToViewHelper: add new flag REPLACEMODE, which causes fields and
  footnotes to be replaced with ZWSP instead of expanding them
- SwXFlatParagraph: add FootnotePositions and FieldPositions properties
- GrammarCheckingIterator: invoke XProofreader::doProofreading with
  properties FootnotePositions and FieldPositions

Change-Id: I9b66a37aac94f940546e812d8b85a35aebd8181a
This commit is contained in:
Michael Stahl
2014-04-07 23:22:22 +02:00
parent bda01cf116
commit d477ff4a81
7 changed files with 294 additions and 14 deletions

View File

@@ -489,6 +489,20 @@ uno::Reference< linguistic2::XProofreader > GrammarCheckingIterator::GetGrammarC
return xRes;
}
static uno::Sequence<beans::PropertyValue>
lcl_makeProperties(uno::Reference<text::XFlatParagraph> const& xFlatPara)
{
uno::Sequence<beans::PropertyValue> ret(2);
uno::Reference<beans::XPropertySet> const xProps(
xFlatPara, uno::UNO_QUERY_THROW);
ret[0] = beans::PropertyValue("FieldPositions", -1,
xProps->getPropertyValue("FieldPositions"),
beans::PropertyState_DIRECT_VALUE);
ret[1] = beans::PropertyValue("FootnotePositions", -1,
xProps->getPropertyValue("FootnotePositions"),
beans::PropertyState_DIRECT_VALUE);
return ret;
}
void GrammarCheckingIterator::DequeueAndCheck()
{
@@ -548,8 +562,10 @@ void GrammarCheckingIterator::DequeueAndCheck()
if (xGC.is())
{
aGuard.clear();
uno::Sequence< beans::PropertyValue > aEmptyProps;
aRes = xGC->doProofreading( aCurDocId, aCurTxt, aCurLocale, nStartPos, nSuggestedEnd, aEmptyProps );
uno::Sequence<beans::PropertyValue> const aProps(
lcl_makeProperties(xFlatPara));
aRes = xGC->doProofreading( aCurDocId, aCurTxt,
aCurLocale, nStartPos, nSuggestedEnd, aProps );
//!! work-around to prevent looping if the grammar checker
//!! failed to properly identify the sentence end
@@ -696,8 +712,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
sal_Int32 nEndPos = -1;
if (xGC.is())
{
uno::Sequence< beans::PropertyValue > aEmptyProps;
aTmpRes = xGC->doProofreading( aDocId, rText, aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aEmptyProps );
uno::Sequence<beans::PropertyValue> const aProps(
lcl_makeProperties(xFlatPara));
aTmpRes = xGC->doProofreading( aDocId, rText,
aCurLocale, nStartPos, nSuggestedEndOfSentencePos, aProps );
//!! work-around to prevent looping if the grammar checker
//!! failed to properly identify the sentence end

View File

@@ -66,6 +66,8 @@ class SwTxtNode;
#define EXPANDFOOTNOTE 0x0002
#define HIDEINVISIBLE 0x0004
#define HIDEREDLINED 0x0008
/// do not expand to content, but replace with ZWSP
#define REPLACEMODE 0x0010
class ModelToViewHelper
{
@@ -77,8 +79,12 @@ class ModelToViewHelper
*/
typedef std::pair< sal_Int32 , sal_Int32 > ConversionMapEntry;
typedef std::vector< ConversionMapEntry > ConversionMap;
typedef std::vector<sal_Int32> Positions;
ConversionMap m_aMap;
/// store positions of fields and footnotes for grammar checkers
Positions m_FieldPositions;
Positions m_FootnotePositions;
OUString m_aRetText;
@@ -99,7 +105,9 @@ public:
ModelPosition() : mnPos(0), mnSubPos(0), mbIsField(false) {}
};
ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode = EXPANDFIELDS | EXPANDFOOTNOTE);
ModelToViewHelper(const SwTxtNode &rNode,
// defaults are appropriate for spell/grammar checking
sal_uInt16 eMode = EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
ModelToViewHelper() //pass through filter, view == model
{
}
@@ -135,6 +143,8 @@ public:
ModelPosition ConvertToModelPosition( sal_Int32 nViewPos ) const;
OUString getViewText() const { return m_aRetText; }
Positions const& getFieldPositions() const { return m_FieldPositions; }
Positions const& getFootnotePositions() const { return m_FootnotePositions;}
};
#endif

View File

@@ -269,6 +269,22 @@ void SwDocTest::testModelToViewHelper()
CPPUNIT_ASSERT_EQUAL(
OUString("AAAAA BBBBB foo CCCCC foo DDDDD"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(
OUString("AAAAA BBBBB " + OUString(CHAR_ZWSP) + " CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
sViewText);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12),
aModelToViewHelper.getFootnotePositions()[0]);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(20),
aModelToViewHelper.getFootnotePositions()[1]);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFieldPositions().size());
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS);
@@ -276,6 +292,23 @@ void SwDocTest::testModelToViewHelper()
CPPUNIT_ASSERT_EQUAL(
OUString("AAAAA BBBBB CCCCC DDDDD"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(OUString("AAAAA BBBBB CCCCC DDDDD"),
sViewText);
// ??? is it a problem that we get the positions without
// EXPANDFOOTNOTE when it's completely removed?
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12),
aModelToViewHelper.getFootnotePositions()[0]);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(19),
aModelToViewHelper.getFootnotePositions()[1]);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFieldPositions().size());
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE);
@@ -298,6 +331,20 @@ void SwDocTest::testModelToViewHelper()
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(OUString("AAAAA CCCCC foo DDDDD"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | HIDEINVISIBLE | EXPANDFOOTNOTE | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(
OUString("AAAAA CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
sViewText);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12),
aModelToViewHelper.getFootnotePositions()[0]);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFieldPositions().size());
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEREDLINED | EXPANDFOOTNOTE);
@@ -305,6 +352,22 @@ void SwDocTest::testModelToViewHelper()
CPPUNIT_ASSERT_EQUAL(
OUString("AAAABB foo CCCCC foo DDDDD"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | HIDEREDLINED | EXPANDFOOTNOTE | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(
OUString("AAAABB " + OUString(CHAR_ZWSP) + " CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
sViewText);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7),
aModelToViewHelper.getFootnotePositions()[0]);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(15),
aModelToViewHelper.getFootnotePositions()[1]);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFieldPositions().size());
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE | HIDEREDLINED);
@@ -321,6 +384,19 @@ void SwDocTest::testModelToViewHelper()
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(OUString("AAAACCCCC foo DDDDD"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | HIDEINVISIBLE | HIDEREDLINED | EXPANDFOOTNOTE | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(sViewText,
OUString("AAAACCCCC " + OUString(CHAR_ZWSP) + " DDDDD"));
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(10),
aModelToViewHelper.getFootnotePositions()[0]);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFieldPositions().size());
}
m_pDoc->AppendTxtNode(*aPaM.GetPoint());
m_pDoc->InsertString(aPaM, OUString("AAAAA"));
@@ -341,6 +417,20 @@ void SwDocTest::testModelToViewHelper()
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(OUString("AAAAABBBBBCCCCC"), sViewText);
}
{
ModelToViewHelper aModelToViewHelper(*pTxtNode,
EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
OUString sViewText = aModelToViewHelper.getViewText();
CPPUNIT_ASSERT_EQUAL(
OUString("AAAAA" + OUString(CHAR_ZWSP) + "CCCCC"),
sViewText);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0),
aModelToViewHelper.getFootnotePositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1),
aModelToViewHelper.getFieldPositions().size());
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5),
aModelToViewHelper.getFieldPositions()[0]);
}
}
}

View File

@@ -21,6 +21,9 @@
#define INCLUDED_SW_SOURCE_CORE_INC_UNOFLATPARA_HXX
#include <cppuhelper/implbase1.hxx>
#include <cppuhelper/implbase3.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/text/XFlatParagraph.hpp>
#include <com/sun/star/text/XFlatParagraphIterator.hpp>
@@ -46,8 +49,9 @@ class SwDoc;
******************************************************************************/
class SwXFlatParagraph:
public ::cppu::WeakImplHelper2
public ::cppu::WeakImplHelper3
<
css::beans::XPropertySet,
css::text::XFlatParagraph,
css::lang::XUnoTunnel
>,
@@ -64,6 +68,53 @@ public:
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// XPropertySet
virtual ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()
throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL setPropertyValue(
const OUString& rPropertyName,
const ::com::sun::star::uno::Any& rValue)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::beans::PropertyVetoException,
::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
const OUString& rPropertyName)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL addPropertyChangeListener(
const OUString& rPropertyName,
const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertyChangeListener >& xListener)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL removePropertyChangeListener(
const OUString& rPropertyName,
const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XPropertyChangeListener >& xListener)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL addVetoableChangeListener(
const OUString& rPropertyName,
const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XVetoableChangeListener >& xListener)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
virtual void SAL_CALL removeVetoableChangeListener(
const OUString& rPropertyName,
const ::com::sun::star::uno::Reference<
::com::sun::star::beans::XVetoableChangeListener >& xListener)
throw (::com::sun::star::beans::UnknownPropertyException,
::com::sun::star::lang::WrappedTargetException,
::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
// text::XTextMarkup:
virtual css::uno::Reference< css::container::XStringKeyMap > SAL_CALL getMarkupInfoContainer() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;

View File

@@ -37,6 +37,7 @@ struct FieldResult
{
sal_Int32 m_nFieldPos;
OUString m_sExpand;
enum { FIELD, FOOTNOTE } m_eType;
};
class sortfieldresults :
@@ -144,9 +145,11 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
case RES_TXTATR_ANNOTATION:
if (eMode & EXPANDFIELDS)
{
aFieldResult.m_sExpand =
static_cast<SwTxtFld const*>(pAttr)->GetFmtFld().GetField()
->ExpandField(true);
aFieldResult.m_sExpand = (eMode & REPLACEMODE)
? OUString(CHAR_ZWSP)
: static_cast<SwTxtFld const*>(pAttr)->
GetFmtFld().GetField()->ExpandField(true);
aFieldResult.m_eType = FieldResult::FIELD;
}
break;
case RES_TXTATR_FTN:
@@ -154,7 +157,10 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
{
const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn();
const SwDoc *pDoc = rNode.GetDoc();
aFieldResult.m_sExpand = rFtn.GetViewNumStr(*pDoc);
aFieldResult.m_sExpand = (eMode & REPLACEMODE)
? OUString(CHAR_ZWSP)
: rFtn.GetViewNumStr(*pDoc);
aFieldResult.m_eType = FieldResult::FOOTNOTE;
}
break;
default:
@@ -186,7 +192,10 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
{
FieldResult aFieldResult;
aFieldResult.m_nFieldPos = nDummyCharPos;
aFieldResult.m_sExpand = sw::mark::ExpandFieldmark(pMark);
aFieldResult.m_sExpand = (eMode & REPLACEMODE)
? OUString(CHAR_ZWSP)
: sw::mark::ExpandFieldmark(pMark);
aFieldResult.m_eType = FieldResult::FIELD;
aFind->m_aAttrs.insert(aFieldResult);
}
}
@@ -209,8 +218,18 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
{
for (FieldResultSet::iterator j = i->m_aAttrs.begin(); j != i->m_aAttrs.end(); ++j)
{
m_aRetText = m_aRetText.replaceAt( nOffset + j->m_nFieldPos, 1, j->m_sExpand );
m_aMap.push_back( ConversionMapEntry( j->m_nFieldPos, nOffset + j->m_nFieldPos ) );
sal_Int32 const viewPos(nOffset + j->m_nFieldPos);
m_aRetText = m_aRetText.replaceAt(viewPos, 1, j->m_sExpand);
m_aMap.push_back( ConversionMapEntry(j->m_nFieldPos, viewPos) );
switch (j->m_eType)
{
case FieldResult::FIELD:
m_FieldPositions.push_back(viewPos);
break;
case FieldResult::FOOTNOTE:
m_FootnotePositions.push_back(viewPos);
break;
}
nOffset += j->m_sExpand.getLength() - 1;
}
}

View File

@@ -1455,7 +1455,7 @@ SwRect SwTxtFrm::SmartTagScan( SwCntntNode* /*pActNode*/, sal_Int32 /*nActPos*/
if ( nBegin < nEnd )
{
// Expand the string:
const ModelToViewHelper aConversionMap(*pNode);
const ModelToViewHelper aConversionMap(*pNode /*TODO - replace or expand fields for smart tags?*/);
OUString aExpandText = aConversionMap.getViewText();
// Ownership ov ConversionMap is passed to SwXTextMarkup object!

View File

@@ -92,6 +92,10 @@ uno::Any SAL_CALL SwXFlatParagraph::queryInterface( const uno::Type& rType ) thr
{
return uno::makeAny( uno::Reference < text::XFlatParagraph >(this) );
}
else if (rType == ::getCppuType((uno::Reference< beans::XPropertySet>*)0))
{
return uno::makeAny( uno::Reference<beans::XPropertySet>(this) );
}
else
return SwXTextMarkup::queryInterface( rType );
}
@@ -111,6 +115,94 @@ const SwTxtNode* SwXFlatParagraph::getTxtNode() const
return mpTxtNode;
}
// XPropertySet
uno::Reference< beans::XPropertySetInfo > SAL_CALL
SwXFlatParagraph::getPropertySetInfo()
throw (uno::RuntimeException, std::exception)
{
throw uno::RuntimeException("SwXFlatParagraph::getPropertySetInfo(): "
"not implemented", 0/*static_cast< ::cppu::OWeakObject*>(this)*/);
}
void SAL_CALL
SwXFlatParagraph::setPropertyValue(const OUString&, const uno::Any&)
throw (beans::UnknownPropertyException, beans::PropertyVetoException,
lang::IllegalArgumentException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
throw lang::IllegalArgumentException("no values can be set",
0/*static_cast< ::cppu::OWeakObject*>(this)*/, 0);
}
uno::Any SAL_CALL
SwXFlatParagraph::getPropertyValue(const OUString& rPropertyName)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
SolarMutexGuard g;
if (rPropertyName == "FieldPositions")
{
uno::Sequence<sal_Int32> ret(maConversionMap.getFieldPositions().size());
std::copy(maConversionMap.getFieldPositions().begin(),
maConversionMap.getFieldPositions().end(), ret.begin());
return uno::makeAny(ret);
}
else if (rPropertyName == "FootnotePositions")
{
uno::Sequence<sal_Int32> ret(maConversionMap.getFootnotePositions().size());
std::copy(maConversionMap.getFootnotePositions().begin(),
maConversionMap.getFootnotePositions().end(), ret.begin());
return uno::makeAny(ret);
}
return uno::Any();
}
void SAL_CALL
SwXFlatParagraph::addPropertyChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
SAL_WARN("sw.uno",
"SwXFlatParagraph::addPropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXFlatParagraph::removePropertyChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
SAL_WARN("sw.uno",
"SwXFlatParagraph::removePropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXFlatParagraph::addVetoableChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
SAL_WARN("sw.uno",
"SwXFlatParagraph::addVetoableChangeListener(): not implemented");
}
void SAL_CALL
SwXFlatParagraph::removeVetoableChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException, std::exception)
{
SAL_WARN("sw.uno",
"SwXFlatParagraph::removeVetoableChangeListener(): not implemented");
}
css::uno::Reference< css::container::XStringKeyMap > SAL_CALL SwXFlatParagraph::getMarkupInfoContainer() throw (css::uno::RuntimeException, std::exception)
{
return SwXTextMarkup::getMarkupInfoContainer();