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