2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 22:24:36 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|
|
|
#include <com/sun/star/container/XIndexReplace.hpp>
|
|
|
|
#include <com/sun/star/style/NumberingType.hpp>
|
2000-10-23 10:28:11 +00:00
|
|
|
#include <com/sun/star/container/XNamed.hpp>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "XMLTextNumRuleInfo.hxx"
|
2010-04-16 23:04:00 +02:00
|
|
|
#include "xmloff/XMLTextListAutoStylePool.hxx"
|
2008-06-06 10:50:50 +00:00
|
|
|
|
2008-03-12 10:05:35 +00:00
|
|
|
using ::rtl::OUString;
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::style;
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
// Complete refactoring of the class and enhancement of the class for lists.
|
2008-06-06 10:50:50 +00:00
|
|
|
XMLTextNumRuleInfo::XMLTextNumRuleInfo()
|
2008-06-13 11:07:21 +00:00
|
|
|
: msNumberingRules(RTL_CONSTASCII_USTRINGPARAM("NumberingRules"))
|
|
|
|
, msNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("NumberingLevel"))
|
|
|
|
, msNumberingStartValue(RTL_CONSTASCII_USTRINGPARAM("NumberingStartValue"))
|
|
|
|
, msParaIsNumberingRestart(RTL_CONSTASCII_USTRINGPARAM("ParaIsNumberingRestart"))
|
|
|
|
, msNumberingIsNumber(RTL_CONSTASCII_USTRINGPARAM("NumberingIsNumber"))
|
|
|
|
, msNumberingIsOutline(RTL_CONSTASCII_USTRINGPARAM("NumberingIsOutline"))
|
|
|
|
, msPropNameListId(RTL_CONSTASCII_USTRINGPARAM("ListId"))
|
|
|
|
, msPropNameStartWith(RTL_CONSTASCII_USTRINGPARAM("StartWith"))
|
2008-12-11 09:52:14 +00:00
|
|
|
, msContinueingPreviousSubTree(RTL_CONSTASCII_USTRINGPARAM("ContinueingPreviousSubTree"))
|
|
|
|
, msListLabelStringProp(RTL_CONSTASCII_USTRINGPARAM("ListLabelString"))
|
2008-06-13 11:07:21 +00:00
|
|
|
, mxNumRules()
|
|
|
|
, msNumRulesName()
|
|
|
|
, msListId()
|
|
|
|
, mnListStartValue( -1 )
|
|
|
|
, mnListLevel( 0 )
|
|
|
|
, mbIsNumbered( sal_False )
|
|
|
|
, mbIsRestart( sal_False )
|
|
|
|
, mnListLevelStartValue( -1 )
|
|
|
|
, mbOutlineStyleAsNormalListStyle( sal_False )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2010-11-09 01:42:14 +05:00
|
|
|
// Written OpenDocument file format doesn't fit to the created text document (#i69627#)
|
2000-09-18 16:07:07 +00:00
|
|
|
void XMLTextNumRuleInfo::Set(
|
|
|
|
const ::com::sun::star::uno::Reference <
|
2006-10-13 11:16:22 +00:00
|
|
|
::com::sun::star::text::XTextContent > & xTextContent,
|
2008-06-13 08:20:16 +00:00
|
|
|
const sal_Bool bOutlineStyleAsNormalListStyle,
|
2008-12-11 09:52:14 +00:00
|
|
|
const XMLTextListAutoStylePool& rListAutoPool,
|
|
|
|
const sal_Bool bExportTextNumberElement )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
Reset();
|
2010-11-09 01:42:14 +05:00
|
|
|
// Written OpenDocument file format doesn't fit to the created text document (#i69627#)
|
2006-10-13 11:16:22 +00:00
|
|
|
mbOutlineStyleAsNormalListStyle = bOutlineStyleAsNormalListStyle;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
Reference< XPropertySet > xPropSet( xTextContent, UNO_QUERY );
|
2008-06-13 08:20:16 +00:00
|
|
|
Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-11-16 13:47:50 +00:00
|
|
|
// check if this paragraph supports a numbering
|
2008-06-13 11:07:21 +00:00
|
|
|
if( !xPropSetInfo->hasPropertyByName( msNumberingLevel ) )
|
2001-11-16 13:47:50 +00:00
|
|
|
return;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSet->getPropertyValue( msNumberingLevel ) >>= mnListLevel )
|
2008-06-06 10:50:50 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSetInfo->hasPropertyByName( msNumberingRules ) )
|
2008-06-13 08:20:16 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
xPropSet->getPropertyValue( msNumberingRules ) >>= mxNumRules;
|
2008-06-13 08:20:16 +00:00
|
|
|
}
|
2008-06-06 10:50:50 +00:00
|
|
|
}
|
|
|
|
else
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-06 10:50:50 +00:00
|
|
|
// in applications using the outliner we always have a numbering rule,
|
|
|
|
// so a void property no numbering
|
2008-06-13 08:20:16 +00:00
|
|
|
mnListLevel = 0;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-09 01:42:14 +05:00
|
|
|
// Assertion saving writer document (#i97312#)
|
2009-01-07 11:57:24 +00:00
|
|
|
if ( mxNumRules.is() && mxNumRules->getCount() < 1 )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( false,
|
|
|
|
"<XMLTextNumRuleInfo::Set(..)> - numbering rules instance does not contain any numbering rule" );
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-13 15:58:25 +01:00
|
|
|
if ( mnListLevel < 0 )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( false,
|
|
|
|
"<XMLTextNumRuleInfo::Set(..)> - unexpected numbering level" );
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-09 01:42:14 +05:00
|
|
|
// Written OpenDocument file format doesn't fit to the created text document (#i69627#)
|
2006-10-13 11:16:22 +00:00
|
|
|
bool bSuppressListStyle( false );
|
2008-06-13 11:07:21 +00:00
|
|
|
if ( mxNumRules.is() )
|
2004-11-26 12:05:38 +00:00
|
|
|
{
|
2006-10-13 11:16:22 +00:00
|
|
|
if ( !mbOutlineStyleAsNormalListStyle )
|
|
|
|
{
|
2008-06-06 10:50:50 +00:00
|
|
|
sal_Bool bIsOutline = sal_False;
|
2008-06-13 08:20:16 +00:00
|
|
|
Reference<XPropertySet> xNumRulesProps(mxNumRules, UNO_QUERY);
|
|
|
|
if ( xNumRulesProps.is() &&
|
|
|
|
xNumRulesProps->getPropertySetInfo()->
|
2008-06-13 11:07:21 +00:00
|
|
|
hasPropertyByName( msNumberingIsOutline ) )
|
2006-10-13 11:16:22 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
xNumRulesProps->getPropertyValue( msNumberingIsOutline ) >>= bIsOutline;
|
2006-10-13 11:16:22 +00:00
|
|
|
bSuppressListStyle = bIsOutline ? true : false;
|
|
|
|
}
|
|
|
|
}
|
2004-11-26 12:05:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
if( mxNumRules.is() && !bSuppressListStyle )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-13 08:20:16 +00:00
|
|
|
// First try to find the numbering rules in the list auto style pool.
|
|
|
|
// If not found, the numbering rules instance has to be named.
|
|
|
|
msNumRulesName = rListAutoPool.Find( mxNumRules );
|
2012-01-26 17:05:51 -02:00
|
|
|
if ( msNumRulesName.isEmpty() )
|
2008-06-13 08:20:16 +00:00
|
|
|
{
|
|
|
|
Reference < XNamed > xNamed( mxNumRules, UNO_QUERY );
|
|
|
|
DBG_ASSERT( xNamed.is(),
|
|
|
|
"<XMLTextNumRuleInfo::Set(..)> - numbering rules instance have to be named. Serious defect -> please inform OD." );
|
|
|
|
if( xNamed.is() )
|
|
|
|
{
|
|
|
|
msNumRulesName = xNamed->getName();
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 17:05:51 -02:00
|
|
|
DBG_ASSERT( !msNumRulesName.isEmpty(),
|
2008-06-13 11:07:21 +00:00
|
|
|
"<XMLTextNumRuleInfo::Set(..)> - no name found for numbering rules instance. Serious defect -> please inform OD." );
|
2008-06-13 08:20:16 +00:00
|
|
|
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSetInfo->hasPropertyByName( msPropNameListId ) )
|
2000-10-31 08:00:40 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
xPropSet->getPropertyValue( msPropNameListId ) >>= msListId;
|
2000-10-31 08:00:40 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2008-12-11 09:52:14 +00:00
|
|
|
mbContinueingPreviousSubTree = sal_False;
|
|
|
|
if( xPropSetInfo->hasPropertyByName( msContinueingPreviousSubTree ) )
|
|
|
|
{
|
|
|
|
xPropSet->getPropertyValue( msContinueingPreviousSubTree ) >>= mbContinueingPreviousSubTree;
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
mbIsNumbered = sal_True;
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSetInfo->hasPropertyByName( msNumberingIsNumber ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
if( !(xPropSet->getPropertyValue( msNumberingIsNumber ) >>= mbIsNumbered ) )
|
2008-06-06 10:50:50 +00:00
|
|
|
{
|
2011-03-12 14:27:45 +01:00
|
|
|
OSL_FAIL( "numbered paragraph without number info" );
|
2008-06-13 08:20:16 +00:00
|
|
|
mbIsNumbered = sal_False;
|
2008-06-06 10:50:50 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
if( mbIsNumbered )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSetInfo->hasPropertyByName( msParaIsNumberingRestart ) )
|
2000-10-23 10:28:11 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
xPropSet->getPropertyValue( msParaIsNumberingRestart ) >>= mbIsRestart;
|
2000-10-23 10:28:11 +00:00
|
|
|
}
|
2008-06-13 11:07:21 +00:00
|
|
|
if( xPropSetInfo->hasPropertyByName( msNumberingStartValue ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-13 11:07:21 +00:00
|
|
|
xPropSet->getPropertyValue( msNumberingStartValue ) >>= mnListStartValue;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
OSL_ENSURE( mnListLevel < mxNumRules->getCount(), "wrong num rule level" );
|
|
|
|
if( mnListLevel >= mxNumRules->getCount() )
|
2001-04-18 07:52:32 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
Sequence<PropertyValue> aProps;
|
2008-06-13 08:20:16 +00:00
|
|
|
mxNumRules->getByIndex( mnListLevel ) >>= aProps;
|
2008-06-06 10:50:50 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
const PropertyValue* pPropArray = aProps.getConstArray();
|
|
|
|
sal_Int32 nCount = aProps.getLength();
|
|
|
|
for( sal_Int32 i=0; i<nCount; i++ )
|
|
|
|
{
|
2008-06-13 08:20:16 +00:00
|
|
|
const PropertyValue& rProp = pPropArray[i];
|
|
|
|
|
2008-06-13 11:07:21 +00:00
|
|
|
if ( rProp.Name == msPropNameStartWith )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2008-06-13 08:20:16 +00:00
|
|
|
rProp.Value >>= mnListLevelStartValue;
|
2008-06-13 11:07:21 +00:00
|
|
|
break;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-13 08:20:16 +00:00
|
|
|
|
2008-12-11 09:52:14 +00:00
|
|
|
msListLabelString = ::rtl::OUString();
|
|
|
|
if ( bExportTextNumberElement &&
|
|
|
|
xPropSetInfo->hasPropertyByName( msListLabelStringProp ) )
|
|
|
|
{
|
|
|
|
xPropSet->getPropertyValue( msListLabelStringProp ) >>= msListLabelString;
|
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
// paragraph's list level range is [0..9] representing list levels [1..10]
|
|
|
|
++mnListLevel;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2008-06-13 11:07:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mnListLevel = 0;
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
sal_Bool XMLTextNumRuleInfo::BelongsToSameList( const XMLTextNumRuleInfo& rCmp ) const
|
2008-06-06 10:50:50 +00:00
|
|
|
{
|
2008-06-13 08:20:16 +00:00
|
|
|
sal_Bool bRet( sal_True );
|
|
|
|
// Currently only the text documents support <ListId>.
|
2012-01-26 17:05:51 -02:00
|
|
|
if ( !rCmp.msListId.isEmpty() || !msListId.isEmpty() )
|
2008-06-13 08:20:16 +00:00
|
|
|
{
|
|
|
|
bRet = rCmp.msListId == msListId;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bRet = HasSameNumRules( rCmp );
|
|
|
|
}
|
2008-06-06 10:50:50 +00:00
|
|
|
|
2008-06-13 08:20:16 +00:00
|
|
|
return bRet;
|
2008-06-06 10:50:50 +00:00
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|