xref: /AOO41X/main/xmloff/source/text/txtsecte.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _XMLOFF_TXTPARAE_HXX
28cdf0e10cSrcweir #include <xmloff/txtparae.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <rtl/ustring.hxx>
32cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <vector>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
41cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValues.hpp>
43cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
44cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
45cdf0e10cSrcweir #include <com/sun/star/text/XTextSection.hpp>
46cdf0e10cSrcweir #include <com/sun/star/text/SectionFileLink.hpp>
47cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
48cdf0e10cSrcweir #include <com/sun/star/text/XDocumentIndex.hpp>
49cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
50cdf0e10cSrcweir #include <xmloff/families.hxx>
51cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
52cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
53cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
54cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
55cdf0e10cSrcweir #include "XMLTextNumRuleInfo.hxx"
56cdf0e10cSrcweir #include "XMLSectionExport.hxx"
57cdf0e10cSrcweir #include "XMLRedlineExport.hxx"
58cdf0e10cSrcweir #ifndef _XMLOFF_MULTIPROPERTYSETHELPER_HXX
59cdf0e10cSrcweir #include "MultiPropertySetHelper.hxx"
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir 
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir using namespace ::com::sun::star::text;
64cdf0e10cSrcweir using namespace ::com::sun::star::uno;
65cdf0e10cSrcweir using namespace ::std;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir using ::rtl::OUString;
68cdf0e10cSrcweir using ::rtl::OUStringBuffer;
69cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet;
70cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
71cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValues;
72cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState;
73cdf0e10cSrcweir using ::com::sun::star::container::XIndexReplace;
74cdf0e10cSrcweir using ::com::sun::star::container::XNamed;
75cdf0e10cSrcweir using ::com::sun::star::lang::XServiceInfo;
76cdf0e10cSrcweir 
lcl_findXText(const Reference<XTextSection> & rSect)77cdf0e10cSrcweir Reference<XText> lcl_findXText(const Reference<XTextSection>& rSect)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 	Reference<XText> xText;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	Reference<XTextContent> xTextContent(rSect, UNO_QUERY);
82cdf0e10cSrcweir 	if (xTextContent.is())
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		xText.set(xTextContent->getAnchor()->getText());
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	return xText;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
exportListAndSectionChange(Reference<XTextSection> & rPrevSection,const Reference<XTextContent> & rNextSectionContent,const XMLTextNumRuleInfo & rPrevRule,const XMLTextNumRuleInfo & rNextRule,sal_Bool bAutoStyles)90cdf0e10cSrcweir void XMLTextParagraphExport::exportListAndSectionChange(
91cdf0e10cSrcweir 	Reference<XTextSection> & rPrevSection,
92cdf0e10cSrcweir 	const Reference<XTextContent> & rNextSectionContent,
93cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rPrevRule,
94cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rNextRule,
95cdf0e10cSrcweir 	sal_Bool bAutoStyles)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	Reference<XTextSection> xNextSection;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	// first: get current XTextSection
100cdf0e10cSrcweir 	Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
101cdf0e10cSrcweir 	if (xPropSet.is())
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		if (xPropSet->getPropertySetInfo()->hasPropertyByName(sTextSection))
104cdf0e10cSrcweir 		{
105cdf0e10cSrcweir 			xPropSet->getPropertyValue(sTextSection) >>= xNextSection;
106cdf0e10cSrcweir 		}
107cdf0e10cSrcweir 		// else: no current section
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	exportListAndSectionChange(rPrevSection, xNextSection,
111cdf0e10cSrcweir 							   rPrevRule, rNextRule, bAutoStyles);
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
exportListAndSectionChange(Reference<XTextSection> & rPrevSection,MultiPropertySetHelper & rPropSetHelper,sal_Int16 nTextSectionId,const Reference<XTextContent> & rNextSectionContent,const XMLTextNumRuleInfo & rPrevRule,const XMLTextNumRuleInfo & rNextRule,sal_Bool bAutoStyles)114cdf0e10cSrcweir void XMLTextParagraphExport::exportListAndSectionChange(
115cdf0e10cSrcweir 	Reference<XTextSection> & rPrevSection,
116cdf0e10cSrcweir 	MultiPropertySetHelper& rPropSetHelper,
117cdf0e10cSrcweir 	sal_Int16 nTextSectionId,
118cdf0e10cSrcweir 	const Reference<XTextContent> & rNextSectionContent,
119cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rPrevRule,
120cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rNextRule,
121cdf0e10cSrcweir 	sal_Bool bAutoStyles)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	Reference<XTextSection> xNextSection;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	// first: get current XTextSection
126cdf0e10cSrcweir 	Reference<XPropertySet> xPropSet(rNextSectionContent, UNO_QUERY);
127cdf0e10cSrcweir 	if (xPropSet.is())
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		if( !rPropSetHelper.checkedProperties() )
130cdf0e10cSrcweir 			rPropSetHelper.hasProperties( xPropSet->getPropertySetInfo() );
131cdf0e10cSrcweir 		if( rPropSetHelper.hasProperty( nTextSectionId ))
132cdf0e10cSrcweir 		{
133cdf0e10cSrcweir 			xNextSection.set(rPropSetHelper.getValue( nTextSectionId , xPropSet,
134cdf0e10cSrcweir                 sal_True ), uno::UNO_QUERY);
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 		// else: no current section
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	exportListAndSectionChange(rPrevSection, xNextSection,
140cdf0e10cSrcweir 							   rPrevRule, rNextRule, bAutoStyles);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
exportListAndSectionChange(Reference<XTextSection> & rPrevSection,const Reference<XTextSection> & rNextSection,const XMLTextNumRuleInfo & rPrevRule,const XMLTextNumRuleInfo & rNextRule,sal_Bool bAutoStyles)143cdf0e10cSrcweir void XMLTextParagraphExport::exportListAndSectionChange(
144cdf0e10cSrcweir 	Reference<XTextSection> & rPrevSection,
145cdf0e10cSrcweir 	const Reference<XTextSection> & rNextSection,
146cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rPrevRule,
147cdf0e10cSrcweir 	const XMLTextNumRuleInfo& rNextRule,
148cdf0e10cSrcweir 	sal_Bool bAutoStyles)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	// old != new? -> maybe we have to start or end a new section
151cdf0e10cSrcweir 	if (rPrevSection != rNextSection)
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		// a new section started, or an old one gets closed!
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 		// close old list
156cdf0e10cSrcweir         XMLTextNumRuleInfo aEmptyNumRuleInfo;
157cdf0e10cSrcweir 		if ( !bAutoStyles )
158cdf0e10cSrcweir             exportListChange(rPrevRule, aEmptyNumRuleInfo);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		// Build stacks of old and new sections
161cdf0e10cSrcweir 		// Sections on top of mute sections should not be on the stack
162cdf0e10cSrcweir         vector< Reference<XTextSection> > aOldStack;
163cdf0e10cSrcweir 		Reference<XTextSection> aCurrent(rPrevSection);
164cdf0e10cSrcweir 		while(aCurrent.is())
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			// if we have a mute section, ignore all its children
167cdf0e10cSrcweir 			// (all previous ones)
168cdf0e10cSrcweir 			if (pSectionExport->IsMuteSection(aCurrent))
169cdf0e10cSrcweir 				aOldStack.clear();
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 			aOldStack.push_back(aCurrent);
172cdf0e10cSrcweir 			aCurrent.set(aCurrent->getParentSection());
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         vector< Reference<XTextSection> > aNewStack;
176cdf0e10cSrcweir 		aCurrent.set(rNextSection);
177cdf0e10cSrcweir 		sal_Bool bMute = sal_False;
178cdf0e10cSrcweir 		while(aCurrent.is())
179cdf0e10cSrcweir 		{
180cdf0e10cSrcweir 			// if we have a mute section, ignore all its children
181cdf0e10cSrcweir 			// (all previous ones)
182cdf0e10cSrcweir 			if (pSectionExport->IsMuteSection(aCurrent))
183cdf0e10cSrcweir 			{
184cdf0e10cSrcweir 				aNewStack.clear();
185cdf0e10cSrcweir 				bMute = sal_True;
186cdf0e10cSrcweir 			}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 			aNewStack.push_back(aCurrent);
189cdf0e10cSrcweir 			aCurrent.set(aCurrent->getParentSection());
190cdf0e10cSrcweir 		}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 		// compare the two stacks
193cdf0e10cSrcweir 		vector<Reference<XTextSection> > ::reverse_iterator aOld =
194cdf0e10cSrcweir 			aOldStack.rbegin();
195cdf0e10cSrcweir 		vector<Reference<XTextSection> > ::reverse_iterator aNew =
196cdf0e10cSrcweir 			aNewStack.rbegin();
197cdf0e10cSrcweir 		// compare bottom sections and skip equal section
198cdf0e10cSrcweir 		while ( (aOld != aOldStack.rend()) &&
199cdf0e10cSrcweir 				(aNew != aNewStack.rend()) &&
200cdf0e10cSrcweir 				(*aOld) == (*aNew) )
201cdf0e10cSrcweir 		{
202cdf0e10cSrcweir 			++aOld;
203cdf0e10cSrcweir 			++aNew;
204cdf0e10cSrcweir 		}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		// close all elements of aOld ...
207cdf0e10cSrcweir 		// (order: newest to oldest)
208cdf0e10cSrcweir 		if (aOld != aOldStack.rend())
209cdf0e10cSrcweir 		{
210cdf0e10cSrcweir 			vector<Reference<XTextSection> > ::iterator aOldForward(
211cdf0e10cSrcweir 				aOldStack.begin());
212cdf0e10cSrcweir 			while ((aOldForward != aOldStack.end()) &&
213cdf0e10cSrcweir 				   (*aOldForward != *aOld))
214cdf0e10cSrcweir 			{
215cdf0e10cSrcweir 				if ( !bAutoStyles && (NULL != pRedlineExport) )
216cdf0e10cSrcweir 					pRedlineExport->ExportStartOrEndRedline(*aOldForward,
217cdf0e10cSrcweir 																sal_False);
218cdf0e10cSrcweir 				pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
219cdf0e10cSrcweir 				++aOldForward;
220cdf0e10cSrcweir 			}
221cdf0e10cSrcweir 			if (aOldForward != aOldStack.end())
222cdf0e10cSrcweir 			{
223cdf0e10cSrcweir 				if ( !bAutoStyles && (NULL != pRedlineExport) )
224cdf0e10cSrcweir 					pRedlineExport->ExportStartOrEndRedline(*aOldForward,
225cdf0e10cSrcweir 															sal_False);
226cdf0e10cSrcweir 				pSectionExport->ExportSectionEnd(*aOldForward, bAutoStyles);
227cdf0e10cSrcweir 			}
228cdf0e10cSrcweir 		}
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		// ...then open all of aNew
231cdf0e10cSrcweir 		// (order: oldest to newest)
232cdf0e10cSrcweir 		while (aNew != aNewStack.rend())
233cdf0e10cSrcweir 		{
234cdf0e10cSrcweir             if ( !bAutoStyles && (NULL != pRedlineExport) )
235cdf0e10cSrcweir 				pRedlineExport->ExportStartOrEndRedline(*aNew, sal_True);
236cdf0e10cSrcweir 			pSectionExport->ExportSectionStart(*aNew, bAutoStyles);
237cdf0e10cSrcweir 			++aNew;
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 		// start new list
241cdf0e10cSrcweir 		if ( !bAutoStyles && !bMute )
242cdf0e10cSrcweir             exportListChange(aEmptyNumRuleInfo, rNextRule);
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir 	else
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		// list change, if sections have not changed
247cdf0e10cSrcweir 		if ( !bAutoStyles )
248cdf0e10cSrcweir 			exportListChange(rPrevRule, rNextRule);
249cdf0e10cSrcweir 	}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	// save old section (old numRule gets saved in calling method)
252cdf0e10cSrcweir 	rPrevSection.set(rNextSection);
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255