xref: /AOO41X/main/sw/source/core/unocore/unoobj2.cxx (revision 37fb9221eef9e50dc318823cbb70195f6d414c56)
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 <rtl/ustrbuf.hxx>
28cdf0e10cSrcweir #include <swtypes.hxx>
29cdf0e10cSrcweir #include <hintids.hxx>
30cdf0e10cSrcweir #include <cmdid.h>
31cdf0e10cSrcweir #include <hints.hxx>
32cdf0e10cSrcweir #include <IMark.hxx>
33cdf0e10cSrcweir #include <bookmrk.hxx>
34cdf0e10cSrcweir #include <frmfmt.hxx>
35cdf0e10cSrcweir #include <doc.hxx>
36cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
37cdf0e10cSrcweir #include <ndtxt.hxx>
38cdf0e10cSrcweir #include <ndnotxt.hxx>
39cdf0e10cSrcweir #include <unocrsr.hxx>
40cdf0e10cSrcweir #include <swundo.hxx>
41cdf0e10cSrcweir #include <rootfrm.hxx>
42cdf0e10cSrcweir #include <flyfrm.hxx>
43cdf0e10cSrcweir #include <ftnidx.hxx>
44cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
45cdf0e10cSrcweir #include <docary.hxx>
46cdf0e10cSrcweir #include <paratr.hxx>
47cdf0e10cSrcweir #include <tools/urlobj.hxx>
48cdf0e10cSrcweir #include <pam.hxx>
49cdf0e10cSrcweir #include <tools/cachestr.hxx>
50cdf0e10cSrcweir #include <shellio.hxx>
51cdf0e10cSrcweir #include <swerror.h>
52cdf0e10cSrcweir #include <swtblfmt.hxx>
53cdf0e10cSrcweir #include <docsh.hxx>
54cdf0e10cSrcweir #include <docstyle.hxx>
55cdf0e10cSrcweir #include <charfmt.hxx>
56cdf0e10cSrcweir #include <txtfld.hxx>
57cdf0e10cSrcweir #include <fmtfld.hxx>
58cdf0e10cSrcweir #include <fmtpdsc.hxx>
59cdf0e10cSrcweir #include <pagedesc.hxx>
60cdf0e10cSrcweir #include <poolfmt.hrc>
61cdf0e10cSrcweir #include <poolfmt.hxx>
62cdf0e10cSrcweir #include <edimp.hxx>
63cdf0e10cSrcweir #include <fchrfmt.hxx>
64cdf0e10cSrcweir #include <cntfrm.hxx>
65cdf0e10cSrcweir #include <pagefrm.hxx>
66cdf0e10cSrcweir #include <doctxm.hxx>
67cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
68cdf0e10cSrcweir #include <sfx2/docfile.hxx>
69cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
70cdf0e10cSrcweir #include <fmtrfmrk.hxx>
71cdf0e10cSrcweir #include <txtrfmrk.hxx>
72cdf0e10cSrcweir #include <unoparaframeenum.hxx>
73cdf0e10cSrcweir #include <unofootnote.hxx>
74cdf0e10cSrcweir #include <unotextbodyhf.hxx>
75cdf0e10cSrcweir #include <unotextrange.hxx>
76cdf0e10cSrcweir #include <unoparagraph.hxx>
77cdf0e10cSrcweir #include <unomap.hxx>
78cdf0e10cSrcweir #include <unoport.hxx>
79cdf0e10cSrcweir #include <unocrsrhelper.hxx>
80cdf0e10cSrcweir #include <unosett.hxx>
81cdf0e10cSrcweir #include <unoprnms.hxx>
82cdf0e10cSrcweir #include <unotbl.hxx>
83cdf0e10cSrcweir #include <unodraw.hxx>
84cdf0e10cSrcweir #include <unocoll.hxx>
85cdf0e10cSrcweir #include <unostyle.hxx>
86cdf0e10cSrcweir #include <unofield.hxx>
87cdf0e10cSrcweir #include <fmtanchr.hxx>
88cdf0e10cSrcweir #include <editeng/flstitem.hxx>
89cdf0e10cSrcweir #include <editeng/unolingu.hxx>
90cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
91cdf0e10cSrcweir #include <flypos.hxx>
92cdf0e10cSrcweir #include <txtftn.hxx>
93cdf0e10cSrcweir #include <fmtftn.hxx>
94cdf0e10cSrcweir #include <fmtcntnt.hxx>
95cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp>
96cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
97cdf0e10cSrcweir #include <com/sun/star/style/PageStyleLayout.hpp>
98cdf0e10cSrcweir #include <com/sun/star/text/XTextDocument.hpp>
99cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
100cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
101cdf0e10cSrcweir #include <unoidx.hxx>
102cdf0e10cSrcweir #include <unoframe.hxx>
103cdf0e10cSrcweir #include <fmthdft.hxx>
104cdf0e10cSrcweir #include <vos/mutex.hxx>
105cdf0e10cSrcweir #include <vcl/svapp.hxx>
106cdf0e10cSrcweir #include <fmtflcnt.hxx>
107cdf0e10cSrcweir #define _SVSTDARR_USHORTS
108cdf0e10cSrcweir #define _SVSTDARR_USHORTSSORT
109cdf0e10cSrcweir #define _SVSTDARR_XUB_STRLEN
110cdf0e10cSrcweir #include <svl/svstdarr.hxx>
111cdf0e10cSrcweir #include <editeng/brshitem.hxx>
112cdf0e10cSrcweir #include <fmtclds.hxx>
113cdf0e10cSrcweir #include <dcontact.hxx>
114cdf0e10cSrcweir #include <dflyobj.hxx>
115cdf0e10cSrcweir #include <crsskip.hxx>
116cdf0e10cSrcweir #include <vector>
117cdf0e10cSrcweir #include <sortedobjs.hxx>
118cdf0e10cSrcweir #include <sortopt.hxx>
119cdf0e10cSrcweir #include <algorithm>
120cdf0e10cSrcweir #include <iterator>
121cdf0e10cSrcweir #include <boost/bind.hpp>
122cdf0e10cSrcweir #include <switerator.hxx>
123cdf0e10cSrcweir 
124cdf0e10cSrcweir using namespace ::com::sun::star;
125cdf0e10cSrcweir using ::rtl::OUString;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir namespace sw {
129cdf0e10cSrcweir 
SupportsServiceImpl(size_t const nServices,char const * const pServices[],::rtl::OUString const & rServiceName)130cdf0e10cSrcweir sal_Bool SupportsServiceImpl(
131cdf0e10cSrcweir         size_t const nServices, char const*const pServices[],
132cdf0e10cSrcweir         ::rtl::OUString const & rServiceName)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     for (size_t i = 0; i < nServices; ++i)
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         if (rServiceName.equalsAscii(pServices[i]))
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             return sal_True;
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir     return sal_False;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir uno::Sequence< ::rtl::OUString >
GetSupportedServiceNamesImpl(size_t const nServices,char const * const pServices[])145cdf0e10cSrcweir GetSupportedServiceNamesImpl(
146cdf0e10cSrcweir         size_t const nServices, char const*const pServices[])
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > ret(nServices);
149cdf0e10cSrcweir     for (size_t i = 0; i < nServices; ++i)
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         ret[i] = C2U(pServices[i]);
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     return ret;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir } // namespace sw
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir namespace sw {
160cdf0e10cSrcweir 
DeepCopyPaM(SwPaM const & rSource,SwPaM & rTarget)161cdf0e10cSrcweir void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     rTarget = rSource;
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     if (rSource.GetNext() != &rSource)
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         SwPaM *pPam = static_cast<SwPaM *>(rSource.GetNext());
168cdf0e10cSrcweir         do
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             // create new PaM
171cdf0e10cSrcweir             SwPaM *const pNew = new SwPaM(*pPam);
172cdf0e10cSrcweir             // insert into ring
173cdf0e10cSrcweir             pNew->MoveTo(&rTarget);
174cdf0e10cSrcweir             pPam = static_cast<SwPaM *>(pPam->GetNext());
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         while (pPam != &rSource);
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir } // namespace sw
181cdf0e10cSrcweir 
182cdf0e10cSrcweir struct FrameDependSortListLess
183cdf0e10cSrcweir {
operator ()FrameDependSortListLess184cdf0e10cSrcweir     bool operator() (FrameDependSortListEntry const& r1,
185cdf0e10cSrcweir                      FrameDependSortListEntry const& r2)
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         return  (r1.nIndex <  r2.nIndex)
188cdf0e10cSrcweir             || ((r1.nIndex == r2.nIndex) && (r1.nOrder < r2.nOrder));
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir };
191cdf0e10cSrcweir 
192cdf0e10cSrcweir // OD 2004-05-07 #i28701# - adjust 4th parameter
CollectFrameAtNode(SwClient & rClnt,const SwNodeIndex & rIdx,FrameDependSortList_t & rFrames,const bool _bAtCharAnchoredObjs)193cdf0e10cSrcweir void CollectFrameAtNode( SwClient& rClnt, const SwNodeIndex& rIdx,
194cdf0e10cSrcweir                          FrameDependSortList_t & rFrames,
195cdf0e10cSrcweir                          const bool _bAtCharAnchoredObjs )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     // _bAtCharAnchoredObjs:
198cdf0e10cSrcweir     // <sal_True>: at-character anchored objects are collected
199cdf0e10cSrcweir     // <sal_False>: at-paragraph anchored objects are collected
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	// alle Rahmen, Grafiken und OLEs suchen, die an diesem Absatz
202cdf0e10cSrcweir 	// gebunden sind
203cdf0e10cSrcweir 	SwDoc* pDoc = rIdx.GetNode().GetDoc();
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     sal_uInt16 nChkType = static_cast< sal_uInt16 >((_bAtCharAnchoredObjs)
206cdf0e10cSrcweir             ? FLY_AT_CHAR : FLY_AT_PARA);
207cdf0e10cSrcweir 	const SwCntntFrm* pCFrm;
208cdf0e10cSrcweir 	const SwCntntNode* pCNd;
209cdf0e10cSrcweir     if( pDoc->GetCurrentViewShell() &&	//swmod 071108//swmod 071225
210cdf0e10cSrcweir         0 != (pCNd = rIdx.GetNode().GetCntntNode()) &&
211cdf0e10cSrcweir 		0 != (pCFrm = pCNd->getLayoutFrm( pDoc->GetCurrentLayout())) )
212cdf0e10cSrcweir 	{
213cdf0e10cSrcweir         const SwSortedObjs *pObjs = pCFrm->GetDrawObjs();
214cdf0e10cSrcweir 		if( pObjs )
215cdf0e10cSrcweir 			for( sal_uInt16 i = 0; i < pObjs->Count(); ++i )
216cdf0e10cSrcweir 			{
217cdf0e10cSrcweir                 SwAnchoredObject* pAnchoredObj = (*pObjs)[i];
218cdf0e10cSrcweir                 SwFrmFmt& rFmt = pAnchoredObj->GetFrmFmt();
219cdf0e10cSrcweir                 if ( rFmt.GetAnchor().GetAnchorId() == nChkType )
220cdf0e10cSrcweir                 {
221cdf0e10cSrcweir                     // create SwDepend and insert into array
222cdf0e10cSrcweir                     SwDepend* pNewDepend = new SwDepend( &rClnt, &rFmt );
223cdf0e10cSrcweir                     xub_StrLen idx =
224cdf0e10cSrcweir                         rFmt.GetAnchor().GetCntntAnchor()->nContent.GetIndex();
225cdf0e10cSrcweir                     sal_uInt32 nOrder = rFmt.GetAnchor().GetOrder();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir                     // OD 2004-05-07 #i28701# - sorting no longer needed,
228cdf0e10cSrcweir                     // because list <SwSortedObjs> is already sorted.
229cdf0e10cSrcweir                     FrameDependSortListEntry entry(idx, nOrder, pNewDepend);
230cdf0e10cSrcweir                     rFrames.push_back(entry);
231cdf0e10cSrcweir                 }
232cdf0e10cSrcweir             }
233cdf0e10cSrcweir 	}
234cdf0e10cSrcweir 	else
235cdf0e10cSrcweir 	{
236cdf0e10cSrcweir         const SwSpzFrmFmts& rFmts = *pDoc->GetSpzFrmFmts();
237cdf0e10cSrcweir 		sal_uInt16 nSize = rFmts.Count();
238cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nSize; i++)
239cdf0e10cSrcweir 		{
240cdf0e10cSrcweir 			const SwFrmFmt* pFmt = rFmts[ i ];
241cdf0e10cSrcweir 			const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
242cdf0e10cSrcweir 			const SwPosition* pAnchorPos;
243cdf0e10cSrcweir 			if( rAnchor.GetAnchorId() == nChkType &&
244cdf0e10cSrcweir 				0 != (pAnchorPos = rAnchor.GetCntntAnchor()) &&
245cdf0e10cSrcweir 					pAnchorPos->nNode == rIdx )
246cdf0e10cSrcweir 			{
247cdf0e10cSrcweir 				//jetzt einen SwDepend anlegen und in das Array einfuegen
248cdf0e10cSrcweir 				SwDepend* pNewDepend = new SwDepend( &rClnt, (SwFrmFmt*)pFmt);
249cdf0e10cSrcweir 
250cdf0e10cSrcweir                 // OD 2004-05-07 #i28701# - determine insert position for
251cdf0e10cSrcweir                 // sorted <rFrameArr>
252cdf0e10cSrcweir                 xub_StrLen nIndex = pAnchorPos->nContent.GetIndex();
253cdf0e10cSrcweir                 sal_uInt32 nOrder = rAnchor.GetOrder();
254cdf0e10cSrcweir 
255cdf0e10cSrcweir                 FrameDependSortListEntry entry(nIndex, nOrder, pNewDepend);
256cdf0e10cSrcweir                 rFrames.push_back(entry);
257cdf0e10cSrcweir             }
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         ::std::sort(rFrames.begin(), rFrames.end(), FrameDependSortListLess());
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir /****************************************************************************
264cdf0e10cSrcweir 	ActionContext
265cdf0e10cSrcweir ****************************************************************************/
UnoActionContext(SwDoc * const pDoc)266cdf0e10cSrcweir UnoActionContext::UnoActionContext(SwDoc *const pDoc)
267cdf0e10cSrcweir     : m_pDoc(pDoc)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     SwRootFrm *const pRootFrm = m_pDoc->GetCurrentLayout();
270cdf0e10cSrcweir     if (pRootFrm)
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         pRootFrm->StartAllAction();
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
~UnoActionContext()276cdf0e10cSrcweir UnoActionContext::~UnoActionContext()
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     // Doc may already have been removed here
279cdf0e10cSrcweir     if (m_pDoc)
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         SwRootFrm *const pRootFrm = m_pDoc->GetCurrentLayout();
282cdf0e10cSrcweir         if (pRootFrm)
283cdf0e10cSrcweir         {
284cdf0e10cSrcweir             pRootFrm->EndAllAction();
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir     }
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir /****************************************************************************
290cdf0e10cSrcweir     ActionRemoveContext
291cdf0e10cSrcweir ****************************************************************************/
UnoActionRemoveContext(SwDoc * const pDoc)292cdf0e10cSrcweir UnoActionRemoveContext::UnoActionRemoveContext(SwDoc *const pDoc)
293cdf0e10cSrcweir     : m_pDoc(pDoc)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir     SwRootFrm *const pRootFrm = m_pDoc->GetCurrentLayout();
296cdf0e10cSrcweir     if (pRootFrm)
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         pRootFrm->UnoRemoveAllActions();
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir /* -----------------07.07.98 12:05-------------------
303cdf0e10cSrcweir  *
304cdf0e10cSrcweir  * --------------------------------------------------*/
~UnoActionRemoveContext()305cdf0e10cSrcweir UnoActionRemoveContext::~UnoActionRemoveContext()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     SwRootFrm *const pRootFrm = m_pDoc->GetCurrentLayout();
308cdf0e10cSrcweir     if (pRootFrm)
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         pRootFrm->UnoRestoreAllActions();
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 
ClientModify(SwClient * pClient,const SfxPoolItem * pOld,const SfxPoolItem * pNew)315cdf0e10cSrcweir void ClientModify(SwClient* pClient, const SfxPoolItem *pOld, const SfxPoolItem *pNew)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	switch( pOld ? pOld->Which() : 0 )
318cdf0e10cSrcweir 	{
319cdf0e10cSrcweir 	case RES_REMOVE_UNO_OBJECT:
320cdf0e10cSrcweir 	case RES_OBJECTDYING:
321cdf0e10cSrcweir 		if( (void*)pClient->GetRegisteredIn() == ((SwPtrMsgPoolItem *)pOld)->pObject )
322cdf0e10cSrcweir 			((SwModify*)pClient->GetRegisteredIn())->Remove(pClient);
323cdf0e10cSrcweir 		break;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	case RES_FMT_CHG:
326cdf0e10cSrcweir 		// wurden wir an das neue umgehaengt und wird das alte geloscht?
327cdf0e10cSrcweir 		if( ((SwFmtChg*)pNew)->pChangedFmt == pClient->GetRegisteredIn() &&
328cdf0e10cSrcweir 			((SwFmtChg*)pOld)->pChangedFmt->IsFmtInDTOR() )
329cdf0e10cSrcweir 			((SwModify*)pClient->GetRegisteredIn())->Remove(pClient);
330cdf0e10cSrcweir 		break;
331cdf0e10cSrcweir 	}
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 
SetCrsrAttr(SwPaM & rPam,const SfxItemSet & rSet,const SetAttrMode nAttrMode,const bool bTableMode)335cdf0e10cSrcweir void SwUnoCursorHelper::SetCrsrAttr(SwPaM & rPam,
336cdf0e10cSrcweir         const SfxItemSet& rSet,
337cdf0e10cSrcweir         const SetAttrMode nAttrMode, const bool bTableMode)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir     const SetAttrMode nFlags = nAttrMode | nsSetAttrMode::SETATTR_APICALL;
340cdf0e10cSrcweir 	SwDoc* pDoc = rPam.GetDoc();
341cdf0e10cSrcweir 	//StartEndAction
342cdf0e10cSrcweir 	UnoActionContext aAction(pDoc);
343cdf0e10cSrcweir     if (rPam.GetNext() != &rPam)    // Ring of Cursors
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSATTR, NULL);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         SwPaM *pCurrent = &rPam;
348cdf0e10cSrcweir         do
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             if (pCurrent->HasMark() &&
351cdf0e10cSrcweir                 ( (bTableMode) ||
352cdf0e10cSrcweir                   (*pCurrent->GetPoint() != *pCurrent->GetMark()) ))
353cdf0e10cSrcweir             {
354cdf0e10cSrcweir                 pDoc->InsertItemSet(*pCurrent, rSet, nFlags);
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir             pCurrent= static_cast<SwPaM *>(pCurrent->GetNext());
357cdf0e10cSrcweir         } while (pCurrent != &rPam);
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSATTR, NULL);
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir     else
362cdf0e10cSrcweir     {
363cdf0e10cSrcweir //			if( !HasSelection() )
364cdf0e10cSrcweir //				UpdateAttr();
365cdf0e10cSrcweir         pDoc->InsertItemSet( rPam, rSet, nFlags );
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir 	//#outline level,add by zhaojianwei
368cdf0e10cSrcweir 	if( rSet.GetItemState( RES_PARATR_OUTLINELEVEL, false ) >= SFX_ITEM_AVAILABLE )
369cdf0e10cSrcweir 	{
370cdf0e10cSrcweir 		SwTxtNode * pTmpNode = rPam.GetNode()->GetTxtNode();
371cdf0e10cSrcweir 		if ( pTmpNode )
372cdf0e10cSrcweir 		{
373cdf0e10cSrcweir 			rPam.GetDoc()->GetNodes().UpdateOutlineNode( *pTmpNode );
374cdf0e10cSrcweir 		}
375cdf0e10cSrcweir 	}
376cdf0e10cSrcweir 	//<-end,zhaojianwei
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
379cdf0e10cSrcweir // --> OD 2006-07-12 #i63870#
380cdf0e10cSrcweir // split third parameter <bCurrentAttrOnly> into new parameters <bOnlyTxtAttr>
381cdf0e10cSrcweir // and <bGetFromChrFmt> to get better control about resulting <SfxItemSet>
GetCrsrAttr(SwPaM & rPam,SfxItemSet & rSet,const bool bOnlyTxtAttr,const bool bGetFromChrFmt)382cdf0e10cSrcweir void SwUnoCursorHelper::GetCrsrAttr(SwPaM & rPam,
383cdf0e10cSrcweir         SfxItemSet & rSet, const bool bOnlyTxtAttr, const bool bGetFromChrFmt)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir 	static const sal_uInt16 nMaxLookup = 1000;
386cdf0e10cSrcweir 	SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() );
387cdf0e10cSrcweir 	SfxItemSet *pSet = &rSet;
388cdf0e10cSrcweir     SwPaM *pCurrent = & rPam;
389cdf0e10cSrcweir     do
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir         SwPosition const & rStart( *pCurrent->Start() );
392cdf0e10cSrcweir         SwPosition const & rEnd( *pCurrent->End() );
393cdf0e10cSrcweir         const sal_uLong nSttNd = rStart.nNode.GetIndex();
394cdf0e10cSrcweir         const sal_uLong nEndNd = rEnd  .nNode.GetIndex();
395cdf0e10cSrcweir 
396cdf0e10cSrcweir         if (nEndNd - nSttNd >= nMaxLookup)
397cdf0e10cSrcweir         {
398cdf0e10cSrcweir             rSet.ClearItem();
399cdf0e10cSrcweir             rSet.InvalidateAllItems();
400cdf0e10cSrcweir             return;// uno::Any();
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         // the first node inserts the values into the get set
404cdf0e10cSrcweir         // all other nodes merge their values into the get set
405cdf0e10cSrcweir         for (sal_uLong n = nSttNd; n <= nEndNd; ++n)
406cdf0e10cSrcweir         {
407cdf0e10cSrcweir             SwNode *const pNd = rPam.GetDoc()->GetNodes()[ n ];
408cdf0e10cSrcweir             switch (pNd->GetNodeType())
409cdf0e10cSrcweir             {
410cdf0e10cSrcweir                 case ND_TEXTNODE:
411cdf0e10cSrcweir                 {
412cdf0e10cSrcweir                     const xub_StrLen nStart = (n == nSttNd)
413cdf0e10cSrcweir                         ? rStart.nContent.GetIndex() : 0;
414cdf0e10cSrcweir                     const xub_StrLen nEnd   = (n == nEndNd)
415cdf0e10cSrcweir                         ? rEnd.nContent.GetIndex()
416cdf0e10cSrcweir                         : static_cast<SwTxtNode*>(pNd)->GetTxt().Len();
417cdf0e10cSrcweir                     static_cast<SwTxtNode*>(pNd)->GetAttr(
418cdf0e10cSrcweir                         *pSet, nStart, nEnd, bOnlyTxtAttr, bGetFromChrFmt);
419cdf0e10cSrcweir                 }
420cdf0e10cSrcweir                 break;
421cdf0e10cSrcweir                 case ND_GRFNODE:
422cdf0e10cSrcweir                 case ND_OLENODE:
423cdf0e10cSrcweir                     static_cast<SwCntntNode*>(pNd)->GetAttr( *pSet );
424cdf0e10cSrcweir                 break;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir                 default:
427cdf0e10cSrcweir                     continue; // skip this node
428cdf0e10cSrcweir             }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir             if (pSet != &rSet)
431cdf0e10cSrcweir             {
432cdf0e10cSrcweir                 rSet.MergeValues( aSet );
433cdf0e10cSrcweir             }
434cdf0e10cSrcweir             else
435cdf0e10cSrcweir             {
436cdf0e10cSrcweir                 pSet = &aSet;
437cdf0e10cSrcweir             }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir             if (aSet.Count())
440cdf0e10cSrcweir             {
441cdf0e10cSrcweir                 aSet.ClearItem();
442cdf0e10cSrcweir             }
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir         pCurrent= static_cast<SwPaM *>(pCurrent->GetNext());
445cdf0e10cSrcweir     } while ( pCurrent != &rPam );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir /******************************************************************
449cdf0e10cSrcweir  * SwXParagraphEnumeration
450cdf0e10cSrcweir  ******************************************************************/
451cdf0e10cSrcweir 
452cdf0e10cSrcweir class SwXParagraphEnumeration::Impl
453cdf0e10cSrcweir     : public SwClient
454cdf0e10cSrcweir {
455cdf0e10cSrcweir 
456cdf0e10cSrcweir public:
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     uno::Reference< text::XText > const     m_xParentText;
459cdf0e10cSrcweir     const CursorType        m_eCursorType;
460cdf0e10cSrcweir     /// Start node of the cell _or_ table the enumeration belongs to.
461cdf0e10cSrcweir     /// Used to restrict the movement of the UNO cursor to the cell and its
462cdf0e10cSrcweir     /// embedded tables.
463cdf0e10cSrcweir     SwStartNode const*const m_pOwnStartNode;
464cdf0e10cSrcweir     SwTable const*const     m_pOwnTable;
465cdf0e10cSrcweir     const sal_uLong             m_nEndIndex;
466cdf0e10cSrcweir     sal_Int32               m_nFirstParaStart;
467cdf0e10cSrcweir     sal_Int32               m_nLastParaEnd;
468cdf0e10cSrcweir     bool                    m_bFirstParagraph;
469cdf0e10cSrcweir     uno::Reference< text::XTextContent >    m_xNextPara;
470cdf0e10cSrcweir 
Impl(uno::Reference<text::XText> const & xParent,::std::auto_ptr<SwUnoCrsr> pCursor,const CursorType eType,SwStartNode const * const pStartNode,SwTable const * const pTable)471cdf0e10cSrcweir     Impl(   uno::Reference< text::XText > const& xParent,
472cdf0e10cSrcweir             ::std::auto_ptr<SwUnoCrsr> pCursor,
473cdf0e10cSrcweir             const CursorType eType,
474cdf0e10cSrcweir             SwStartNode const*const pStartNode, SwTable const*const pTable)
475cdf0e10cSrcweir         : SwClient( pCursor.release() )
476cdf0e10cSrcweir         , m_xParentText( xParent )
477cdf0e10cSrcweir         , m_eCursorType( eType )
478cdf0e10cSrcweir         // remember table and start node for later travelling
479cdf0e10cSrcweir         // (used in export of tables in tables)
480cdf0e10cSrcweir         , m_pOwnStartNode( pStartNode )
481cdf0e10cSrcweir         // for import of tables in tables we have to remember the actual
482cdf0e10cSrcweir         // table and start node of the current position in the enumeration.
483cdf0e10cSrcweir         , m_pOwnTable( pTable )
484cdf0e10cSrcweir         , m_nEndIndex( GetCursor()->End()->nNode.GetIndex() )
485cdf0e10cSrcweir         , m_nFirstParaStart( -1 )
486cdf0e10cSrcweir         , m_nLastParaEnd( -1 )
487cdf0e10cSrcweir         , m_bFirstParagraph( true )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         OSL_ENSURE(m_xParentText.is(), "SwXParagraphEnumeration: no parent?");
490cdf0e10cSrcweir         OSL_ENSURE(GetRegisteredIn(),  "SwXParagraphEnumeration: no cursor?");
491cdf0e10cSrcweir         OSL_ENSURE(   !((CURSOR_SELECTION_IN_TABLE == eType) ||
492cdf0e10cSrcweir                         (CURSOR_TBLTEXT == eType))
493cdf0e10cSrcweir                    || (m_pOwnTable && m_pOwnStartNode),
494cdf0e10cSrcweir             "SwXParagraphEnumeration: table type but no start node or table?");
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         if ((CURSOR_SELECTION == m_eCursorType) ||
497cdf0e10cSrcweir             (CURSOR_SELECTION_IN_TABLE == m_eCursorType))
498cdf0e10cSrcweir         {
499cdf0e10cSrcweir             SwUnoCrsr & rCursor = *GetCursor();
500cdf0e10cSrcweir             rCursor.Normalize();
501cdf0e10cSrcweir             m_nFirstParaStart = rCursor.GetPoint()->nContent.GetIndex();
502cdf0e10cSrcweir             m_nLastParaEnd = rCursor.GetMark()->nContent.GetIndex();
503cdf0e10cSrcweir             rCursor.DeleteMark();
504cdf0e10cSrcweir         }
505cdf0e10cSrcweir     }
506cdf0e10cSrcweir 
~Impl()507cdf0e10cSrcweir     ~Impl() {
508cdf0e10cSrcweir         // Impl owns the cursor; delete it here: SolarMutex is locked
509cdf0e10cSrcweir         delete GetRegisteredIn();
510cdf0e10cSrcweir     }
511cdf0e10cSrcweir 
GetCursor()512cdf0e10cSrcweir     SwUnoCrsr * GetCursor() {
513cdf0e10cSrcweir         return static_cast<SwUnoCrsr*>(
514cdf0e10cSrcweir                 const_cast<SwModify*>(GetRegisteredIn()));
515cdf0e10cSrcweir     }
516cdf0e10cSrcweir 
517cdf0e10cSrcweir     uno::Reference< text::XTextContent > NextElement_Impl()
518cdf0e10cSrcweir         throw (container::NoSuchElementException, lang::WrappedTargetException,
519cdf0e10cSrcweir                 uno::RuntimeException);
520cdf0e10cSrcweir protected:
521cdf0e10cSrcweir     // SwClient
522cdf0e10cSrcweir     virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew);
523cdf0e10cSrcweir 
524cdf0e10cSrcweir };
525cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)526cdf0e10cSrcweir void SwXParagraphEnumeration::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir     ClientModify(this, pOld, pNew);
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
SwXParagraphEnumeration(uno::Reference<text::XText> const & xParent,::std::auto_ptr<SwUnoCrsr> pCursor,const CursorType eType,SwStartNode const * const pStartNode,SwTable const * const pTable)531cdf0e10cSrcweir SwXParagraphEnumeration::SwXParagraphEnumeration(
532cdf0e10cSrcweir         uno::Reference< text::XText > const& xParent,
533cdf0e10cSrcweir         ::std::auto_ptr<SwUnoCrsr> pCursor,
534cdf0e10cSrcweir         const CursorType eType,
535cdf0e10cSrcweir         SwStartNode const*const pStartNode, SwTable const*const pTable)
536cdf0e10cSrcweir     : m_pImpl( new SwXParagraphEnumeration::Impl(xParent, pCursor, eType,
537cdf0e10cSrcweir                     pStartNode, pTable) )
538cdf0e10cSrcweir {
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
~SwXParagraphEnumeration()541cdf0e10cSrcweir SwXParagraphEnumeration::~SwXParagraphEnumeration()
542cdf0e10cSrcweir {
543cdf0e10cSrcweir }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()546cdf0e10cSrcweir SwXParagraphEnumeration::getImplementationName() throw (uno::RuntimeException)
547cdf0e10cSrcweir {
548cdf0e10cSrcweir 	return C2U("SwXParagraphEnumeration");
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir static char const*const g_ServicesParagraphEnum[] =
552cdf0e10cSrcweir {
553cdf0e10cSrcweir     "com.sun.star.text.ParagraphEnumeration",
554cdf0e10cSrcweir };
555cdf0e10cSrcweir static const size_t g_nServicesParagraphEnum(
556cdf0e10cSrcweir     sizeof(g_ServicesParagraphEnum)/sizeof(g_ServicesParagraphEnum[0]));
557cdf0e10cSrcweir 
558cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const OUString & rServiceName)559cdf0e10cSrcweir SwXParagraphEnumeration::supportsService(const OUString& rServiceName)
560cdf0e10cSrcweir throw (uno::RuntimeException)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     return ::sw::SupportsServiceImpl(
563cdf0e10cSrcweir             g_nServicesParagraphEnum, g_ServicesParagraphEnum, rServiceName);
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
566cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL
getSupportedServiceNames()567cdf0e10cSrcweir SwXParagraphEnumeration::getSupportedServiceNames()
568cdf0e10cSrcweir throw (uno::RuntimeException)
569cdf0e10cSrcweir {
570cdf0e10cSrcweir     return ::sw::GetSupportedServiceNamesImpl(
571cdf0e10cSrcweir             g_nServicesParagraphEnum, g_ServicesParagraphEnum);
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir sal_Bool SAL_CALL
hasMoreElements()575cdf0e10cSrcweir SwXParagraphEnumeration::hasMoreElements() throw (uno::RuntimeException)
576cdf0e10cSrcweir {
577cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     return (m_pImpl->m_bFirstParagraph) ? sal_True : m_pImpl->m_xNextPara.is();
580cdf0e10cSrcweir }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir //!! compare to SwShellTableCrsr::FillRects() in viscrs.cxx
583cdf0e10cSrcweir static SwTableNode *
lcl_FindTopLevelTable(SwTableNode * const pTblNode,SwTable const * const pOwnTable)584cdf0e10cSrcweir lcl_FindTopLevelTable(
585cdf0e10cSrcweir         SwTableNode *const pTblNode, SwTable const*const pOwnTable)
586cdf0e10cSrcweir {
587cdf0e10cSrcweir 	// find top-most table in current context (section) level
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 	SwTableNode * pLast = pTblNode;
590cdf0e10cSrcweir 	for (SwTableNode* pTmp = pLast;
591cdf0e10cSrcweir 		 pTmp != NULL  &&  &pTmp->GetTable() != pOwnTable;	/* we must not go up higher than the own table! */
592cdf0e10cSrcweir          pTmp = pTmp->StartOfSectionNode()->FindTableNode() )
593cdf0e10cSrcweir 	{
594cdf0e10cSrcweir 		pLast = pTmp;
595cdf0e10cSrcweir 	}
596cdf0e10cSrcweir 	return pLast;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
600cdf0e10cSrcweir static bool
lcl_CursorIsInSection(SwUnoCrsr const * const pUnoCrsr,SwStartNode const * const pOwnStartNode)601cdf0e10cSrcweir lcl_CursorIsInSection(
602cdf0e10cSrcweir         SwUnoCrsr const*const pUnoCrsr, SwStartNode const*const pOwnStartNode)
603cdf0e10cSrcweir {
604cdf0e10cSrcweir 	// returns true if the cursor is in the section (or in a sub section!)
605cdf0e10cSrcweir 	// represented by pOwnStartNode
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     bool bRes = true;
608cdf0e10cSrcweir 	if (pUnoCrsr && pOwnStartNode)
609cdf0e10cSrcweir 	{
610cdf0e10cSrcweir 		const SwEndNode * pOwnEndNode = pOwnStartNode->EndOfSectionNode();
611cdf0e10cSrcweir 		bRes = pOwnStartNode->GetIndex() <= pUnoCrsr->Start()->nNode.GetIndex() &&
612cdf0e10cSrcweir 			   pUnoCrsr->End()->nNode.GetIndex() <= pOwnEndNode->GetIndex();
613cdf0e10cSrcweir 	}
614cdf0e10cSrcweir 	return bRes;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 
618cdf0e10cSrcweir uno::Reference< text::XTextContent >
NextElement_Impl()619cdf0e10cSrcweir SwXParagraphEnumeration::Impl::NextElement_Impl()
620cdf0e10cSrcweir throw (container::NoSuchElementException, lang::WrappedTargetException,
621cdf0e10cSrcweir         uno::RuntimeException)
622cdf0e10cSrcweir {
623cdf0e10cSrcweir     SwUnoCrsr *const pUnoCrsr = GetCursor();
624cdf0e10cSrcweir     if (!pUnoCrsr)
625cdf0e10cSrcweir     {
626cdf0e10cSrcweir         throw uno::RuntimeException();
627cdf0e10cSrcweir     }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     // check for exceeding selections
630cdf0e10cSrcweir     if (!m_bFirstParagraph &&
631cdf0e10cSrcweir         ((CURSOR_SELECTION == m_eCursorType) ||
632cdf0e10cSrcweir          (CURSOR_SELECTION_IN_TABLE == m_eCursorType)))
633cdf0e10cSrcweir     {
634cdf0e10cSrcweir         SwPosition* pStart = pUnoCrsr->Start();
635cdf0e10cSrcweir         const ::std::auto_ptr<SwUnoCrsr> aNewCrsr(
636cdf0e10cSrcweir             pUnoCrsr->GetDoc()->CreateUnoCrsr(*pStart, sal_False) );
637cdf0e10cSrcweir         // one may also go into tables here
638cdf0e10cSrcweir         if ((CURSOR_TBLTEXT != m_eCursorType) &&
639cdf0e10cSrcweir             (CURSOR_SELECTION_IN_TABLE != m_eCursorType))
640cdf0e10cSrcweir         {
641cdf0e10cSrcweir             aNewCrsr->SetRemainInSection( sal_False );
642cdf0e10cSrcweir         }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir         // os 2005-01-14: This part is only necessary to detect movements out
645cdf0e10cSrcweir         // of a selection; if there is no selection we don't have to care
646cdf0e10cSrcweir         SwTableNode *const pTblNode = aNewCrsr->GetNode()->FindTableNode();
647cdf0e10cSrcweir         if (((CURSOR_TBLTEXT != m_eCursorType) &&
648cdf0e10cSrcweir             (CURSOR_SELECTION_IN_TABLE != m_eCursorType)) && pTblNode)
649cdf0e10cSrcweir         {
650cdf0e10cSrcweir             aNewCrsr->GetPoint()->nNode = pTblNode->EndOfSectionIndex();
651cdf0e10cSrcweir             aNewCrsr->Move(fnMoveForward, fnGoNode);
652cdf0e10cSrcweir         }
653cdf0e10cSrcweir         else
654cdf0e10cSrcweir         {
655cdf0e10cSrcweir             aNewCrsr->MovePara(fnParaNext, fnParaStart);
656cdf0e10cSrcweir         }
657cdf0e10cSrcweir         if (m_nEndIndex < aNewCrsr->Start()->nNode.GetIndex())
658cdf0e10cSrcweir         {
659cdf0e10cSrcweir             return 0;
660cdf0e10cSrcweir         }
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     sal_Bool bInTable = sal_False;
664cdf0e10cSrcweir     if (!m_bFirstParagraph)
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         pUnoCrsr->SetRemainInSection( sal_False );
667cdf0e10cSrcweir         // what to do if already in a table?
668cdf0e10cSrcweir         SwTableNode * pTblNode = pUnoCrsr->GetNode()->FindTableNode();
669cdf0e10cSrcweir         pTblNode = lcl_FindTopLevelTable( pTblNode, m_pOwnTable );
670cdf0e10cSrcweir         if (pTblNode && (&pTblNode->GetTable() != m_pOwnTable))
671cdf0e10cSrcweir         {
672cdf0e10cSrcweir             // this is a foreign table: go to end
673cdf0e10cSrcweir             pUnoCrsr->GetPoint()->nNode = pTblNode->EndOfSectionIndex();
674cdf0e10cSrcweir             if (!pUnoCrsr->Move(fnMoveForward, fnGoNode))
675cdf0e10cSrcweir             {
676cdf0e10cSrcweir                 return 0;
677cdf0e10cSrcweir             }
678cdf0e10cSrcweir             bInTable = sal_True;
679cdf0e10cSrcweir         }
680cdf0e10cSrcweir     }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     uno::Reference< text::XTextContent >  xRef;
683cdf0e10cSrcweir     // the cursor must remain in the current section or a subsection
684cdf0e10cSrcweir     // before AND after the movement...
685cdf0e10cSrcweir     if (lcl_CursorIsInSection( pUnoCrsr, m_pOwnStartNode ) &&
686cdf0e10cSrcweir         (m_bFirstParagraph || bInTable ||
687cdf0e10cSrcweir         (pUnoCrsr->MovePara(fnParaNext, fnParaStart) &&
688cdf0e10cSrcweir             lcl_CursorIsInSection( pUnoCrsr, m_pOwnStartNode ))))
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir         SwPosition* pStart = pUnoCrsr->Start();
691cdf0e10cSrcweir         const sal_Int32 nFirstContent =
692cdf0e10cSrcweir             (m_bFirstParagraph) ? m_nFirstParaStart : -1;
693cdf0e10cSrcweir         const sal_Int32 nLastContent =
694cdf0e10cSrcweir             (m_nEndIndex == pStart->nNode.GetIndex()) ? m_nLastParaEnd : -1;
695cdf0e10cSrcweir 
696cdf0e10cSrcweir         // position in a table, or in a simple paragraph?
697cdf0e10cSrcweir         SwTableNode * pTblNode = pUnoCrsr->GetNode()->FindTableNode();
698cdf0e10cSrcweir         pTblNode = lcl_FindTopLevelTable( pTblNode, m_pOwnTable );
699cdf0e10cSrcweir         if (/*CURSOR_TBLTEXT != eCursorType && CURSOR_SELECTION_IN_TABLE != eCursorType && */
700cdf0e10cSrcweir             pTblNode && (&pTblNode->GetTable() != m_pOwnTable))
701cdf0e10cSrcweir         {
702cdf0e10cSrcweir             // this is a foreign table
703cdf0e10cSrcweir             SwFrmFmt* pTableFmt =
704cdf0e10cSrcweir                 static_cast<SwFrmFmt*>(pTblNode->GetTable().GetFrmFmt());
705cdf0e10cSrcweir             text::XTextTable *const pTable =
706cdf0e10cSrcweir                 SwXTextTables::GetObject( *pTableFmt );
707cdf0e10cSrcweir             xRef = static_cast<text::XTextContent*>(
708cdf0e10cSrcweir                     static_cast<SwXTextTable*>(pTable));
709cdf0e10cSrcweir         }
710cdf0e10cSrcweir         else
711cdf0e10cSrcweir         {
712cdf0e10cSrcweir             text::XText *const pText = m_xParentText.get();
713cdf0e10cSrcweir             xRef = SwXParagraph::CreateXParagraph(*pUnoCrsr->GetDoc(),
714cdf0e10cSrcweir                 *pStart->nNode.GetNode().GetTxtNode(),
715cdf0e10cSrcweir                 static_cast<SwXText*>(pText), nFirstContent, nLastContent);
716cdf0e10cSrcweir         }
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir     return xRef;
720cdf0e10cSrcweir }
721cdf0e10cSrcweir 
nextElement()722cdf0e10cSrcweir uno::Any SAL_CALL SwXParagraphEnumeration::nextElement()
723cdf0e10cSrcweir throw (container::NoSuchElementException, lang::WrappedTargetException,
724cdf0e10cSrcweir         uno::RuntimeException)
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
727cdf0e10cSrcweir 
728cdf0e10cSrcweir     if (m_pImpl->m_bFirstParagraph)
729cdf0e10cSrcweir     {
730cdf0e10cSrcweir         m_pImpl->m_xNextPara = m_pImpl->NextElement_Impl();
731cdf0e10cSrcweir         m_pImpl->m_bFirstParagraph = false;
732cdf0e10cSrcweir     }
733cdf0e10cSrcweir     const uno::Reference< text::XTextContent > xRef = m_pImpl->m_xNextPara;
734cdf0e10cSrcweir     if (!xRef.is())
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         throw container::NoSuchElementException();
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir     m_pImpl->m_xNextPara = m_pImpl->NextElement_Impl();
739cdf0e10cSrcweir 
740cdf0e10cSrcweir     uno::Any aRet;
741cdf0e10cSrcweir     aRet <<= xRef;
742cdf0e10cSrcweir 	return aRet;
743cdf0e10cSrcweir }
744cdf0e10cSrcweir 
745cdf0e10cSrcweir /******************************************************************
746cdf0e10cSrcweir  * SwXTextRange
747cdf0e10cSrcweir  ******************************************************************/
748cdf0e10cSrcweir 
749cdf0e10cSrcweir class SwXTextRange::Impl
750cdf0e10cSrcweir     : public SwClient
751cdf0e10cSrcweir {
752cdf0e10cSrcweir 
753cdf0e10cSrcweir public:
754cdf0e10cSrcweir 
755cdf0e10cSrcweir     const SfxItemPropertySet &  m_rPropSet;
756cdf0e10cSrcweir     const enum RangePosition    m_eRangePosition;
757cdf0e10cSrcweir     SwDoc &                     m_rDoc;
758cdf0e10cSrcweir     uno::Reference<text::XText> m_xParentText;
759cdf0e10cSrcweir     SwDepend            m_ObjectDepend; // register at format of table or frame
760cdf0e10cSrcweir     ::sw::mark::IMark * m_pMark;
761cdf0e10cSrcweir 
Impl(SwDoc & rDoc,const enum RangePosition eRange,SwFrmFmt * const pTblFmt=0,const uno::Reference<text::XText> & xParent=0)762cdf0e10cSrcweir     Impl(   SwDoc & rDoc, const enum RangePosition eRange,
763cdf0e10cSrcweir             SwFrmFmt *const pTblFmt = 0,
764cdf0e10cSrcweir             const uno::Reference< text::XText > & xParent = 0)
765cdf0e10cSrcweir         : SwClient()
766cdf0e10cSrcweir         , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
767cdf0e10cSrcweir         , m_eRangePosition(eRange)
768cdf0e10cSrcweir         , m_rDoc(rDoc)
769cdf0e10cSrcweir         , m_xParentText(xParent)
770cdf0e10cSrcweir         , m_ObjectDepend(this, pTblFmt)
771cdf0e10cSrcweir         , m_pMark(0)
772cdf0e10cSrcweir     {
773cdf0e10cSrcweir     }
774cdf0e10cSrcweir 
~Impl()775cdf0e10cSrcweir     ~Impl()
776cdf0e10cSrcweir     {
777cdf0e10cSrcweir         // Impl owns the bookmark; delete it here: SolarMutex is locked
778cdf0e10cSrcweir         Invalidate();
779cdf0e10cSrcweir     }
780cdf0e10cSrcweir 
Invalidate()781cdf0e10cSrcweir     void Invalidate()
782cdf0e10cSrcweir     {
783cdf0e10cSrcweir         if (m_pMark)
784cdf0e10cSrcweir         {
785cdf0e10cSrcweir             m_rDoc.getIDocumentMarkAccess()->deleteMark(m_pMark);
786cdf0e10cSrcweir             m_pMark = 0;
787cdf0e10cSrcweir         }
788cdf0e10cSrcweir     }
789cdf0e10cSrcweir 
GetBookmark() const790cdf0e10cSrcweir     const ::sw::mark::IMark * GetBookmark() const { return m_pMark; }
791cdf0e10cSrcweir protected:
792cdf0e10cSrcweir     // SwClient
793cdf0e10cSrcweir     virtual void    Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
794cdf0e10cSrcweir 
795cdf0e10cSrcweir };
796cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)797cdf0e10cSrcweir void SwXTextRange::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
798cdf0e10cSrcweir {
799cdf0e10cSrcweir     const bool bAlreadyRegistered = 0 != GetRegisteredIn();
800cdf0e10cSrcweir     ClientModify(this, pOld, pNew);
801cdf0e10cSrcweir     if (m_ObjectDepend.GetRegisteredIn())
802cdf0e10cSrcweir     {
803cdf0e10cSrcweir         ClientModify(&m_ObjectDepend, pOld, pNew);
804cdf0e10cSrcweir         // if the depend was removed then the range must be removed too
805cdf0e10cSrcweir         if (!m_ObjectDepend.GetRegisteredIn() && GetRegisteredIn())
806cdf0e10cSrcweir         {
807cdf0e10cSrcweir             const_cast<SwModify*>(GetRegisteredIn())->Remove(this);
808cdf0e10cSrcweir         }
809cdf0e10cSrcweir         // or if the range has been removed but the depend ist still
810cdf0e10cSrcweir         // connected then the depend must be removed
811cdf0e10cSrcweir         else if (bAlreadyRegistered && !GetRegisteredIn() &&
812cdf0e10cSrcweir                     m_ObjectDepend.GetRegisteredIn())
813cdf0e10cSrcweir         {
814cdf0e10cSrcweir             const_cast<SwModify*>(m_ObjectDepend.GetRegisteredIn())
815cdf0e10cSrcweir                 ->Remove(& m_ObjectDepend);
816cdf0e10cSrcweir         }
817cdf0e10cSrcweir     }
818cdf0e10cSrcweir     if (!GetRegisteredIn())
819cdf0e10cSrcweir     {
820cdf0e10cSrcweir         m_pMark = 0;
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir 
SwXTextRange(SwPaM & rPam,const uno::Reference<text::XText> & xParent,const enum RangePosition eRange)825cdf0e10cSrcweir SwXTextRange::SwXTextRange(SwPaM& rPam,
826cdf0e10cSrcweir         const uno::Reference< text::XText > & xParent,
827cdf0e10cSrcweir         const enum RangePosition eRange)
828cdf0e10cSrcweir     : m_pImpl( new SwXTextRange::Impl(*rPam.GetDoc(), eRange, 0, xParent) )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir     SetPositions(rPam);
831cdf0e10cSrcweir }
832cdf0e10cSrcweir 
SwXTextRange(SwFrmFmt & rTblFmt)833cdf0e10cSrcweir SwXTextRange::SwXTextRange(SwFrmFmt& rTblFmt)
834cdf0e10cSrcweir     : m_pImpl(
835cdf0e10cSrcweir         new SwXTextRange::Impl(*rTblFmt.GetDoc(), RANGE_IS_TABLE, &rTblFmt) )
836cdf0e10cSrcweir {
837cdf0e10cSrcweir     SwTable *const pTable = SwTable::FindTable( &rTblFmt );
838cdf0e10cSrcweir     SwTableNode *const pTblNode = pTable->GetTableNode();
839cdf0e10cSrcweir     SwPosition aPosition( *pTblNode );
840cdf0e10cSrcweir     SwPaM aPam( aPosition );
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     SetPositions( aPam );
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
~SwXTextRange()845cdf0e10cSrcweir SwXTextRange::~SwXTextRange()
846cdf0e10cSrcweir {
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
GetDoc() const849cdf0e10cSrcweir const SwDoc * SwXTextRange::GetDoc() const
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     return & m_pImpl->m_rDoc;
852cdf0e10cSrcweir }
853cdf0e10cSrcweir 
GetDoc()854cdf0e10cSrcweir SwDoc * SwXTextRange::GetDoc()
855cdf0e10cSrcweir {
856cdf0e10cSrcweir     return & m_pImpl->m_rDoc;
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 
Invalidate()860cdf0e10cSrcweir void SwXTextRange::Invalidate()
861cdf0e10cSrcweir {
862cdf0e10cSrcweir     m_pImpl->Invalidate();
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
SetPositions(const SwPaM & rPam)865cdf0e10cSrcweir void SwXTextRange::SetPositions(const SwPaM& rPam)
866cdf0e10cSrcweir {
867cdf0e10cSrcweir     m_pImpl->Invalidate();
868cdf0e10cSrcweir     IDocumentMarkAccess* const pMA = m_pImpl->m_rDoc.getIDocumentMarkAccess();
869cdf0e10cSrcweir     m_pImpl->m_pMark = pMA->makeMark(rPam, ::rtl::OUString(),
870cdf0e10cSrcweir                 IDocumentMarkAccess::UNO_BOOKMARK);
871cdf0e10cSrcweir     m_pImpl->m_pMark->Add(m_pImpl.get());
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
DeleteAndInsert(const::rtl::OUString & rText,const bool bForceExpandHints)874cdf0e10cSrcweir void SwXTextRange::DeleteAndInsert(
875cdf0e10cSrcweir         const ::rtl::OUString& rText, const bool bForceExpandHints)
876cdf0e10cSrcweir throw (uno::RuntimeException)
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
879cdf0e10cSrcweir     {
880cdf0e10cSrcweir         // setString on table not allowed
881cdf0e10cSrcweir         throw uno::RuntimeException();
882cdf0e10cSrcweir     }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir     const SwPosition aPos(GetDoc()->GetNodes().GetEndOfContent());
885cdf0e10cSrcweir     SwCursor aCursor(aPos, 0, false);
886cdf0e10cSrcweir     if (GetPositions(aCursor))
887cdf0e10cSrcweir     {
888cdf0e10cSrcweir         UnoActionContext aAction(& m_pImpl->m_rDoc);
889cdf0e10cSrcweir         m_pImpl->m_rDoc.GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
890cdf0e10cSrcweir         if (aCursor.HasMark())
891cdf0e10cSrcweir         {
892cdf0e10cSrcweir             m_pImpl->m_rDoc.DeleteAndJoin(aCursor);
893cdf0e10cSrcweir         }
894cdf0e10cSrcweir 
895cdf0e10cSrcweir         if (rText.getLength())
896cdf0e10cSrcweir         {
897cdf0e10cSrcweir             SwUnoCursorHelper::DocInsertStringSplitCR(
898cdf0e10cSrcweir                     m_pImpl->m_rDoc, aCursor, rText, bForceExpandHints);
899cdf0e10cSrcweir 
900cdf0e10cSrcweir             SwUnoCursorHelper::SelectPam(aCursor, true);
901cdf0e10cSrcweir             aCursor.Left(rText.getLength(), CRSR_SKIP_CHARS, sal_False, sal_False);
902cdf0e10cSrcweir         }
903cdf0e10cSrcweir         SetPositions(aCursor);
904cdf0e10cSrcweir         m_pImpl->m_rDoc.GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
905cdf0e10cSrcweir     }
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
getUnoTunnelId()908cdf0e10cSrcweir const uno::Sequence< sal_Int8 > & SwXTextRange::getUnoTunnelId()
909cdf0e10cSrcweir {
910cdf0e10cSrcweir     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
911cdf0e10cSrcweir     return aSeq;
912cdf0e10cSrcweir }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir // XUnoTunnel
915cdf0e10cSrcweir sal_Int64 SAL_CALL
getSomething(const uno::Sequence<sal_Int8> & rId)916cdf0e10cSrcweir SwXTextRange::getSomething(const uno::Sequence< sal_Int8 >& rId)
917cdf0e10cSrcweir throw (uno::RuntimeException)
918cdf0e10cSrcweir {
919cdf0e10cSrcweir     return ::sw::UnoTunnelImpl<SwXTextRange>(rId, this);
920cdf0e10cSrcweir }
921cdf0e10cSrcweir 
922cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()923cdf0e10cSrcweir SwXTextRange::getImplementationName() throw (uno::RuntimeException)
924cdf0e10cSrcweir {
925cdf0e10cSrcweir     return OUString::createFromAscii("SwXTextRange");
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
928cdf0e10cSrcweir static char const*const g_ServicesTextRange[] =
929cdf0e10cSrcweir {
930cdf0e10cSrcweir     "com.sun.star.text.TextRange",
931cdf0e10cSrcweir     "com.sun.star.style.CharacterProperties",
932cdf0e10cSrcweir     "com.sun.star.style.CharacterPropertiesAsian",
933cdf0e10cSrcweir     "com.sun.star.style.CharacterPropertiesComplex",
934cdf0e10cSrcweir     "com.sun.star.style.ParagraphProperties",
935cdf0e10cSrcweir     "com.sun.star.style.ParagraphPropertiesAsian",
936cdf0e10cSrcweir     "com.sun.star.style.ParagraphPropertiesComplex",
937cdf0e10cSrcweir };
938cdf0e10cSrcweir static const size_t g_nServicesTextRange(
939cdf0e10cSrcweir     sizeof(g_ServicesTextRange)/sizeof(g_ServicesTextRange[0]));
940cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)941cdf0e10cSrcweir sal_Bool SAL_CALL SwXTextRange::supportsService(const OUString& rServiceName)
942cdf0e10cSrcweir throw (uno::RuntimeException)
943cdf0e10cSrcweir {
944cdf0e10cSrcweir     return ::sw::SupportsServiceImpl(
945cdf0e10cSrcweir             g_nServicesTextRange, g_ServicesTextRange, rServiceName);
946cdf0e10cSrcweir }
947cdf0e10cSrcweir 
948cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL
getSupportedServiceNames()949cdf0e10cSrcweir SwXTextRange::getSupportedServiceNames() throw (uno::RuntimeException)
950cdf0e10cSrcweir {
951cdf0e10cSrcweir     return ::sw::GetSupportedServiceNamesImpl(
952cdf0e10cSrcweir             g_nServicesTextRange, g_ServicesTextRange);
953cdf0e10cSrcweir }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir uno::Reference< text::XText > SAL_CALL
getText()956cdf0e10cSrcweir SwXTextRange::getText() throw (uno::RuntimeException)
957cdf0e10cSrcweir {
958cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
959cdf0e10cSrcweir 
960cdf0e10cSrcweir     if (!m_pImpl->m_xParentText.is())
961cdf0e10cSrcweir     {
962cdf0e10cSrcweir         if (m_pImpl->m_eRangePosition == RANGE_IS_TABLE &&
963cdf0e10cSrcweir             m_pImpl->m_ObjectDepend.GetRegisteredIn())
964cdf0e10cSrcweir         {
965cdf0e10cSrcweir             SwFrmFmt const*const pTblFmt = static_cast<SwFrmFmt const*>(
966cdf0e10cSrcweir                     m_pImpl->m_ObjectDepend.GetRegisteredIn());
967cdf0e10cSrcweir             SwTable const*const pTable = SwTable::FindTable( pTblFmt );
968cdf0e10cSrcweir             SwTableNode const*const pTblNode = pTable->GetTableNode();
969cdf0e10cSrcweir             const SwPosition aPosition( *pTblNode );
970cdf0e10cSrcweir             m_pImpl->m_xParentText =
971cdf0e10cSrcweir                 ::sw::CreateParentXText(m_pImpl->m_rDoc, aPosition);
972cdf0e10cSrcweir         }
973cdf0e10cSrcweir     }
974cdf0e10cSrcweir     OSL_ENSURE(m_pImpl->m_xParentText.is(), "SwXTextRange::getText: no text");
975cdf0e10cSrcweir     return m_pImpl->m_xParentText;
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
978cdf0e10cSrcweir uno::Reference< text::XTextRange > SAL_CALL
getStart()979cdf0e10cSrcweir SwXTextRange::getStart() throw (uno::RuntimeException)
980cdf0e10cSrcweir {
981cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
982cdf0e10cSrcweir 
983cdf0e10cSrcweir     uno::Reference< text::XTextRange >  xRet;
984cdf0e10cSrcweir     ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
985cdf0e10cSrcweir     if (!m_pImpl->m_xParentText.is())
986cdf0e10cSrcweir     {
987cdf0e10cSrcweir         getText();
988cdf0e10cSrcweir     }
989cdf0e10cSrcweir     if(pBkmk)
990cdf0e10cSrcweir     {
991cdf0e10cSrcweir         SwPaM aPam(pBkmk->GetMarkStart());
992cdf0e10cSrcweir         xRet = new SwXTextRange(aPam, m_pImpl->m_xParentText);
993cdf0e10cSrcweir     }
994cdf0e10cSrcweir     else if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
995cdf0e10cSrcweir     {
996cdf0e10cSrcweir         // start and end are this, if its a table
997cdf0e10cSrcweir         xRet = this;
998cdf0e10cSrcweir     }
999cdf0e10cSrcweir     else
1000cdf0e10cSrcweir     {
1001cdf0e10cSrcweir         throw uno::RuntimeException();
1002cdf0e10cSrcweir     }
1003cdf0e10cSrcweir     return xRet;
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir 
1006cdf0e10cSrcweir uno::Reference< text::XTextRange > SAL_CALL
getEnd()1007cdf0e10cSrcweir SwXTextRange::getEnd() throw (uno::RuntimeException)
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir     uno::Reference< text::XTextRange >  xRet;
1012cdf0e10cSrcweir     ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
1013cdf0e10cSrcweir     if (!m_pImpl->m_xParentText.is())
1014cdf0e10cSrcweir     {
1015cdf0e10cSrcweir         getText();
1016cdf0e10cSrcweir     }
1017cdf0e10cSrcweir     if(pBkmk)
1018cdf0e10cSrcweir     {
1019cdf0e10cSrcweir         SwPaM aPam(pBkmk->GetMarkEnd());
1020cdf0e10cSrcweir         xRet = new SwXTextRange(aPam, m_pImpl->m_xParentText);
1021cdf0e10cSrcweir     }
1022cdf0e10cSrcweir     else if (RANGE_IS_TABLE == m_pImpl->m_eRangePosition)
1023cdf0e10cSrcweir     {
1024cdf0e10cSrcweir         // start and end are this, if its a table
1025cdf0e10cSrcweir         xRet = this;
1026cdf0e10cSrcweir     }
1027cdf0e10cSrcweir     else
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         throw uno::RuntimeException();
1030cdf0e10cSrcweir     }
1031cdf0e10cSrcweir     return xRet;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir 
getString()1034cdf0e10cSrcweir OUString SAL_CALL SwXTextRange::getString() throw (uno::RuntimeException)
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir     OUString sRet;
1039cdf0e10cSrcweir     // for tables there is no bookmark, thus also no text
1040cdf0e10cSrcweir     // one could export the table as ASCII here maybe?
1041cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1042cdf0e10cSrcweir     if (GetPositions(aPaM) && aPaM.HasMark())
1043cdf0e10cSrcweir     {
1044cdf0e10cSrcweir         SwUnoCursorHelper::GetTextFromPam(aPaM, sRet);
1045cdf0e10cSrcweir     }
1046cdf0e10cSrcweir     return sRet;
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir 
setString(const OUString & rString)1049cdf0e10cSrcweir void SAL_CALL SwXTextRange::setString(const OUString& rString)
1050cdf0e10cSrcweir throw (uno::RuntimeException)
1051cdf0e10cSrcweir {
1052cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir     DeleteAndInsert(rString, false);
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir 
GetPositions(SwPaM & rToFill) const1057cdf0e10cSrcweir bool SwXTextRange::GetPositions(SwPaM& rToFill) const
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir     ::sw::mark::IMark const * const pBkmk = m_pImpl->GetBookmark();
1060cdf0e10cSrcweir     if(pBkmk)
1061cdf0e10cSrcweir     {
1062cdf0e10cSrcweir         *rToFill.GetPoint() = pBkmk->GetMarkPos();
1063cdf0e10cSrcweir         if(pBkmk->IsExpanded())
1064cdf0e10cSrcweir         {
1065cdf0e10cSrcweir             rToFill.SetMark();
1066cdf0e10cSrcweir             *rToFill.GetMark() = pBkmk->GetOtherMarkPos();
1067cdf0e10cSrcweir         }
1068cdf0e10cSrcweir         else
1069cdf0e10cSrcweir         {
1070cdf0e10cSrcweir             rToFill.DeleteMark();
1071cdf0e10cSrcweir         }
1072cdf0e10cSrcweir         return true;
1073cdf0e10cSrcweir     }
1074cdf0e10cSrcweir     return false;
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir namespace sw {
1078cdf0e10cSrcweir 
XTextRangeToSwPaM(SwUnoInternalPaM & rToFill,const uno::Reference<text::XTextRange> & xTextRange)1079cdf0e10cSrcweir bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill,
1080cdf0e10cSrcweir         const uno::Reference< text::XTextRange > & xTextRange)
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir     bool bRet = false;
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
1085cdf0e10cSrcweir     SwXTextRange* pRange = 0;
1086cdf0e10cSrcweir     OTextCursorHelper* pCursor = 0;
1087cdf0e10cSrcweir     SwXTextPortion* pPortion = 0;
1088cdf0e10cSrcweir     SwXText* pText = 0;
1089cdf0e10cSrcweir     SwXParagraph* pPara = 0;
1090cdf0e10cSrcweir     if(xRangeTunnel.is())
1091cdf0e10cSrcweir     {
1092cdf0e10cSrcweir         pRange  = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1093cdf0e10cSrcweir         pCursor =
1094cdf0e10cSrcweir             ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1095cdf0e10cSrcweir         pPortion=
1096cdf0e10cSrcweir             ::sw::UnoTunnelGetImplementation<SwXTextPortion>(xRangeTunnel);
1097cdf0e10cSrcweir         pText   = ::sw::UnoTunnelGetImplementation<SwXText>(xRangeTunnel);
1098cdf0e10cSrcweir         pPara   = ::sw::UnoTunnelGetImplementation<SwXParagraph>(xRangeTunnel);
1099cdf0e10cSrcweir     }
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir     // if it's a text then create a temporary cursor there and re-use
1102cdf0e10cSrcweir     // the pCursor variable
1103cdf0e10cSrcweir     // #i108489#: Reference in outside scope to keep cursor alive
1104cdf0e10cSrcweir     uno::Reference< text::XTextCursor > xTextCursor;
1105cdf0e10cSrcweir     if (pText)
1106cdf0e10cSrcweir     {
1107cdf0e10cSrcweir         xTextCursor.set( pText->CreateCursor() );
1108cdf0e10cSrcweir         xTextCursor->gotoEnd(sal_True);
1109cdf0e10cSrcweir         const uno::Reference<lang::XUnoTunnel> xCrsrTunnel(
1110cdf0e10cSrcweir                 xTextCursor, uno::UNO_QUERY);
1111cdf0e10cSrcweir         pCursor =
1112cdf0e10cSrcweir             ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xCrsrTunnel);
1113cdf0e10cSrcweir     }
1114cdf0e10cSrcweir     if(pRange && pRange->GetDoc() == rToFill.GetDoc())
1115cdf0e10cSrcweir     {
1116cdf0e10cSrcweir         bRet = pRange->GetPositions(rToFill);
1117cdf0e10cSrcweir     }
1118cdf0e10cSrcweir     else
1119cdf0e10cSrcweir     {
1120cdf0e10cSrcweir         if (pPara)
1121cdf0e10cSrcweir         {
1122cdf0e10cSrcweir             bRet = pPara->SelectPaM(rToFill);
1123cdf0e10cSrcweir         }
1124cdf0e10cSrcweir         else
1125cdf0e10cSrcweir         {
1126cdf0e10cSrcweir             SwDoc* const pDoc = (pCursor) ? pCursor->GetDoc()
1127cdf0e10cSrcweir                 : ((pPortion) ? pPortion->GetCursor()->GetDoc() : 0);
1128cdf0e10cSrcweir             const SwPaM* const pUnoCrsr = (pCursor) ? pCursor->GetPaM()
1129cdf0e10cSrcweir                 : ((pPortion) ? pPortion->GetCursor() : 0);
1130cdf0e10cSrcweir             if (pUnoCrsr && pDoc == rToFill.GetDoc())
1131cdf0e10cSrcweir             {
1132cdf0e10cSrcweir                 DBG_ASSERT((SwPaM*)pUnoCrsr->GetNext() == pUnoCrsr,
1133cdf0e10cSrcweir                         "what to do about rings?");
1134cdf0e10cSrcweir                 bRet = true;
1135cdf0e10cSrcweir                 *rToFill.GetPoint() = *pUnoCrsr->GetPoint();
1136cdf0e10cSrcweir                 if (pUnoCrsr->HasMark())
1137cdf0e10cSrcweir                 {
1138cdf0e10cSrcweir                     rToFill.SetMark();
1139cdf0e10cSrcweir                     *rToFill.GetMark() = *pUnoCrsr->GetMark();
1140cdf0e10cSrcweir                 }
1141cdf0e10cSrcweir                 else
1142cdf0e10cSrcweir                     rToFill.DeleteMark();
1143cdf0e10cSrcweir             }
1144cdf0e10cSrcweir         }
1145cdf0e10cSrcweir     }
1146cdf0e10cSrcweir     return bRet;
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir static bool
lcl_IsStartNodeInFormat(const bool bHeader,SwStartNode * const pSttNode,SwFrmFmt const * const pFrmFmt,SwFrmFmt * & rpFormat)1150cdf0e10cSrcweir lcl_IsStartNodeInFormat(const bool bHeader, SwStartNode *const pSttNode,
1151cdf0e10cSrcweir     SwFrmFmt const*const pFrmFmt, SwFrmFmt*& rpFormat)
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir     bool bRet = false;
1154cdf0e10cSrcweir     const SfxItemSet& rSet = pFrmFmt->GetAttrSet();
1155cdf0e10cSrcweir     const SfxPoolItem* pItem;
1156cdf0e10cSrcweir     if (SFX_ITEM_SET == rSet.GetItemState(
1157cdf0e10cSrcweir             static_cast<sal_uInt16>(bHeader ? RES_HEADER : RES_FOOTER),
1158cdf0e10cSrcweir             sal_True, &pItem))
1159cdf0e10cSrcweir     {
1160cdf0e10cSrcweir         SfxPoolItem *const pItemNonConst(const_cast<SfxPoolItem *>(pItem));
1161cdf0e10cSrcweir         SwFrmFmt *const pHeadFootFmt = (bHeader) ?
1162cdf0e10cSrcweir             static_cast<SwFmtHeader*>(pItemNonConst)->GetHeaderFmt() :
1163cdf0e10cSrcweir             static_cast<SwFmtFooter*>(pItemNonConst)->GetFooterFmt();
1164cdf0e10cSrcweir         if (pHeadFootFmt)
1165cdf0e10cSrcweir         {
1166cdf0e10cSrcweir             const SwFmtCntnt& rFlyCntnt = pHeadFootFmt->GetCntnt();
1167cdf0e10cSrcweir             const SwNode& rNode = rFlyCntnt.GetCntntIdx()->GetNode();
1168cdf0e10cSrcweir             SwStartNode const*const pCurSttNode = rNode.FindSttNodeByType(
1169cdf0e10cSrcweir                 (bHeader) ? SwHeaderStartNode : SwFooterStartNode);
1170cdf0e10cSrcweir             if (pCurSttNode && (pCurSttNode == pSttNode))
1171cdf0e10cSrcweir             {
1172cdf0e10cSrcweir                 rpFormat = pHeadFootFmt;
1173cdf0e10cSrcweir                 bRet = true;
1174cdf0e10cSrcweir             }
1175cdf0e10cSrcweir         }
1176cdf0e10cSrcweir     }
1177cdf0e10cSrcweir     return bRet;
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir } // namespace sw
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir uno::Reference< text::XTextRange >
CreateXTextRange(SwDoc & rDoc,const SwPosition & rPos,const SwPosition * const pMark)1183cdf0e10cSrcweir SwXTextRange::CreateXTextRange(
1184cdf0e10cSrcweir     SwDoc & rDoc, const SwPosition& rPos, const SwPosition *const pMark)
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir     const uno::Reference<text::XText> xParentText(
1187cdf0e10cSrcweir             ::sw::CreateParentXText(rDoc, rPos));
1188cdf0e10cSrcweir     const ::std::auto_ptr<SwUnoCrsr> pNewCrsr(
1189cdf0e10cSrcweir             rDoc.CreateUnoCrsr(rPos, sal_False));
1190cdf0e10cSrcweir     if(pMark)
1191cdf0e10cSrcweir     {
1192cdf0e10cSrcweir         pNewCrsr->SetMark();
1193cdf0e10cSrcweir         *pNewCrsr->GetMark() = *pMark;
1194cdf0e10cSrcweir     }
1195cdf0e10cSrcweir     const bool isCell( dynamic_cast<SwXCell*>(xParentText.get()) );
1196cdf0e10cSrcweir     const uno::Reference< text::XTextRange > xRet(
1197cdf0e10cSrcweir         new SwXTextRange(*pNewCrsr, xParentText,
1198cdf0e10cSrcweir             isCell ? RANGE_IN_CELL : RANGE_IN_TEXT) );
1199cdf0e10cSrcweir     return xRet;
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir namespace sw {
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir uno::Reference< text::XText >
CreateParentXText(SwDoc & rDoc,const SwPosition & rPos)1205cdf0e10cSrcweir CreateParentXText(SwDoc & rDoc, const SwPosition& rPos)
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir     uno::Reference< text::XText > xParentText;
1208cdf0e10cSrcweir     SwStartNode* pSttNode = rPos.nNode.GetNode().StartOfSectionNode();
1209cdf0e10cSrcweir     while(pSttNode && pSttNode->IsSectionNode())
1210cdf0e10cSrcweir     {
1211cdf0e10cSrcweir         pSttNode = pSttNode->StartOfSectionNode();
1212cdf0e10cSrcweir     }
1213cdf0e10cSrcweir     SwStartNodeType eType = pSttNode->GetStartNodeType();
1214cdf0e10cSrcweir     switch(eType)
1215cdf0e10cSrcweir     {
1216cdf0e10cSrcweir         case SwTableBoxStartNode:
1217cdf0e10cSrcweir         {
1218cdf0e10cSrcweir             SwTableNode const*const pTblNode = pSttNode->FindTableNode();
1219cdf0e10cSrcweir             SwFrmFmt *const pTableFmt =
1220cdf0e10cSrcweir                 static_cast<SwFrmFmt*>(pTblNode->GetTable().GetFrmFmt());
1221cdf0e10cSrcweir             SwTableBox *const  pBox = pSttNode->GetTblBox();
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir             xParentText = (pBox)
1224cdf0e10cSrcweir                 ? SwXCell::CreateXCell( pTableFmt, pBox )
1225cdf0e10cSrcweir                 : new SwXCell( pTableFmt, *pSttNode );
1226cdf0e10cSrcweir         }
1227cdf0e10cSrcweir         break;
1228cdf0e10cSrcweir         case SwFlyStartNode:
1229cdf0e10cSrcweir         {
1230cdf0e10cSrcweir             SwFrmFmt *const pFmt = pSttNode->GetFlyFmt();
1231cdf0e10cSrcweir             if (0 != pFmt)
1232cdf0e10cSrcweir             {
1233cdf0e10cSrcweir                 SwXTextFrame* pFrame = SwIterator<SwXTextFrame,SwFmt>::FirstElement( *pFmt );
1234cdf0e10cSrcweir                 xParentText = pFrame ? pFrame : new SwXTextFrame( *pFmt );
1235cdf0e10cSrcweir             }
1236cdf0e10cSrcweir         }
1237cdf0e10cSrcweir         break;
1238cdf0e10cSrcweir         case SwHeaderStartNode:
1239cdf0e10cSrcweir         case SwFooterStartNode:
1240cdf0e10cSrcweir         {
1241cdf0e10cSrcweir             const bool bHeader = (SwHeaderStartNode == eType);
1242cdf0e10cSrcweir             const sal_uInt16 nPDescCount = rDoc.GetPageDescCnt();
1243cdf0e10cSrcweir             for(sal_uInt16 i = 0; i < nPDescCount; i++)
1244cdf0e10cSrcweir             {
1245cdf0e10cSrcweir                 const SwPageDesc& rDesc =
1246cdf0e10cSrcweir                     // C++ is retarded
1247cdf0e10cSrcweir                     const_cast<SwDoc const&>(rDoc).GetPageDesc( i );
1248cdf0e10cSrcweir                 const SwFrmFmt* pFrmFmtMaster = &rDesc.GetMaster();
1249cdf0e10cSrcweir                 const SwFrmFmt* pFrmFmtLeft = &rDesc.GetLeft();
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir                 SwFrmFmt* pHeadFootFmt = 0;
1252cdf0e10cSrcweir                 if (!lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrmFmtMaster,
1253cdf0e10cSrcweir                             pHeadFootFmt))
1254cdf0e10cSrcweir                 {
1255cdf0e10cSrcweir                     lcl_IsStartNodeInFormat(bHeader, pSttNode, pFrmFmtLeft,
1256cdf0e10cSrcweir                             pHeadFootFmt);
1257cdf0e10cSrcweir                 }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir                 if (pHeadFootFmt)
1260cdf0e10cSrcweir                 {
1261cdf0e10cSrcweir                     xParentText = SwXHeadFootText::CreateXHeadFootText(
1262cdf0e10cSrcweir                             *pHeadFootFmt, bHeader);
1263cdf0e10cSrcweir                 }
1264cdf0e10cSrcweir             }
1265cdf0e10cSrcweir         }
1266cdf0e10cSrcweir         break;
1267cdf0e10cSrcweir         case SwFootnoteStartNode:
1268cdf0e10cSrcweir         {
1269cdf0e10cSrcweir             const sal_uInt16 nFtnCnt = rDoc.GetFtnIdxs().Count();
1270cdf0e10cSrcweir             uno::Reference< text::XFootnote >  xRef;
1271cdf0e10cSrcweir             for (sal_uInt16 n = 0; n < nFtnCnt; ++n )
1272cdf0e10cSrcweir             {
1273cdf0e10cSrcweir                 const SwTxtFtn* pTxtFtn = rDoc.GetFtnIdxs()[ n ];
1274cdf0e10cSrcweir                 const SwFmtFtn& rFtn = pTxtFtn->GetFtn();
1275cdf0e10cSrcweir                 pTxtFtn = rFtn.GetTxtFtn();
1276cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1277cdf0e10cSrcweir                 const SwStartNode* pTmpSttNode =
1278cdf0e10cSrcweir                         pTxtFtn->GetStartNode()->GetNode().
1279cdf0e10cSrcweir                                 FindSttNodeByType(SwFootnoteStartNode);
1280cdf0e10cSrcweir                 (void)pTmpSttNode;
1281cdf0e10cSrcweir #endif
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir                 if (pSttNode == pTxtFtn->GetStartNode()->GetNode().
1284cdf0e10cSrcweir                                     FindSttNodeByType(SwFootnoteStartNode))
1285cdf0e10cSrcweir                 {
1286cdf0e10cSrcweir                     xParentText = SwXFootnote::CreateXFootnote(rDoc, rFtn);
1287cdf0e10cSrcweir                     break;
1288cdf0e10cSrcweir                 }
1289cdf0e10cSrcweir             }
1290cdf0e10cSrcweir         }
1291cdf0e10cSrcweir         break;
1292cdf0e10cSrcweir         default:
1293cdf0e10cSrcweir         {
1294cdf0e10cSrcweir             // then it is the body text
1295cdf0e10cSrcweir             const uno::Reference<frame::XModel> xModel =
1296cdf0e10cSrcweir                 rDoc.GetDocShell()->GetBaseModel();
1297cdf0e10cSrcweir             const uno::Reference< text::XTextDocument > xDoc(
1298cdf0e10cSrcweir                 xModel, uno::UNO_QUERY);
1299cdf0e10cSrcweir             xParentText = xDoc->getText();
1300cdf0e10cSrcweir         }
1301cdf0e10cSrcweir     }
1302cdf0e10cSrcweir     OSL_ENSURE(xParentText.is(), "no parent text?");
1303cdf0e10cSrcweir     return xParentText;
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir } // namespace sw
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL
createContentEnumeration(const OUString & rServiceName)1309cdf0e10cSrcweir SwXTextRange::createContentEnumeration(const OUString& rServiceName)
1310cdf0e10cSrcweir throw (uno::RuntimeException)
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir     if (!rServiceName.equalsAscii("com.sun.star.text.TextContent"))
1315cdf0e10cSrcweir     {
1316cdf0e10cSrcweir         throw uno::RuntimeException();
1317cdf0e10cSrcweir     }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1320cdf0e10cSrcweir     {
1321cdf0e10cSrcweir         throw uno::RuntimeException();
1322cdf0e10cSrcweir     }
1323cdf0e10cSrcweir     const SwPosition aPos(GetDoc()->GetNodes().GetEndOfContent());
1324cdf0e10cSrcweir     const ::std::auto_ptr<SwUnoCrsr> pNewCrsr(
1325cdf0e10cSrcweir             m_pImpl->m_rDoc.CreateUnoCrsr(aPos, sal_False));
1326cdf0e10cSrcweir     if (!GetPositions(*pNewCrsr))
1327cdf0e10cSrcweir     {
1328cdf0e10cSrcweir         throw uno::RuntimeException();
1329cdf0e10cSrcweir     }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir     const uno::Reference< container::XEnumeration > xRet =
1332cdf0e10cSrcweir         new SwXParaFrameEnumeration(*pNewCrsr, PARAFRAME_PORTION_TEXTRANGE);
1333cdf0e10cSrcweir     return xRet;
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir uno::Reference< container::XEnumeration > SAL_CALL
createEnumeration()1337cdf0e10cSrcweir SwXTextRange::createEnumeration() throw (uno::RuntimeException)
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1342cdf0e10cSrcweir     {
1343cdf0e10cSrcweir         throw uno::RuntimeException();
1344cdf0e10cSrcweir     }
1345cdf0e10cSrcweir     const SwPosition aPos(GetDoc()->GetNodes().GetEndOfContent());
1346cdf0e10cSrcweir     ::std::auto_ptr<SwUnoCrsr> pNewCrsr(
1347cdf0e10cSrcweir             m_pImpl->m_rDoc.CreateUnoCrsr(aPos, sal_False));
1348cdf0e10cSrcweir     if (!GetPositions(*pNewCrsr))
1349cdf0e10cSrcweir     {
1350cdf0e10cSrcweir         throw uno::RuntimeException();
1351cdf0e10cSrcweir     }
1352cdf0e10cSrcweir     if (!m_pImpl->m_xParentText.is())
1353cdf0e10cSrcweir     {
1354cdf0e10cSrcweir         getText();
1355cdf0e10cSrcweir     }
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir     const CursorType eSetType = (RANGE_IN_CELL == m_pImpl->m_eRangePosition)
1358cdf0e10cSrcweir             ? CURSOR_SELECTION_IN_TABLE : CURSOR_SELECTION;
1359cdf0e10cSrcweir     const uno::Reference< container::XEnumeration > xRet =
1360cdf0e10cSrcweir         new SwXParagraphEnumeration(m_pImpl->m_xParentText, pNewCrsr, eSetType);
1361cdf0e10cSrcweir     return xRet;
1362cdf0e10cSrcweir }
1363cdf0e10cSrcweir 
getElementType()1364cdf0e10cSrcweir uno::Type SAL_CALL SwXTextRange::getElementType() throw (uno::RuntimeException)
1365cdf0e10cSrcweir {
1366cdf0e10cSrcweir     return text::XTextRange::static_type();
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir 
hasElements()1369cdf0e10cSrcweir sal_Bool SAL_CALL SwXTextRange::hasElements() throw (uno::RuntimeException)
1370cdf0e10cSrcweir {
1371cdf0e10cSrcweir     return sal_True;
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL
getAvailableServiceNames()1375cdf0e10cSrcweir SwXTextRange::getAvailableServiceNames() throw (uno::RuntimeException)
1376cdf0e10cSrcweir {
1377cdf0e10cSrcweir     uno::Sequence< OUString > aRet(1);
1378cdf0e10cSrcweir     OUString* pArray = aRet.getArray();
1379cdf0e10cSrcweir     pArray[0] = OUString::createFromAscii("com.sun.star.text.TextContent");
1380cdf0e10cSrcweir     return aRet;
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL
getPropertySetInfo()1384cdf0e10cSrcweir SwXTextRange::getPropertySetInfo() throw (uno::RuntimeException)
1385cdf0e10cSrcweir {
1386cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir     static uno::Reference< beans::XPropertySetInfo > xRef =
1389cdf0e10cSrcweir         m_pImpl->m_rPropSet.getPropertySetInfo();
1390cdf0e10cSrcweir 	return xRef;
1391cdf0e10cSrcweir }
1392cdf0e10cSrcweir 
1393cdf0e10cSrcweir void SAL_CALL
setPropertyValue(const OUString & rPropertyName,const uno::Any & rValue)1394cdf0e10cSrcweir SwXTextRange::setPropertyValue(
1395cdf0e10cSrcweir         const OUString& rPropertyName, const uno::Any& rValue)
1396cdf0e10cSrcweir throw (beans::UnknownPropertyException, beans::PropertyVetoException,
1397cdf0e10cSrcweir         lang::IllegalArgumentException, lang::WrappedTargetException,
1398cdf0e10cSrcweir         uno::RuntimeException)
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1403cdf0e10cSrcweir     {
1404cdf0e10cSrcweir         throw uno::RuntimeException();
1405cdf0e10cSrcweir     }
1406cdf0e10cSrcweir 	SwPaM aPaM(GetDoc()->GetNodes());
1407cdf0e10cSrcweir     GetPositions(aPaM);
1408cdf0e10cSrcweir     SwUnoCursorHelper::SetPropertyValue(aPaM, m_pImpl->m_rPropSet,
1409cdf0e10cSrcweir             rPropertyName, rValue);
1410cdf0e10cSrcweir }
1411cdf0e10cSrcweir 
1412cdf0e10cSrcweir uno::Any SAL_CALL
getPropertyValue(const OUString & rPropertyName)1413cdf0e10cSrcweir SwXTextRange::getPropertyValue(const OUString& rPropertyName)
1414cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1415cdf0e10cSrcweir         uno::RuntimeException)
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1420cdf0e10cSrcweir     {
1421cdf0e10cSrcweir         throw uno::RuntimeException();
1422cdf0e10cSrcweir     }
1423cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1424cdf0e10cSrcweir     GetPositions(aPaM);
1425cdf0e10cSrcweir     return SwUnoCursorHelper::GetPropertyValue(aPaM, m_pImpl->m_rPropSet,
1426cdf0e10cSrcweir             rPropertyName);
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir void SAL_CALL
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1430cdf0e10cSrcweir SwXTextRange::addPropertyChangeListener(
1431cdf0e10cSrcweir         const ::rtl::OUString& /*rPropertyName*/,
1432cdf0e10cSrcweir         const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1433cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1434cdf0e10cSrcweir     uno::RuntimeException)
1435cdf0e10cSrcweir {
1436cdf0e10cSrcweir     OSL_ENSURE(false,
1437cdf0e10cSrcweir         "SwXTextRange::addPropertyChangeListener(): not implemented");
1438cdf0e10cSrcweir }
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir void SAL_CALL
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1441cdf0e10cSrcweir SwXTextRange::removePropertyChangeListener(
1442cdf0e10cSrcweir         const ::rtl::OUString& /*rPropertyName*/,
1443cdf0e10cSrcweir         const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
1444cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1445cdf0e10cSrcweir     uno::RuntimeException)
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir     OSL_ENSURE(false,
1448cdf0e10cSrcweir         "SwXTextRange::removePropertyChangeListener(): not implemented");
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir void SAL_CALL
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1452cdf0e10cSrcweir SwXTextRange::addVetoableChangeListener(
1453cdf0e10cSrcweir         const ::rtl::OUString& /*rPropertyName*/,
1454cdf0e10cSrcweir         const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1455cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1456cdf0e10cSrcweir     uno::RuntimeException)
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir     OSL_ENSURE(false,
1459cdf0e10cSrcweir         "SwXTextRange::addVetoableChangeListener(): not implemented");
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir void SAL_CALL
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1463cdf0e10cSrcweir SwXTextRange::removeVetoableChangeListener(
1464cdf0e10cSrcweir         const ::rtl::OUString& /*rPropertyName*/,
1465cdf0e10cSrcweir         const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
1466cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1467cdf0e10cSrcweir         uno::RuntimeException)
1468cdf0e10cSrcweir {
1469cdf0e10cSrcweir     OSL_ENSURE(false,
1470cdf0e10cSrcweir         "SwXTextRange::removeVetoableChangeListener(): not implemented");
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir beans::PropertyState SAL_CALL
getPropertyState(const OUString & rPropertyName)1474cdf0e10cSrcweir SwXTextRange::getPropertyState(const OUString& rPropertyName)
1475cdf0e10cSrcweir throw (beans::UnknownPropertyException, uno::RuntimeException)
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1478cdf0e10cSrcweir 
1479cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1480cdf0e10cSrcweir     {
1481cdf0e10cSrcweir         throw uno::RuntimeException();
1482cdf0e10cSrcweir     }
1483cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1484cdf0e10cSrcweir     GetPositions(aPaM);
1485cdf0e10cSrcweir     return SwUnoCursorHelper::GetPropertyState(aPaM, m_pImpl->m_rPropSet,
1486cdf0e10cSrcweir             rPropertyName);
1487cdf0e10cSrcweir }
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir uno::Sequence< beans::PropertyState > SAL_CALL
getPropertyStates(const uno::Sequence<OUString> & rPropertyName)1490cdf0e10cSrcweir SwXTextRange::getPropertyStates(const uno::Sequence< OUString >& rPropertyName)
1491cdf0e10cSrcweir throw (beans::UnknownPropertyException, uno::RuntimeException)
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir     vos::OGuard g(Application::GetSolarMutex());
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1496cdf0e10cSrcweir     {
1497cdf0e10cSrcweir         throw uno::RuntimeException();
1498cdf0e10cSrcweir     }
1499cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1500cdf0e10cSrcweir     GetPositions(aPaM);
1501cdf0e10cSrcweir     return SwUnoCursorHelper::GetPropertyStates(aPaM, m_pImpl->m_rPropSet,
1502cdf0e10cSrcweir             rPropertyName);
1503cdf0e10cSrcweir }
1504cdf0e10cSrcweir 
setPropertyToDefault(const OUString & rPropertyName)1505cdf0e10cSrcweir void SAL_CALL SwXTextRange::setPropertyToDefault(const OUString& rPropertyName)
1506cdf0e10cSrcweir throw (beans::UnknownPropertyException, uno::RuntimeException)
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1511cdf0e10cSrcweir     {
1512cdf0e10cSrcweir         throw uno::RuntimeException();
1513cdf0e10cSrcweir     }
1514cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1515cdf0e10cSrcweir     GetPositions(aPaM);
1516cdf0e10cSrcweir     SwUnoCursorHelper::SetPropertyToDefault(aPaM, m_pImpl->m_rPropSet,
1517cdf0e10cSrcweir             rPropertyName);
1518cdf0e10cSrcweir }
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir uno::Any SAL_CALL
getPropertyDefault(const OUString & rPropertyName)1521cdf0e10cSrcweir SwXTextRange::getPropertyDefault(const OUString& rPropertyName)
1522cdf0e10cSrcweir throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1523cdf0e10cSrcweir         uno::RuntimeException)
1524cdf0e10cSrcweir {
1525cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1528cdf0e10cSrcweir     {
1529cdf0e10cSrcweir         throw uno::RuntimeException();
1530cdf0e10cSrcweir     }
1531cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1532cdf0e10cSrcweir     GetPositions(aPaM);
1533cdf0e10cSrcweir     return SwUnoCursorHelper::GetPropertyDefault(aPaM, m_pImpl->m_rPropSet,
1534cdf0e10cSrcweir             rPropertyName);
1535cdf0e10cSrcweir }
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir void SAL_CALL
makeRedline(const::rtl::OUString & rRedlineType,const uno::Sequence<beans::PropertyValue> & rRedlineProperties)1538cdf0e10cSrcweir SwXTextRange::makeRedline(
1539cdf0e10cSrcweir     const ::rtl::OUString& rRedlineType,
1540cdf0e10cSrcweir     const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
1541cdf0e10cSrcweir throw (lang::IllegalArgumentException, uno::RuntimeException)
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir     vos::OGuard aGuard(Application::GetSolarMutex());
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir     if (!GetDoc() || !m_pImpl->GetBookmark())
1546cdf0e10cSrcweir     {
1547cdf0e10cSrcweir         throw uno::RuntimeException();
1548cdf0e10cSrcweir     }
1549cdf0e10cSrcweir     SwPaM aPaM(GetDoc()->GetNodes());
1550cdf0e10cSrcweir     SwXTextRange::GetPositions(aPaM);
1551cdf0e10cSrcweir     SwUnoCursorHelper::makeRedline( aPaM, rRedlineType, rRedlineProperties );
1552cdf0e10cSrcweir }
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir /******************************************************************
1555cdf0e10cSrcweir  * SwXTextRanges
1556cdf0e10cSrcweir  ******************************************************************/
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir class SwXTextRanges::Impl
1559cdf0e10cSrcweir     : public SwClient
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir public:
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir     ::std::vector< uno::Reference< text::XTextRange > > m_Ranges;
1565cdf0e10cSrcweir 
Impl(SwPaM * const pPaM)1566cdf0e10cSrcweir     Impl(SwPaM *const pPaM)
1567cdf0e10cSrcweir         : SwClient( (pPaM)
1568cdf0e10cSrcweir             ? pPaM->GetDoc()->CreateUnoCrsr(*pPaM->GetPoint())
1569cdf0e10cSrcweir             : 0 )
1570cdf0e10cSrcweir     {
1571cdf0e10cSrcweir         if (pPaM)
1572cdf0e10cSrcweir         {
1573cdf0e10cSrcweir             ::sw::DeepCopyPaM(*pPaM, *GetCursor());
1574cdf0e10cSrcweir         }
1575cdf0e10cSrcweir         MakeRanges();
1576cdf0e10cSrcweir     }
1577cdf0e10cSrcweir 
~Impl()1578cdf0e10cSrcweir     ~Impl() {
1579cdf0e10cSrcweir         // Impl owns the cursor; delete it here: SolarMutex is locked
1580cdf0e10cSrcweir         delete GetRegisteredIn();
1581cdf0e10cSrcweir     }
1582cdf0e10cSrcweir 
GetCursor()1583cdf0e10cSrcweir     SwUnoCrsr * GetCursor() {
1584cdf0e10cSrcweir         return static_cast<SwUnoCrsr*>(
1585cdf0e10cSrcweir                 const_cast<SwModify*>(GetRegisteredIn()));
1586cdf0e10cSrcweir     }
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir     void MakeRanges();
1589cdf0e10cSrcweir protected:
1590cdf0e10cSrcweir     // SwClient
1591cdf0e10cSrcweir     virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew);
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir };
1594cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1595cdf0e10cSrcweir void SwXTextRanges::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir     ClientModify(this, pOld, pNew);
1598cdf0e10cSrcweir }
1599cdf0e10cSrcweir 
MakeRanges()1600cdf0e10cSrcweir void SwXTextRanges::Impl::MakeRanges()
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir     SwUnoCrsr *const pCursor = GetCursor();
1603cdf0e10cSrcweir     if (pCursor)
1604cdf0e10cSrcweir     {
1605cdf0e10cSrcweir         SwPaM *pTmpCursor = pCursor;
1606cdf0e10cSrcweir         do {
1607cdf0e10cSrcweir             const uno::Reference< text::XTextRange > xRange(
1608cdf0e10cSrcweir                     SwXTextRange::CreateXTextRange(
1609cdf0e10cSrcweir                         *pTmpCursor->GetDoc(),
1610cdf0e10cSrcweir                         *pTmpCursor->GetPoint(), pTmpCursor->GetMark()));
1611cdf0e10cSrcweir             if (xRange.is())
1612cdf0e10cSrcweir             {
1613cdf0e10cSrcweir                 m_Ranges.push_back(xRange);
1614cdf0e10cSrcweir             }
1615cdf0e10cSrcweir             pTmpCursor = static_cast<SwPaM*>(pTmpCursor->GetNext());
1616cdf0e10cSrcweir         }
1617cdf0e10cSrcweir         while (pTmpCursor != pCursor);
1618cdf0e10cSrcweir     }
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir 
GetCursor() const1621cdf0e10cSrcweir const SwUnoCrsr* SwXTextRanges::GetCursor() const
1622cdf0e10cSrcweir {
1623cdf0e10cSrcweir     return m_pImpl->GetCursor();
1624cdf0e10cSrcweir }
1625cdf0e10cSrcweir 
SwXTextRanges(SwPaM * const pPaM)1626cdf0e10cSrcweir SwXTextRanges::SwXTextRanges(SwPaM *const pPaM)
1627cdf0e10cSrcweir     : m_pImpl( new SwXTextRanges::Impl(pPaM) )
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir }
1630cdf0e10cSrcweir 
~SwXTextRanges()1631cdf0e10cSrcweir SwXTextRanges::~SwXTextRanges()
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir }
1634cdf0e10cSrcweir 
getUnoTunnelId()1635cdf0e10cSrcweir const uno::Sequence< sal_Int8 > & SwXTextRanges::getUnoTunnelId()
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir     static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
1638cdf0e10cSrcweir 	return aSeq;
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir sal_Int64 SAL_CALL
getSomething(const uno::Sequence<sal_Int8> & rId)1642cdf0e10cSrcweir SwXTextRanges::getSomething(const uno::Sequence< sal_Int8 >& rId)
1643cdf0e10cSrcweir throw (uno::RuntimeException)
1644cdf0e10cSrcweir {
1645cdf0e10cSrcweir     return ::sw::UnoTunnelImpl<SwXTextRanges>(rId, this);
1646cdf0e10cSrcweir }
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir /****************************************************************************
1649cdf0e10cSrcweir  *	Text positions
1650cdf0e10cSrcweir  * 	Bis zum ersten Zugriff auf eine TextPosition wird ein SwCursor gehalten,
1651cdf0e10cSrcweir  * danach wird ein Array mit uno::Reference< XTextPosition >  angelegt
1652cdf0e10cSrcweir  *
1653cdf0e10cSrcweir ****************************************************************************/
1654cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()1655cdf0e10cSrcweir SwXTextRanges::getImplementationName() throw (uno::RuntimeException)
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir 	return C2U("SwXTextRanges");
1658cdf0e10cSrcweir }
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir static char const*const g_ServicesTextRanges[] =
1661cdf0e10cSrcweir {
1662cdf0e10cSrcweir     "com.sun.star.text.TextRanges",
1663cdf0e10cSrcweir };
1664cdf0e10cSrcweir static const size_t g_nServicesTextRanges(
1665cdf0e10cSrcweir     sizeof(g_ServicesTextRanges)/sizeof(g_ServicesTextRanges[0]));
1666cdf0e10cSrcweir 
supportsService(const OUString & rServiceName)1667cdf0e10cSrcweir sal_Bool SAL_CALL SwXTextRanges::supportsService(const OUString& rServiceName)
1668cdf0e10cSrcweir throw (uno::RuntimeException)
1669cdf0e10cSrcweir {
1670cdf0e10cSrcweir     return ::sw::SupportsServiceImpl(
1671cdf0e10cSrcweir             g_nServicesTextRanges, g_ServicesTextRanges, rServiceName);
1672cdf0e10cSrcweir }
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL
getSupportedServiceNames()1675cdf0e10cSrcweir SwXTextRanges::getSupportedServiceNames() throw (uno::RuntimeException)
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir     return ::sw::GetSupportedServiceNamesImpl(
1678cdf0e10cSrcweir             g_nServicesTextRanges, g_ServicesTextRanges);
1679cdf0e10cSrcweir }
1680cdf0e10cSrcweir 
getCount()1681cdf0e10cSrcweir sal_Int32 SAL_CALL SwXTextRanges::getCount() throw (uno::RuntimeException)
1682cdf0e10cSrcweir {
1683cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1684cdf0e10cSrcweir 
1685cdf0e10cSrcweir     return static_cast<sal_Int32>(m_pImpl->m_Ranges.size());
1686cdf0e10cSrcweir }
1687cdf0e10cSrcweir 
getByIndex(sal_Int32 nIndex)1688cdf0e10cSrcweir uno::Any SAL_CALL SwXTextRanges::getByIndex(sal_Int32 nIndex)
1689cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
1690cdf0e10cSrcweir         uno::RuntimeException)
1691cdf0e10cSrcweir {
1692cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir     if ((nIndex < 0) ||
1695cdf0e10cSrcweir         (static_cast<size_t>(nIndex) >= m_pImpl->m_Ranges.size()))
1696cdf0e10cSrcweir     {
1697cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
1698cdf0e10cSrcweir     }
1699cdf0e10cSrcweir     uno::Any ret;
1700cdf0e10cSrcweir     ret <<= (m_pImpl->m_Ranges.at(nIndex));
1701cdf0e10cSrcweir     return ret;
1702cdf0e10cSrcweir }
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir uno::Type SAL_CALL
getElementType()1705cdf0e10cSrcweir SwXTextRanges::getElementType() throw (uno::RuntimeException)
1706cdf0e10cSrcweir {
1707cdf0e10cSrcweir     return text::XTextRange::static_type();
1708cdf0e10cSrcweir }
1709cdf0e10cSrcweir 
hasElements()1710cdf0e10cSrcweir sal_Bool SAL_CALL SwXTextRanges::hasElements() throw (uno::RuntimeException)
1711cdf0e10cSrcweir {
1712cdf0e10cSrcweir     // no mutex necessary: getCount() does locking
1713cdf0e10cSrcweir 	return getCount() > 0;
1714cdf0e10cSrcweir }
1715cdf0e10cSrcweir 
SetString(SwCursor & rCursor,const OUString & rString)1716cdf0e10cSrcweir void SwUnoCursorHelper::SetString(SwCursor & rCursor, const OUString& rString)
1717cdf0e10cSrcweir {
1718cdf0e10cSrcweir 	// Start/EndAction
1719cdf0e10cSrcweir     SwDoc *const pDoc = rCursor.GetDoc();
1720cdf0e10cSrcweir 	UnoActionContext aAction(pDoc);
1721cdf0e10cSrcweir     pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
1722cdf0e10cSrcweir     if (rCursor.HasMark())
1723cdf0e10cSrcweir     {
1724cdf0e10cSrcweir         pDoc->DeleteAndJoin(rCursor);
1725cdf0e10cSrcweir     }
1726cdf0e10cSrcweir     if (rString.getLength())
1727cdf0e10cSrcweir     {
1728cdf0e10cSrcweir         String aText(rString);
1729cdf0e10cSrcweir         const bool bSuccess( SwUnoCursorHelper::DocInsertStringSplitCR(
1730cdf0e10cSrcweir                     *pDoc, rCursor, aText, false ) );
1731cdf0e10cSrcweir         DBG_ASSERT( bSuccess, "DocInsertStringSplitCR" );
1732cdf0e10cSrcweir         (void) bSuccess;
1733cdf0e10cSrcweir         SwUnoCursorHelper::SelectPam(rCursor, true);
1734cdf0e10cSrcweir         rCursor.Left(rString.getLength(), CRSR_SKIP_CHARS, sal_False, sal_False);
1735cdf0e10cSrcweir     }
1736cdf0e10cSrcweir     pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
1737cdf0e10cSrcweir }
1738cdf0e10cSrcweir 
1739cdf0e10cSrcweir /******************************************************************
1740cdf0e10cSrcweir  * SwXParaFrameEnumeration
1741cdf0e10cSrcweir  ******************************************************************/
1742cdf0e10cSrcweir 
1743cdf0e10cSrcweir class SwXParaFrameEnumeration::Impl
1744cdf0e10cSrcweir     : public SwClient
1745cdf0e10cSrcweir {
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir public:
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir     // created by hasMoreElements
1750cdf0e10cSrcweir     uno::Reference< text::XTextContent > m_xNextObject;
1751cdf0e10cSrcweir     FrameDependList_t m_Frames;
1752cdf0e10cSrcweir 
Impl(SwPaM const & rPaM)1753cdf0e10cSrcweir     Impl(SwPaM const & rPaM)
1754cdf0e10cSrcweir         : SwClient(rPaM.GetDoc()->CreateUnoCrsr(*rPaM.GetPoint(), sal_False))
1755cdf0e10cSrcweir     {
1756cdf0e10cSrcweir         if (rPaM.HasMark())
1757cdf0e10cSrcweir         {
1758cdf0e10cSrcweir             GetCursor()->SetMark();
1759cdf0e10cSrcweir             *GetCursor()->GetMark() = *rPaM.GetMark();
1760cdf0e10cSrcweir         }
1761cdf0e10cSrcweir     }
1762cdf0e10cSrcweir 
~Impl()1763cdf0e10cSrcweir     ~Impl() {
1764cdf0e10cSrcweir         // Impl owns the cursor; delete it here: SolarMutex is locked
1765cdf0e10cSrcweir         delete GetRegisteredIn();
1766cdf0e10cSrcweir     }
1767cdf0e10cSrcweir 
GetCursor()1768cdf0e10cSrcweir     SwUnoCrsr * GetCursor() {
1769cdf0e10cSrcweir         return static_cast<SwUnoCrsr*>(
1770cdf0e10cSrcweir                 const_cast<SwModify*>(GetRegisteredIn()));
1771cdf0e10cSrcweir     }
1772cdf0e10cSrcweir protected:
1773cdf0e10cSrcweir     // SwClient
1774cdf0e10cSrcweir     virtual void Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew);
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir };
1777cdf0e10cSrcweir 
1778cdf0e10cSrcweir struct InvalidFrameDepend {
operator ()InvalidFrameDepend1779cdf0e10cSrcweir     bool operator() (::boost::shared_ptr<SwDepend> const & rEntry)
1780cdf0e10cSrcweir     { return !rEntry->GetRegisteredIn(); }
1781cdf0e10cSrcweir };
1782cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1783cdf0e10cSrcweir void SwXParaFrameEnumeration::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
1784cdf0e10cSrcweir {
1785cdf0e10cSrcweir     ClientModify(this, pOld, pNew);
1786cdf0e10cSrcweir     if(!GetRegisteredIn())
1787cdf0e10cSrcweir     {
1788cdf0e10cSrcweir         m_Frames.clear();
1789cdf0e10cSrcweir         m_xNextObject = 0;
1790cdf0e10cSrcweir     }
1791cdf0e10cSrcweir     else
1792cdf0e10cSrcweir     {
1793cdf0e10cSrcweir         // check if any frame went away...
1794cdf0e10cSrcweir         FrameDependList_t::iterator const iter =
1795cdf0e10cSrcweir             ::std::remove_if(m_Frames.begin(), m_Frames.end(),
1796cdf0e10cSrcweir                     InvalidFrameDepend());
1797cdf0e10cSrcweir         m_Frames.erase(iter, m_Frames.end());
1798cdf0e10cSrcweir     }
1799cdf0e10cSrcweir }
1800cdf0e10cSrcweir 
1801cdf0e10cSrcweir static sal_Bool
lcl_CreateNextObject(SwUnoCrsr & i_rUnoCrsr,uno::Reference<text::XTextContent> & o_rNextObject,FrameDependList_t & i_rFrames)1802cdf0e10cSrcweir lcl_CreateNextObject(SwUnoCrsr& i_rUnoCrsr,
1803cdf0e10cSrcweir         uno::Reference<text::XTextContent> & o_rNextObject,
1804cdf0e10cSrcweir         FrameDependList_t & i_rFrames)
1805cdf0e10cSrcweir {
1806cdf0e10cSrcweir     if (!i_rFrames.size())
1807cdf0e10cSrcweir         return sal_False;
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir     SwFrmFmt *const pFormat = static_cast<SwFrmFmt*>(const_cast<SwModify*>(
1810cdf0e10cSrcweir                 i_rFrames.front()->GetRegisteredIn()));
1811cdf0e10cSrcweir     i_rFrames.pop_front();
1812cdf0e10cSrcweir     // the format should be valid here, otherwise the client
1813cdf0e10cSrcweir     // would have been removed in ::Modify
1814cdf0e10cSrcweir     // check for a shape first
1815cdf0e10cSrcweir     SwDrawContact* const pContact = SwIterator<SwDrawContact,SwFmt>::FirstElement( *pFormat );
1816cdf0e10cSrcweir     if (pContact)
1817cdf0e10cSrcweir     {
1818cdf0e10cSrcweir         SdrObject * const pSdr = pContact->GetMaster();
1819cdf0e10cSrcweir         if (pSdr)
1820cdf0e10cSrcweir         {
1821cdf0e10cSrcweir             o_rNextObject.set(pSdr->getUnoShape(), uno::UNO_QUERY);
1822cdf0e10cSrcweir         }
1823cdf0e10cSrcweir     }
1824cdf0e10cSrcweir     else
1825cdf0e10cSrcweir     {
1826cdf0e10cSrcweir         const SwNodeIndex* pIdx = pFormat->GetCntnt().GetCntntIdx();
1827cdf0e10cSrcweir         DBG_ASSERT(pIdx, "where is the index?");
1828cdf0e10cSrcweir         SwNode const*const pNd =
1829cdf0e10cSrcweir             i_rUnoCrsr.GetDoc()->GetNodes()[ pIdx->GetIndex() + 1 ];
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir         const FlyCntType eType = (!pNd->IsNoTxtNode()) ? FLYCNTTYPE_FRM
1832cdf0e10cSrcweir             : ( (pNd->IsGrfNode()) ? FLYCNTTYPE_GRF : FLYCNTTYPE_OLE );
1833cdf0e10cSrcweir 
1834cdf0e10cSrcweir         const uno::Reference< container::XNamed >  xFrame =
1835cdf0e10cSrcweir             SwXFrames::GetObject(*pFormat, eType);
1836cdf0e10cSrcweir         o_rNextObject.set(xFrame, uno::UNO_QUERY);
1837cdf0e10cSrcweir     }
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir     return o_rNextObject.is();
1840cdf0e10cSrcweir }
1841cdf0e10cSrcweir 
1842cdf0e10cSrcweir /* -----------------------------03.04.00 10:15--------------------------------
1843cdf0e10cSrcweir     Description: Search for a FLYCNT text attribute at the cursor point
1844cdf0e10cSrcweir                 and fill the frame into the array
1845cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
1846cdf0e10cSrcweir static void
lcl_FillFrame(SwClient & rEnum,SwUnoCrsr & rUnoCrsr,FrameDependList_t & rFrames)1847cdf0e10cSrcweir lcl_FillFrame(SwClient & rEnum, SwUnoCrsr& rUnoCrsr,
1848cdf0e10cSrcweir         FrameDependList_t & rFrames)
1849cdf0e10cSrcweir {
1850cdf0e10cSrcweir     // search for objects at the cursor - anchored at/as char
1851cdf0e10cSrcweir     SwTxtAttr const*const pTxtAttr =
1852cdf0e10cSrcweir         rUnoCrsr.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
1853cdf0e10cSrcweir             rUnoCrsr.GetPoint()->nContent.GetIndex(), RES_TXTATR_FLYCNT);
1854cdf0e10cSrcweir     if (pTxtAttr)
1855cdf0e10cSrcweir     {
1856cdf0e10cSrcweir         const SwFmtFlyCnt& rFlyCnt = pTxtAttr->GetFlyCnt();
1857cdf0e10cSrcweir         SwFrmFmt * const  pFrmFmt = rFlyCnt.GetFrmFmt();
1858cdf0e10cSrcweir         SwDepend * const pNewDepend = new SwDepend(&rEnum, pFrmFmt);
1859cdf0e10cSrcweir         rFrames.push_back( ::boost::shared_ptr<SwDepend>(pNewDepend) );
1860cdf0e10cSrcweir     }
1861cdf0e10cSrcweir }
1862cdf0e10cSrcweir 
SwXParaFrameEnumeration(const SwPaM & rPaM,const enum ParaFrameMode eParaFrameMode,SwFrmFmt * const pFmt)1863cdf0e10cSrcweir SwXParaFrameEnumeration::SwXParaFrameEnumeration(
1864cdf0e10cSrcweir         const SwPaM& rPaM, const enum ParaFrameMode eParaFrameMode,
1865cdf0e10cSrcweir         SwFrmFmt *const pFmt)
1866cdf0e10cSrcweir     : m_pImpl( new SwXParaFrameEnumeration::Impl(rPaM) )
1867cdf0e10cSrcweir {
1868cdf0e10cSrcweir     if (PARAFRAME_PORTION_PARAGRAPH == eParaFrameMode)
1869cdf0e10cSrcweir     {
1870cdf0e10cSrcweir         FrameDependSortList_t frames;
1871cdf0e10cSrcweir         ::CollectFrameAtNode(*m_pImpl.get(), rPaM.GetPoint()->nNode,
1872cdf0e10cSrcweir                 frames, false);
1873cdf0e10cSrcweir         ::std::transform(frames.begin(), frames.end(),
1874cdf0e10cSrcweir             ::std::back_inserter(m_pImpl->m_Frames),
1875cdf0e10cSrcweir             ::boost::bind(&FrameDependSortListEntry::pFrameDepend, _1));
1876cdf0e10cSrcweir     }
1877cdf0e10cSrcweir     else if (pFmt)
1878cdf0e10cSrcweir     {
1879cdf0e10cSrcweir         // create SwDepend for frame and insert into array
1880cdf0e10cSrcweir         SwDepend *const pNewDepend = new SwDepend(m_pImpl.get(), pFmt);
1881cdf0e10cSrcweir         m_pImpl->m_Frames.push_back(::boost::shared_ptr<SwDepend>(pNewDepend));
1882cdf0e10cSrcweir     }
1883cdf0e10cSrcweir     else if ((PARAFRAME_PORTION_CHAR == eParaFrameMode) ||
1884cdf0e10cSrcweir              (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode))
1885cdf0e10cSrcweir     {
1886cdf0e10cSrcweir         if (PARAFRAME_PORTION_TEXTRANGE == eParaFrameMode)
1887cdf0e10cSrcweir         {
1888cdf0e10cSrcweir             //get all frames that are bound at paragraph or at character
1889*37fb9221SArmin Le Grand             SwPosFlyFrms aFlyFrms(rPaM.GetDoc()->GetAllFlyFmts(m_pImpl->GetCursor()));
1890*37fb9221SArmin Le Grand 
1891*37fb9221SArmin Le Grand             for(SwPosFlyFrms::const_iterator aIter(aFlyFrms.begin()); aIter != aFlyFrms.end(); aIter++)
1892cdf0e10cSrcweir             {
1893*37fb9221SArmin Le Grand                 SwFrmFmt *const pFrmFmt = const_cast<SwFrmFmt*>(&((*aIter)->GetFmt()));
1894*37fb9221SArmin Le Grand 
1895cdf0e10cSrcweir                 // create SwDepend for frame and insert into array
1896*37fb9221SArmin Le Grand                 SwDepend *const pNewDepend = new SwDepend(m_pImpl.get(), pFrmFmt);
1897*37fb9221SArmin Le Grand                 m_pImpl->m_Frames.push_back(::boost::shared_ptr<SwDepend>(pNewDepend));
1898cdf0e10cSrcweir             }
1899*37fb9221SArmin Le Grand 
1900cdf0e10cSrcweir             //created from any text range
1901cdf0e10cSrcweir             if (m_pImpl->GetCursor()->HasMark())
1902cdf0e10cSrcweir             {
1903cdf0e10cSrcweir                 m_pImpl->GetCursor()->Normalize();
1904cdf0e10cSrcweir                 do
1905cdf0e10cSrcweir                 {
1906cdf0e10cSrcweir                     lcl_FillFrame(*m_pImpl.get(), *m_pImpl->GetCursor(),
1907cdf0e10cSrcweir                             m_pImpl->m_Frames);
1908cdf0e10cSrcweir                     m_pImpl->GetCursor()->Right(
1909cdf0e10cSrcweir                             1, CRSR_SKIP_CHARS, sal_False, sal_False);
1910cdf0e10cSrcweir                 }
1911cdf0e10cSrcweir                 while (*m_pImpl->GetCursor()->GetPoint() <
1912cdf0e10cSrcweir                         *m_pImpl->GetCursor()->GetMark());
1913cdf0e10cSrcweir             }
1914cdf0e10cSrcweir         }
1915*37fb9221SArmin Le Grand 
1916cdf0e10cSrcweir         lcl_FillFrame(*m_pImpl.get(), *m_pImpl->GetCursor(), m_pImpl->m_Frames);
1917cdf0e10cSrcweir     }
1918cdf0e10cSrcweir }
1919cdf0e10cSrcweir 
~SwXParaFrameEnumeration()1920cdf0e10cSrcweir SwXParaFrameEnumeration::~SwXParaFrameEnumeration()
1921cdf0e10cSrcweir {
1922cdf0e10cSrcweir }
1923cdf0e10cSrcweir 
1924cdf0e10cSrcweir sal_Bool SAL_CALL
hasMoreElements()1925cdf0e10cSrcweir SwXParaFrameEnumeration::hasMoreElements() throw (uno::RuntimeException)
1926cdf0e10cSrcweir {
1927cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1928cdf0e10cSrcweir 
1929cdf0e10cSrcweir     if (!m_pImpl->GetCursor())
1930cdf0e10cSrcweir         throw uno::RuntimeException();
1931cdf0e10cSrcweir 
1932cdf0e10cSrcweir     return (m_pImpl->m_xNextObject.is())
1933cdf0e10cSrcweir         ? sal_True
1934cdf0e10cSrcweir         : lcl_CreateNextObject(*m_pImpl->GetCursor(),
1935cdf0e10cSrcweir             m_pImpl->m_xNextObject, m_pImpl->m_Frames);
1936cdf0e10cSrcweir }
1937cdf0e10cSrcweir 
nextElement()1938cdf0e10cSrcweir uno::Any SAL_CALL SwXParaFrameEnumeration::nextElement()
1939cdf0e10cSrcweir throw (container::NoSuchElementException,
1940cdf0e10cSrcweir         lang::WrappedTargetException, uno::RuntimeException)
1941cdf0e10cSrcweir {
1942cdf0e10cSrcweir 	vos::OGuard aGuard(Application::GetSolarMutex());
1943cdf0e10cSrcweir 
1944cdf0e10cSrcweir     if (!m_pImpl->GetCursor())
1945cdf0e10cSrcweir     {
1946cdf0e10cSrcweir         throw uno::RuntimeException();
1947cdf0e10cSrcweir     }
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir     if (!m_pImpl->m_xNextObject.is() && m_pImpl->m_Frames.size())
1950cdf0e10cSrcweir     {
1951cdf0e10cSrcweir         lcl_CreateNextObject(*m_pImpl->GetCursor(),
1952cdf0e10cSrcweir                 m_pImpl->m_xNextObject, m_pImpl->m_Frames);
1953cdf0e10cSrcweir     }
1954cdf0e10cSrcweir     if (!m_pImpl->m_xNextObject.is())
1955cdf0e10cSrcweir     {
1956cdf0e10cSrcweir         throw container::NoSuchElementException();
1957cdf0e10cSrcweir     }
1958cdf0e10cSrcweir     uno::Any aRet;
1959cdf0e10cSrcweir     aRet <<= m_pImpl->m_xNextObject;
1960cdf0e10cSrcweir     m_pImpl->m_xNextObject = 0;
1961cdf0e10cSrcweir     return aRet;
1962cdf0e10cSrcweir }
1963cdf0e10cSrcweir 
1964cdf0e10cSrcweir OUString SAL_CALL
getImplementationName()1965cdf0e10cSrcweir SwXParaFrameEnumeration::getImplementationName() throw (uno::RuntimeException)
1966cdf0e10cSrcweir {
1967cdf0e10cSrcweir     return C2U("SwXParaFrameEnumeration");
1968cdf0e10cSrcweir }
1969cdf0e10cSrcweir 
1970cdf0e10cSrcweir static char const*const g_ServicesParaFrameEnum[] =
1971cdf0e10cSrcweir {
1972cdf0e10cSrcweir     "com.sun.star.util.ContentEnumeration",
1973cdf0e10cSrcweir };
1974cdf0e10cSrcweir static const size_t g_nServicesParaFrameEnum(
1975cdf0e10cSrcweir     sizeof(g_ServicesParaFrameEnum)/sizeof(g_ServicesParaFrameEnum[0]));
1976cdf0e10cSrcweir 
1977cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const OUString & rServiceName)1978cdf0e10cSrcweir SwXParaFrameEnumeration::supportsService(const OUString& rServiceName)
1979cdf0e10cSrcweir throw (uno::RuntimeException)
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir     return ::sw::SupportsServiceImpl(
1982cdf0e10cSrcweir             g_nServicesParaFrameEnum, g_ServicesParaFrameEnum, rServiceName);
1983cdf0e10cSrcweir }
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL
getSupportedServiceNames()1986cdf0e10cSrcweir SwXParaFrameEnumeration::getSupportedServiceNames()
1987cdf0e10cSrcweir throw (uno::RuntimeException)
1988cdf0e10cSrcweir {
1989cdf0e10cSrcweir     return ::sw::GetSupportedServiceNamesImpl(
1990cdf0e10cSrcweir             g_nServicesParaFrameEnum, g_ServicesParaFrameEnum);
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir 
1993