xref: /AOO41X/main/sw/source/core/unocore/unoflatpara.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <editeng/unolingu.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <unobaseclass.hxx>
30cdf0e10cSrcweir #include <unoflatpara.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vos/mutex.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <com/sun/star/text/TextMarkupType.hpp>
35cdf0e10cSrcweir #include <unotextmarkup.hxx>
36cdf0e10cSrcweir #include <ndtxt.hxx>
37cdf0e10cSrcweir #include <doc.hxx>
38cdf0e10cSrcweir #include <docsh.hxx>
39cdf0e10cSrcweir #include <viewsh.hxx>
40cdf0e10cSrcweir #include <viewimp.hxx>
41cdf0e10cSrcweir #include <breakit.hxx>
42cdf0e10cSrcweir #include <pam.hxx>
43cdf0e10cSrcweir #include <unobaseclass.hxx>
44cdf0e10cSrcweir #include <unotextrange.hxx>
45cdf0e10cSrcweir #include <pagefrm.hxx>
46cdf0e10cSrcweir #include <cntfrm.hxx>
47cdf0e10cSrcweir #include <rootfrm.hxx>
48cdf0e10cSrcweir #include <poolfmt.hxx>
49cdf0e10cSrcweir #include <pagedesc.hxx>
50cdf0e10cSrcweir #include <IGrammarContact.hxx>
51cdf0e10cSrcweir #include <viewopt.hxx>
52cdf0e10cSrcweir 
53*1ced0919SJürgen Schmidt #include <com/sun/star/lang/XUnoTunnel.hpp>
54*1ced0919SJürgen Schmidt #include <com/sun/star/text/XTextRange.hpp>
55*1ced0919SJürgen Schmidt 
56cdf0e10cSrcweir using namespace ::com::sun::star;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir /******************************************************************************
59cdf0e10cSrcweir  * SwXFlatParagraph
60cdf0e10cSrcweir  ******************************************************************************/
61cdf0e10cSrcweir 
SwXFlatParagraph(SwTxtNode & rTxtNode,rtl::OUString aExpandText,const ModelToViewHelper::ConversionMap * pMap)62cdf0e10cSrcweir SwXFlatParagraph::SwXFlatParagraph( SwTxtNode& rTxtNode, rtl::OUString aExpandText, const ModelToViewHelper::ConversionMap* pMap ) :
63cdf0e10cSrcweir     SwXTextMarkup( rTxtNode, pMap ),
64cdf0e10cSrcweir     maExpandText( aExpandText )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
~SwXFlatParagraph()68cdf0e10cSrcweir SwXFlatParagraph::~SwXFlatParagraph()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
getTypes()72cdf0e10cSrcweir uno::Sequence< uno::Type > SwXFlatParagraph::getTypes(  ) throw(uno::RuntimeException)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 	uno::Sequence< uno::Type > aTypes = SwXTextMarkup::getTypes();
75cdf0e10cSrcweir 	aTypes.realloc( aTypes.getLength() + 1 );
76cdf0e10cSrcweir     aTypes[aTypes.getLength()-1] = ::getCppuType((uno::Reference< text::XFlatParagraph >*)0);
77cdf0e10cSrcweir 	return aTypes;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
getImplementationId()80cdf0e10cSrcweir uno::Sequence< sal_Int8 > SwXFlatParagraph::getImplementationId(  ) throw(uno::RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
83cdf0e10cSrcweir     static uno::Sequence< sal_Int8 > aId( 16 );
84cdf0e10cSrcweir     static sal_Bool bInit = sal_False;
85cdf0e10cSrcweir     if(!bInit)
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
88cdf0e10cSrcweir         bInit = sal_True;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir     return aId;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)93cdf0e10cSrcweir uno::Any SAL_CALL SwXFlatParagraph::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	if ( rType == ::getCppuType((uno::Reference< text::XFlatParagraph >*)0) )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		return uno::makeAny( uno::Reference < text::XFlatParagraph >(this) );
98cdf0e10cSrcweir 	}
99cdf0e10cSrcweir 	else
100cdf0e10cSrcweir 		return SwXTextMarkup::queryInterface( rType );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
acquire()103cdf0e10cSrcweir void SAL_CALL SwXFlatParagraph::acquire() throw()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     SwXTextMarkup::acquire();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
release()108cdf0e10cSrcweir void SAL_CALL SwXFlatParagraph::release() throw()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     SwXTextMarkup::release();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
getTxtNode() const113cdf0e10cSrcweir const SwTxtNode* SwXFlatParagraph::getTxtNode() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     return mpTxtNode;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
getMarkupInfoContainer()118cdf0e10cSrcweir css::uno::Reference< css::container::XStringKeyMap > SAL_CALL SwXFlatParagraph::getMarkupInfoContainer() throw (css::uno::RuntimeException)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     return SwXTextMarkup::getMarkupInfoContainer();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
commitTextRangeMarkup(::sal_Int32 nType,const::rtl::OUString & aIdentifier,const uno::Reference<text::XTextRange> & xRange,const css::uno::Reference<css::container::XStringKeyMap> & xMarkupInfoContainer)123*1ced0919SJürgen Schmidt void SAL_CALL SwXFlatParagraph::commitTextRangeMarkup(::sal_Int32 nType, const ::rtl::OUString & aIdentifier, const uno::Reference< text::XTextRange> & xRange,
124*1ced0919SJürgen Schmidt                                                       const css::uno::Reference< css::container::XStringKeyMap > & xMarkupInfoContainer) throw (uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
127*1ced0919SJürgen Schmidt     SwXTextMarkup::commitTextRangeMarkup( nType, aIdentifier, xRange,  xMarkupInfoContainer );
128*1ced0919SJürgen Schmidt }
129*1ced0919SJürgen Schmidt 
130*1ced0919SJürgen Schmidt 
commitStringMarkup(::sal_Int32 nType,const::rtl::OUString & rIdentifier,::sal_Int32 nStart,::sal_Int32 nLength,const css::uno::Reference<css::container::XStringKeyMap> & rxMarkupInfoContainer)131*1ced0919SJürgen Schmidt void SAL_CALL SwXFlatParagraph::commitStringMarkup(::sal_Int32 nType, const ::rtl::OUString & rIdentifier, ::sal_Int32 nStart, ::sal_Int32 nLength, const css::uno::Reference< css::container::XStringKeyMap > & rxMarkupInfoContainer) throw (css::uno::RuntimeException)
132*1ced0919SJürgen Schmidt {
133*1ced0919SJürgen Schmidt     vos::OGuard aGuard(Application::GetSolarMutex());
134*1ced0919SJürgen Schmidt     SwXTextMarkup::commitStringMarkup( nType, rIdentifier, nStart, nLength,  rxMarkupInfoContainer );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir // text::XFlatParagraph:
getText()138cdf0e10cSrcweir ::rtl::OUString SAL_CALL SwXFlatParagraph::getText() throw (uno::RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     return maExpandText;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // text::XFlatParagraph:
setChecked(::sal_Int32 nType,::sal_Bool bVal)144cdf0e10cSrcweir void SAL_CALL SwXFlatParagraph::setChecked( ::sal_Int32 nType, ::sal_Bool bVal ) throw (uno::RuntimeException)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     if ( mpTxtNode )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         if ( text::TextMarkupType::SPELLCHECK == nType )
151cdf0e10cSrcweir             mpTxtNode->SetWrongDirty( !bVal );
152cdf0e10cSrcweir         else if ( text::TextMarkupType::SMARTTAG == nType )
153cdf0e10cSrcweir             mpTxtNode->SetSmartTagDirty( !bVal );
154cdf0e10cSrcweir         else if( text::TextMarkupType::PROOFREADING == nType )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             mpTxtNode->SetGrammarCheckDirty( !bVal );
157cdf0e10cSrcweir             if( bVal )
158cdf0e10cSrcweir                 ::finishGrammarCheck( *mpTxtNode );
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir // text::XFlatParagraph:
isChecked(::sal_Int32 nType)164cdf0e10cSrcweir ::sal_Bool SAL_CALL SwXFlatParagraph::isChecked( ::sal_Int32 nType ) throw (uno::RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
167cdf0e10cSrcweir     if ( mpTxtNode )
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         if ( text::TextMarkupType::SPELLCHECK == nType )
170cdf0e10cSrcweir             return mpTxtNode->IsWrongDirty();
171cdf0e10cSrcweir         else if ( text::TextMarkupType::PROOFREADING == nType )
172cdf0e10cSrcweir             return mpTxtNode->IsGrammarCheckDirty();
173cdf0e10cSrcweir         else if ( text::TextMarkupType::SMARTTAG == nType )
174cdf0e10cSrcweir             return mpTxtNode->IsSmartTagDirty();
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     return sal_False;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir // text::XFlatParagraph:
isModified()181cdf0e10cSrcweir ::sal_Bool SAL_CALL SwXFlatParagraph::isModified() throw (uno::RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
184cdf0e10cSrcweir     return 0 == mpTxtNode;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // text::XFlatParagraph:
getLanguageOfText(::sal_Int32 nPos,::sal_Int32 nLen)188cdf0e10cSrcweir lang::Locale SAL_CALL SwXFlatParagraph::getLanguageOfText(::sal_Int32 nPos, ::sal_Int32 nLen)
189cdf0e10cSrcweir 	throw (uno::RuntimeException, lang::IllegalArgumentException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
192cdf0e10cSrcweir     if (!mpTxtNode)
193cdf0e10cSrcweir         return SvxCreateLocale( LANGUAGE_NONE );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     const lang::Locale aLocale( SW_BREAKITER()->GetLocale( mpTxtNode->GetLang( static_cast<sal_uInt16>(nPos), static_cast<sal_uInt16>(nLen) ) ) );
196cdf0e10cSrcweir     return aLocale;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // text::XFlatParagraph:
getPrimaryLanguageOfText(::sal_Int32 nPos,::sal_Int32 nLen)200cdf0e10cSrcweir lang::Locale SAL_CALL SwXFlatParagraph::getPrimaryLanguageOfText(::sal_Int32 nPos, ::sal_Int32 nLen)
201cdf0e10cSrcweir 	throw (uno::RuntimeException, lang::IllegalArgumentException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     if (!mpTxtNode)
206cdf0e10cSrcweir         return SvxCreateLocale( LANGUAGE_NONE );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     const lang::Locale aLocale( SW_BREAKITER()->GetLocale( mpTxtNode->GetLang( static_cast<sal_uInt16>(nPos), static_cast<sal_uInt16>(nLen) ) ) );
209cdf0e10cSrcweir     return aLocale;
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir // text::XFlatParagraph:
changeText(::sal_Int32 nPos,::sal_Int32 nLen,const::rtl::OUString & aNewText,const css::uno::Sequence<css::beans::PropertyValue> & aAttributes)213cdf0e10cSrcweir void SAL_CALL SwXFlatParagraph::changeText(::sal_Int32 nPos, ::sal_Int32 nLen, const ::rtl::OUString & aNewText, const css::uno::Sequence< css::beans::PropertyValue > & aAttributes) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     if ( !mpTxtNode )
218cdf0e10cSrcweir         return;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     SwTxtNode* pOldTxtNode = mpTxtNode;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     SwPaM aPaM( *mpTxtNode, static_cast<sal_uInt16>(nPos), *mpTxtNode, static_cast<sal_uInt16>(nPos + nLen) );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     UnoActionContext aAction( mpTxtNode->GetDoc() );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     const uno::Reference< text::XTextRange > xRange =
227cdf0e10cSrcweir         SwXTextRange::CreateXTextRange(
228cdf0e10cSrcweir             *mpTxtNode->GetDoc(), *aPaM.GetPoint(), aPaM.GetMark() );
229cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY );
230cdf0e10cSrcweir     if ( xPropSet.is() )
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < aAttributes.getLength(); ++i )
233cdf0e10cSrcweir             xPropSet->setPropertyValue( aAttributes[i].Name, aAttributes[i].Value );
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     mpTxtNode = pOldTxtNode; // setPropertyValue() modifies this. We restore the old state.
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     IDocumentContentOperations* pIDCO = mpTxtNode->getIDocumentContentOperations();
239cdf0e10cSrcweir     pIDCO->ReplaceRange( aPaM, aNewText, false );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     mpTxtNode = 0;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir // text::XFlatParagraph:
changeAttributes(::sal_Int32 nPos,::sal_Int32 nLen,const css::uno::Sequence<css::beans::PropertyValue> & aAttributes)245cdf0e10cSrcweir void SAL_CALL SwXFlatParagraph::changeAttributes(::sal_Int32 nPos, ::sal_Int32 nLen, const css::uno::Sequence< css::beans::PropertyValue > & aAttributes) throw (css::uno::RuntimeException, css::lang::IllegalArgumentException)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     if ( !mpTxtNode )
250cdf0e10cSrcweir         return;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     SwPaM aPaM( *mpTxtNode, static_cast<sal_uInt16>(nPos), *mpTxtNode, static_cast<sal_uInt16>(nPos + nLen) );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     UnoActionContext aAction( mpTxtNode->GetDoc() );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     const uno::Reference< text::XTextRange > xRange =
257cdf0e10cSrcweir         SwXTextRange::CreateXTextRange(
258cdf0e10cSrcweir             *mpTxtNode->GetDoc(), *aPaM.GetPoint(), aPaM.GetMark() );
259cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xPropSet( xRange, uno::UNO_QUERY );
260cdf0e10cSrcweir     if ( xPropSet.is() )
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         for ( sal_uInt16 i = 0; i < aAttributes.getLength(); ++i )
263cdf0e10cSrcweir             xPropSet->setPropertyValue( aAttributes[i].Name, aAttributes[i].Value );
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     mpTxtNode = 0;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir // text::XFlatParagraph:
getLanguagePortions()270cdf0e10cSrcweir css::uno::Sequence< ::sal_Int32 > SAL_CALL SwXFlatParagraph::getLanguagePortions() throw (css::uno::RuntimeException)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
273cdf0e10cSrcweir     return css::uno::Sequence< ::sal_Int32>();
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 
277cdf0e10cSrcweir const uno::Sequence< sal_Int8 >&
getUnoTunnelId()278cdf0e10cSrcweir SwXFlatParagraph::getUnoTunnelId()
279cdf0e10cSrcweir {
280cdf0e10cSrcweir     static uno::Sequence<sal_Int8> aSeq(CreateUnoTunnelId());
281cdf0e10cSrcweir     return aSeq;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 
285cdf0e10cSrcweir sal_Int64 SAL_CALL
getSomething(const uno::Sequence<sal_Int8> & rId)286cdf0e10cSrcweir SwXFlatParagraph::getSomething(
287cdf0e10cSrcweir         const uno::Sequence< sal_Int8 >& rId)
288cdf0e10cSrcweir     throw (uno::RuntimeException)
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     return sw::UnoTunnelImpl(rId, this);
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 
294cdf0e10cSrcweir /******************************************************************************
295cdf0e10cSrcweir  * SwXFlatParagraphIterator
296cdf0e10cSrcweir  ******************************************************************************/
297cdf0e10cSrcweir 
SwXFlatParagraphIterator(SwDoc & rDoc,sal_Int32 nType,sal_Bool bAutomatic)298cdf0e10cSrcweir SwXFlatParagraphIterator::SwXFlatParagraphIterator( SwDoc& rDoc, sal_Int32 nType, sal_Bool bAutomatic )
299cdf0e10cSrcweir     : mpDoc( &rDoc ),
300cdf0e10cSrcweir       mnType( nType ),
301cdf0e10cSrcweir       mbAutomatic( bAutomatic ),
302cdf0e10cSrcweir       mnCurrentNode( 0 ),
303cdf0e10cSrcweir       mnStartNode( 0 ),
304cdf0e10cSrcweir       mnEndNode( rDoc.GetNodes().Count() ),
305cdf0e10cSrcweir       mbWrapped( sal_False )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     //mnStartNode = mnCurrentNode = get node from current cursor TODO!
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     // register as listener and get notified when document is closed
310cdf0e10cSrcweir     mpDoc->GetPageDescFromPool( RES_POOLPAGE_STANDARD )->Add(this);
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
~SwXFlatParagraphIterator()313cdf0e10cSrcweir SwXFlatParagraphIterator::~SwXFlatParagraphIterator()
314cdf0e10cSrcweir {
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)318cdf0e10cSrcweir void SwXFlatParagraphIterator::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir     ClientModify( this, pOld, pNew );
321cdf0e10cSrcweir     // check if document gets closed...
322cdf0e10cSrcweir     if(!GetRegisteredIn())
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         vos::OGuard aGuard(Application::GetSolarMutex());
325cdf0e10cSrcweir         mpDoc = 0;
326cdf0e10cSrcweir     }
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 
getFirstPara()330cdf0e10cSrcweir uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getFirstPara()
331cdf0e10cSrcweir 	throw( uno::RuntimeException )
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     return getNextPara();   // TODO
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
getNextPara()336cdf0e10cSrcweir uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getNextPara()
337cdf0e10cSrcweir 	throw( uno::RuntimeException )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     uno::Reference< text::XFlatParagraph > xRet;
342cdf0e10cSrcweir     if (!mpDoc)
343cdf0e10cSrcweir         return xRet;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     SwTxtNode* pRet = 0;
346cdf0e10cSrcweir     if ( mbAutomatic )
347cdf0e10cSrcweir     {
348cdf0e10cSrcweir         ViewShell* pViewShell = 0;
349cdf0e10cSrcweir         mpDoc->GetEditShell( &pViewShell );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         SwPageFrm* pCurrentPage = pViewShell ? pViewShell->Imp()->GetFirstVisPage() : 0;
352cdf0e10cSrcweir         SwPageFrm* pStartPage = pCurrentPage;
353cdf0e10cSrcweir         SwPageFrm* pStopPage = 0;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         while ( pCurrentPage != pStopPage )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             if (mnType != text::TextMarkupType::SPELLCHECK || pCurrentPage->IsInvalidSpelling() )
358cdf0e10cSrcweir             {
359cdf0e10cSrcweir 				// this method is supposed to return an empty paragraph in case Online Checking is disabled
360cdf0e10cSrcweir 				if ( ( mnType == text::TextMarkupType::PROOFREADING || mnType == text::TextMarkupType::SPELLCHECK )
361cdf0e10cSrcweir 					&& !pViewShell->GetViewOptions()->IsOnlineSpell() )
362cdf0e10cSrcweir 					return xRet;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir                 // search for invalid content:
365cdf0e10cSrcweir                 SwCntntFrm* pCnt = pCurrentPage->ContainsCntnt();
366cdf0e10cSrcweir 
367cdf0e10cSrcweir                 while( pCnt && pCurrentPage->IsAnLower( pCnt ) )
368cdf0e10cSrcweir                 {
369cdf0e10cSrcweir                     SwTxtNode* pTxtNode = dynamic_cast<SwTxtNode*>( pCnt->GetNode()->GetTxtNode() );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir                     if ( pTxtNode &&
372cdf0e10cSrcweir                         ((mnType == text::TextMarkupType::SPELLCHECK &&
373cdf0e10cSrcweir                                 pTxtNode->IsWrongDirty()) ||
374cdf0e10cSrcweir                          (mnType == text::TextMarkupType::PROOFREADING &&
375cdf0e10cSrcweir                                 pTxtNode->IsGrammarCheckDirty())) )
376cdf0e10cSrcweir                     {
377cdf0e10cSrcweir                         pRet = pTxtNode;
378cdf0e10cSrcweir                         break;
379cdf0e10cSrcweir                     }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir                     pCnt = pCnt->GetNextCntntFrm();
382cdf0e10cSrcweir                 }
383cdf0e10cSrcweir             }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir             if ( pRet )
386cdf0e10cSrcweir                 break;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir             // if there is no invalid text node on the current page,
389cdf0e10cSrcweir             // we validate the page
390cdf0e10cSrcweir             pCurrentPage->ValidateSpelling();
391cdf0e10cSrcweir 
392cdf0e10cSrcweir             // proceed with next page, wrap at end of document if required:
393cdf0e10cSrcweir             pCurrentPage = static_cast<SwPageFrm*>(pCurrentPage->GetNext());
394cdf0e10cSrcweir 
395cdf0e10cSrcweir             if ( !pCurrentPage && !pStopPage )
396cdf0e10cSrcweir             {
397cdf0e10cSrcweir                 pStopPage = pStartPage;
398cdf0e10cSrcweir                 pCurrentPage = static_cast<SwPageFrm*>(pViewShell->GetLayout()->Lower());
399cdf0e10cSrcweir             }
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir     }
402cdf0e10cSrcweir     else    // non-automatic checking
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         const SwNodes& rNodes = mpDoc->GetNodes();
405cdf0e10cSrcweir         const sal_uLong nMaxNodes = rNodes.Count();
406cdf0e10cSrcweir 
407cdf0e10cSrcweir         while ( mnCurrentNode < mnEndNode && mnCurrentNode < nMaxNodes )
408cdf0e10cSrcweir         {
409cdf0e10cSrcweir             SwNode* pNd = rNodes[ mnCurrentNode ];
410cdf0e10cSrcweir 
411cdf0e10cSrcweir             ++mnCurrentNode;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir             pRet = dynamic_cast<SwTxtNode*>(pNd);
414cdf0e10cSrcweir             if ( pRet )
415cdf0e10cSrcweir                 break;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir             if ( mnCurrentNode == mnEndNode && !mbWrapped )
418cdf0e10cSrcweir             {
419cdf0e10cSrcweir                 mnCurrentNode = 0;
420cdf0e10cSrcweir                 mnEndNode = mnStartNode;
421cdf0e10cSrcweir             }
422cdf0e10cSrcweir         }
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     if ( pRet )
426cdf0e10cSrcweir     {
427cdf0e10cSrcweir         // Expand the string:
428cdf0e10cSrcweir         rtl::OUString aExpandText;
429cdf0e10cSrcweir         const ModelToViewHelper::ConversionMap* pConversionMap =
430cdf0e10cSrcweir                 pRet->BuildConversionMap( aExpandText );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         xRet = new SwXFlatParagraph( *pRet, aExpandText, pConversionMap );
433cdf0e10cSrcweir 		// keep hard references...
434cdf0e10cSrcweir 		m_aFlatParaList.insert( xRet );
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 	return xRet;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
getLastPara()440cdf0e10cSrcweir uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getLastPara()
441cdf0e10cSrcweir 	throw( uno::RuntimeException )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     return getNextPara();
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
getParaAfter(const uno::Reference<text::XFlatParagraph> & xPara)446cdf0e10cSrcweir uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaAfter(const uno::Reference< text::XFlatParagraph > & xPara)
447cdf0e10cSrcweir 	throw ( uno::RuntimeException, lang::IllegalArgumentException )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     uno::Reference< text::XFlatParagraph > xRet;
452cdf0e10cSrcweir     if (!mpDoc)
453cdf0e10cSrcweir         return xRet;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     const uno::Reference<lang::XUnoTunnel> xFPTunnel(xPara, uno::UNO_QUERY);
456cdf0e10cSrcweir     OSL_ASSERT(xFPTunnel.is());
457cdf0e10cSrcweir     SwXFlatParagraph* const pFlatParagraph(sw::UnoTunnelGetImplementation<SwXFlatParagraph>(xFPTunnel));
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     if ( !pFlatParagraph )
460cdf0e10cSrcweir         return xRet;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     const SwTxtNode* pCurrentNode = pFlatParagraph->getTxtNode();
463cdf0e10cSrcweir 
464cdf0e10cSrcweir     if ( !pCurrentNode )
465cdf0e10cSrcweir         return xRet;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     SwTxtNode* pNextTxtNode = 0;
468cdf0e10cSrcweir     const SwNodes& rNodes = pCurrentNode->GetDoc()->GetNodes();
469cdf0e10cSrcweir 
470cdf0e10cSrcweir     for( sal_uLong nCurrentNode = pCurrentNode->GetIndex() + 1; nCurrentNode < rNodes.Count(); ++nCurrentNode )
471cdf0e10cSrcweir     {
472cdf0e10cSrcweir         SwNode* pNd = rNodes[ nCurrentNode ];
473cdf0e10cSrcweir         pNextTxtNode = dynamic_cast<SwTxtNode*>(pNd);
474cdf0e10cSrcweir         if ( pNextTxtNode )
475cdf0e10cSrcweir             break;
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     if ( pNextTxtNode )
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         // Expand the string:
481cdf0e10cSrcweir         rtl::OUString aExpandText;
482cdf0e10cSrcweir         const ModelToViewHelper::ConversionMap* pConversionMap =
483cdf0e10cSrcweir                 pNextTxtNode->BuildConversionMap( aExpandText );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir         xRet = new SwXFlatParagraph( *pNextTxtNode, aExpandText, pConversionMap );
486cdf0e10cSrcweir 		// keep hard references...
487cdf0e10cSrcweir 		m_aFlatParaList.insert( xRet );
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     return xRet;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
getParaBefore(const uno::Reference<text::XFlatParagraph> & xPara)493cdf0e10cSrcweir uno::Reference< text::XFlatParagraph > SwXFlatParagraphIterator::getParaBefore(const uno::Reference< text::XFlatParagraph > & xPara )
494cdf0e10cSrcweir 	throw ( uno::RuntimeException, lang::IllegalArgumentException )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
497cdf0e10cSrcweir 
498cdf0e10cSrcweir     uno::Reference< text::XFlatParagraph > xRet;
499cdf0e10cSrcweir     if (!mpDoc)
500cdf0e10cSrcweir         return xRet;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     const uno::Reference<lang::XUnoTunnel> xFPTunnel(xPara, uno::UNO_QUERY);
503cdf0e10cSrcweir     OSL_ASSERT(xFPTunnel.is());
504cdf0e10cSrcweir     SwXFlatParagraph* const pFlatParagraph(sw::UnoTunnelGetImplementation<SwXFlatParagraph>(xFPTunnel));
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     if ( !pFlatParagraph )
507cdf0e10cSrcweir         return xRet;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     const SwTxtNode* pCurrentNode = pFlatParagraph->getTxtNode();
510cdf0e10cSrcweir 
511cdf0e10cSrcweir     if ( !pCurrentNode )
512cdf0e10cSrcweir         return xRet;
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     SwTxtNode* pPrevTxtNode = 0;
515cdf0e10cSrcweir     const SwNodes& rNodes = pCurrentNode->GetDoc()->GetNodes();
516cdf0e10cSrcweir 
517cdf0e10cSrcweir     for( sal_uLong nCurrentNode = pCurrentNode->GetIndex() - 1; nCurrentNode > 0; --nCurrentNode )
518cdf0e10cSrcweir     {
519cdf0e10cSrcweir         SwNode* pNd = rNodes[ nCurrentNode ];
520cdf0e10cSrcweir         pPrevTxtNode = dynamic_cast<SwTxtNode*>(pNd);
521cdf0e10cSrcweir         if ( pPrevTxtNode )
522cdf0e10cSrcweir             break;
523cdf0e10cSrcweir     }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir     if ( pPrevTxtNode )
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         // Expand the string:
528cdf0e10cSrcweir         rtl::OUString aExpandText;
529cdf0e10cSrcweir         const ModelToViewHelper::ConversionMap* pConversionMap =
530cdf0e10cSrcweir                 pPrevTxtNode->BuildConversionMap( aExpandText );
531cdf0e10cSrcweir 
532cdf0e10cSrcweir         xRet = new SwXFlatParagraph( *pPrevTxtNode, aExpandText, pConversionMap );
533cdf0e10cSrcweir 		// keep hard references...
534cdf0e10cSrcweir 		m_aFlatParaList.insert( xRet );
535cdf0e10cSrcweir     }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     return xRet;
538cdf0e10cSrcweir }
539