Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/util/XCloseable.hpp>
31 : :
32 : : #include <doc.hxx>
33 : : #include "writerhelper.hxx"
34 : : #include <msfilter.hxx>
35 : : #include <com/sun/star/container/XChild.hpp>
36 : : #include <com/sun/star/embed/EmbedStates.hpp>
37 : :
38 : : #include <algorithm> //std::swap
39 : : #include <functional> //std::binary_function
40 : : #include <svl/itemiter.hxx> //SfxItemIter
41 : : #include <svx/svdobj.hxx> //SdrObject
42 : : #include <svx/svdoole2.hxx> //SdrOle2Obj
43 : : #include <svx/fmglob.hxx> //FmFormInventor
44 : : #include <editeng/brkitem.hxx> //SvxFmtBreakItem
45 : : #include <editeng/tstpitem.hxx> //SvxTabStopItem
46 : : #include <ndtxt.hxx> //SwTxtNode
47 : : #include <ndnotxt.hxx> //SwNoTxtNode
48 : : #include <fmtcntnt.hxx> //SwFmtCntnt
49 : : #include <swtable.hxx> //SwTable
50 : : #include <frmfmt.hxx> //SwFrmFmt
51 : : #include <flypos.hxx> //SwPosFlyFrms
52 : : #include <fmtanchr.hxx> //SwFmtAnchor
53 : : #include <ndgrf.hxx> //SwGrfNode
54 : : #include <fmtfsize.hxx> //SwFmtFrmSize
55 : : #include <SwStyleNameMapper.hxx> //SwStyleNameMapper
56 : : #include <docary.hxx> //SwCharFmts
57 : : #include <charfmt.hxx> //SwCharFmt
58 : : #include <fchrfmt.hxx> //SwFmtCharFmt
59 : : #include <unotools/streamwrap.hxx>
60 : : #include <numrule.hxx>
61 : :
62 : : using namespace com::sun::star;
63 : : using namespace nsSwGetPoolIdFromName;
64 : :
65 : :
66 : : namespace
67 : : {
68 : : /*
69 : : Stroustroup forgets copy_if, See C++ Programming language Chp 18, pg 530
70 : : */
71 : : template <typename In , typename Out , typename Pred>
72 : 300 : Out my_copy_if(In first, In last, Out res, Pred p)
73 : : {
74 [ + + ]: 369 : while (first != last)
75 : : {
76 [ + + ]: 69 : if (p(*first))
77 : 9 : *res = *first;
78 : 69 : ++first;
79 : : }
80 : 300 : return res;
81 : : }
82 : :
83 : : // #i98791# - adjust sorting
84 : : // Utility to sort SwTxtFmtColl's by their assigned outline style list level
85 : : class outlinecmp : public
86 : : std::binary_function<const SwTxtFmtColl*, const SwTxtFmtColl*, bool>
87 : : {
88 : : public:
89 : 4011 : bool operator()(const SwTxtFmtColl *pA, const SwTxtFmtColl *pB) const
90 : : {
91 : : // #i98791#
92 : 4011 : bool bResult( false );
93 : 4011 : const bool bIsAAssignedToOutlineStyle( pA->IsAssignedToListLevelOfOutlineStyle() );
94 : 4011 : const bool bIsBAssignedToOutlineStyle( pB->IsAssignedToListLevelOfOutlineStyle() );
95 [ + + ]: 4011 : if ( bIsAAssignedToOutlineStyle != bIsBAssignedToOutlineStyle )
96 : : {
97 : 1401 : bResult = bIsBAssignedToOutlineStyle;
98 : : }
99 [ + + ]: 2610 : else if ( !bIsAAssignedToOutlineStyle )
100 : : {
101 : : // pA and pB are equal regarding the sorting criteria.
102 : : // Thus return value does not matter.
103 : 2361 : bResult = false;
104 : : }
105 : : else
106 : : {
107 : 249 : bResult = pA->GetAssignedOutlineStyleLevel() < pB->GetAssignedOutlineStyleLevel();
108 : : }
109 : :
110 : 4011 : return bResult;
111 : : }
112 : : };
113 : :
114 : 0 : bool IsValidSlotWhich(sal_uInt16 nSlotId, sal_uInt16 nWhichId)
115 : : {
116 [ # # ][ # # ]: 0 : return (nSlotId != 0 && nWhichId != 0 && nSlotId != nWhichId);
[ # # ]
117 : : }
118 : :
119 : : /*
120 : : Utility to convert a SwPosFlyFrms into a simple vector of sw::Frames
121 : :
122 : : The crucial thing is that a sw::Frame always has an anchor which
123 : : points to some content in the document. This is a requirement of exporting
124 : : to Word
125 : : */
126 : 144 : sw::Frames SwPosFlyFrmsToFrames(const SwPosFlyFrms &rFlys)
127 : : {
128 : 144 : sw::Frames aRet;
129 [ + - ][ + - ]: 153 : for(SwPosFlyFrms::const_reverse_iterator it = rFlys.rbegin(); it != rFlys.rend(); ++it)
[ + + ]
130 : : {
131 [ + - ]: 9 : const SwFrmFmt &rEntry = (*it)->GetFmt();
132 [ + - ][ + - ]: 9 : if (const SwPosition* pAnchor = rEntry.GetAnchor().GetCntntAnchor())
[ + - ]
133 [ + - ][ + - ]: 9 : aRet.push_back(sw::Frame(rEntry, *pAnchor));
[ + - ]
134 : : else
135 : : {
136 [ # # ][ # # ]: 0 : SwPosition aPos((*it)->GetNdIndex());
137 [ # # ]: 0 : if (SwTxtNode* pTxtNd = aPos.nNode.GetNode().GetTxtNode())
138 [ # # ][ # # ]: 0 : aPos.nContent.Assign(pTxtNd, 0);
139 [ # # ][ # # ]: 0 : aRet.push_back(sw::Frame(rEntry, aPos));
[ # # ][ # # ]
140 : : }
141 : : }
142 : 144 : return aRet;
143 : : }
144 : :
145 : : //Utility to test if a frame is anchored at a given node index
146 : : class anchoredto: public std::unary_function<const sw::Frame&, bool>
147 : : {
148 : : private:
149 : : sal_uLong mnNode;
150 : : public:
151 : 300 : anchoredto(sal_uLong nNode) : mnNode(nNode) {}
152 : 69 : bool operator()(const sw::Frame &rFrame) const
153 : : {
154 : 69 : return (mnNode == rFrame.GetPosition().nNode.GetNode().GetIndex());
155 : : }
156 : : };
157 : : }
158 : :
159 : : namespace sw
160 : : {
161 : 222 : Frame::Frame(const SwFrmFmt &rFmt, const SwPosition &rPos)
162 : : : mpFlyFrm(&rFmt),
163 : : maPos(rPos),
164 : : maSize(),
165 : : maLayoutSize(), // #i43447#
166 : : meWriterType(eTxtBox),
167 : : mpStartFrameContent(0),
168 : : // #i43447# - move to initialization list
169 [ + - ]: 222 : mbIsInline( (rFmt.GetAnchor().GetAnchorId() == FLY_AS_CHAR) )
170 : : {
171 [ + + ]: 222 : switch (rFmt.Which())
172 : : {
173 : : case RES_FLYFRMFMT:
174 [ + - ][ + - ]: 216 : if (const SwNodeIndex* pIdx = rFmt.GetCntnt().GetCntntIdx())
175 : : {
176 [ + - ]: 216 : SwNodeIndex aIdx(*pIdx, 1);
177 : 216 : const SwNode &rNd = aIdx.GetNode();
178 : : using sw::util::GetSwappedInSize;
179 : : // #i43447# - determine layout size
180 : : {
181 [ + - ]: 216 : SwRect aLayRect( rFmt.FindLayoutRect() );
182 [ + - ]: 216 : Rectangle aRect( aLayRect.SVRect() );
183 : : // The Object is not rendered (e.g. something in unused
184 : : // header/footer) - thus, get the values from the format.
185 [ - + ]: 216 : if ( aLayRect.IsEmpty() )
186 : : {
187 [ # # ][ # # ]: 0 : aRect.SetSize( rFmt.GetFrmSize().GetSize() );
188 : : }
189 [ + - ]: 216 : maLayoutSize = aRect.GetSize();
190 : : }
191 [ + + - ]: 216 : switch (rNd.GetNodeType())
192 : : {
193 : : case ND_GRFNODE:
194 : 3 : meWriterType = eGraphic;
195 [ + - ]: 3 : maSize = GetSwappedInSize(*rNd.GetNoTxtNode());
196 : 3 : break;
197 : : case ND_OLENODE:
198 : 213 : meWriterType = eOle;
199 [ + - ]: 213 : maSize = GetSwappedInSize(*rNd.GetNoTxtNode());
200 : 213 : break;
201 : : default:
202 : 0 : meWriterType = eTxtBox;
203 : : // #i43447# - Size equals layout size for text boxes
204 : 0 : maSize = maLayoutSize;
205 : 0 : break;
206 : : }
207 [ + - ]: 216 : mpStartFrameContent = &rNd;
208 : : }
209 : : else
210 : : {
211 : : OSL_ENSURE(!this, "Impossible");
212 : 0 : meWriterType = eTxtBox;
213 : : }
214 : 216 : break;
215 : : default:
216 [ + - ][ + - ]: 6 : if (const SdrObject* pObj = rFmt.FindRealSdrObject())
217 : : {
218 [ + - ][ + + ]: 6 : if (pObj->GetObjInventor() == FmFormInventor)
219 : 3 : meWriterType = eFormControl;
220 : : else
221 : 3 : meWriterType = eDrawing;
222 [ + - ][ + - ]: 6 : maSize = pObj->GetSnapRect().GetSize();
223 : : }
224 : : else
225 : : {
226 : : OSL_ENSURE(!this, "Impossible");
227 : 0 : meWriterType = eDrawing;
228 : : }
229 : 6 : break;
230 : : }
231 : 222 : }
232 : :
233 : 42 : bool Frame::IsInline() const
234 : : {
235 : 42 : return mbIsInline;
236 : : }
237 : :
238 : 0 : void Frame::ForceTreatAsInline()
239 : : {
240 : 0 : mbIsInline = true;
241 : 0 : }
242 : :
243 : : namespace hack
244 : : {
245 : :
246 : 0 : sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
247 : : const SfxItemPool &rSrcPool, sal_uInt16 nWhich)
248 : : {
249 : 0 : sal_uInt16 nSlotId = rSrcPool.GetSlotId(nWhich);
250 [ # # ]: 0 : if (IsValidSlotWhich(nSlotId, nWhich))
251 : 0 : nWhich = rDestPool.GetWhich(nSlotId);
252 : : else
253 : 0 : nWhich = 0;
254 : 0 : return nWhich;
255 : : }
256 : :
257 : 213 : sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
258 : : const SwDoc &rDoc, sal_uInt16 nWhich)
259 : : {
260 [ - + ]: 213 : if (RES_WHICHHINT_END < *(rSet.GetRanges()))
261 : : {
262 : 0 : nWhich = TransformWhichBetweenPools(*rSet.GetPool(),
263 : 0 : rDoc.GetAttrPool(), nWhich);
264 : : }
265 : 213 : return nWhich;
266 : : }
267 : :
268 : 0 : DrawingOLEAdaptor::DrawingOLEAdaptor(SdrOle2Obj &rObj,
269 : : SfxObjectShell &rPers)
270 : : : msOrigPersistName(rObj.GetPersistName()),
271 : : mxIPRef(rObj.GetObjRef()), mrPers(rPers),
272 [ # # ][ # # ]: 0 : mpGraphic( rObj.GetGraphic() )
[ # # ]
273 : : {
274 [ # # ]: 0 : rObj.AbandonObject();
275 : 0 : }
276 : :
277 : 0 : bool DrawingOLEAdaptor::TransferToDoc( rtl::OUString &rName )
278 : : {
279 : : OSL_ENSURE(mxIPRef.is(), "Transferring invalid object to doc");
280 [ # # ]: 0 : if (!mxIPRef.is())
281 : 0 : return false;
282 : :
283 [ # # ]: 0 : uno::Reference < container::XChild > xChild( mxIPRef, uno::UNO_QUERY );
284 [ # # ]: 0 : if ( xChild.is() )
285 [ # # ][ # # ]: 0 : xChild->setParent( mrPers.GetModel() );
[ # # ]
286 : :
287 [ # # ][ # # ]: 0 : bool bSuccess = mrPers.GetEmbeddedObjectContainer().InsertEmbeddedObject( mxIPRef, rName );
288 [ # # ]: 0 : if (bSuccess)
289 : : {
290 [ # # ]: 0 : if ( mpGraphic )
291 : : ::svt::EmbeddedObjectRef::SetGraphicToContainer( *mpGraphic,
292 [ # # ]: 0 : mrPers.GetEmbeddedObjectContainer(),
293 : : rName,
294 [ # # ]: 0 : rtl::OUString() );
295 : :
296 [ # # ]: 0 : mxIPRef = 0;
297 : : }
298 : :
299 : 0 : return bSuccess;
300 : : }
301 : :
302 : 0 : DrawingOLEAdaptor::~DrawingOLEAdaptor()
303 : : {
304 [ # # ]: 0 : if (mxIPRef.is())
305 : : {
306 : : OSL_ENSURE( !mrPers.GetEmbeddedObjectContainer().HasEmbeddedObject( mxIPRef ), "Object in adaptor is inserted?!" );
307 : : try
308 : : {
309 [ # # ]: 0 : uno::Reference < com::sun::star::util::XCloseable > xClose( mxIPRef, uno::UNO_QUERY );
310 [ # # ]: 0 : if ( xClose.is() )
311 [ # # ][ # # ]: 0 : xClose->close(sal_True);
[ # # ]
312 : : }
313 [ # # ]: 0 : catch ( const com::sun::star::util::CloseVetoException& )
314 : : {
315 : : }
316 : :
317 [ # # ]: 0 : mxIPRef = 0;
318 : : }
319 : 0 : }
320 : : }
321 : :
322 : : namespace util
323 : : {
324 : 297 : SwTwips MakeSafePositioningValue(SwTwips nIn)
325 : : {
326 [ - + ]: 297 : if (nIn > SHRT_MAX)
327 : 0 : nIn = SHRT_MAX;
328 [ - + ]: 297 : else if (nIn < SHRT_MIN)
329 : 0 : nIn = SHRT_MIN;
330 : 297 : return nIn;
331 : : }
332 : :
333 : 0 : void SetLayer::SendObjectToHell(SdrObject &rObject) const
334 : : {
335 : 0 : SetObjectLayer(rObject, eHell);
336 : 0 : }
337 : :
338 : 132 : void SetLayer::SendObjectToHeaven(SdrObject &rObject) const
339 : : {
340 : 132 : SetObjectLayer(rObject, eHeaven);
341 : 132 : }
342 : :
343 : 132 : void SetLayer::SetObjectLayer(SdrObject &rObject, Layer eLayer) const
344 : : {
345 [ + + ]: 132 : if (FmFormInventor == rObject.GetObjInventor())
346 : 3 : rObject.SetLayer(mnFormLayer);
347 : : else
348 : : {
349 [ + - - ]: 129 : switch (eLayer)
350 : : {
351 : : case eHeaven:
352 : 129 : rObject.SetLayer(mnHeavenLayer);
353 : 129 : break;
354 : : case eHell:
355 : 0 : rObject.SetLayer(mnHellLayer);
356 : 0 : break;
357 : : }
358 : : }
359 : 132 : }
360 : :
361 : : //SetLayer boilerplate begin
362 : 0 : void SetLayer::Swap(SetLayer& rOther) throw()
363 : : {
364 : 0 : std::swap(mnHeavenLayer, rOther.mnHeavenLayer);
365 : 0 : std::swap(mnHellLayer, rOther.mnHellLayer);
366 : 0 : std::swap(mnFormLayer, rOther.mnFormLayer);
367 : 0 : }
368 : :
369 : : // #i38889# - by default put objects into the invisible layers.
370 : 144 : SetLayer::SetLayer(const SwDoc &rDoc)
371 : 144 : : mnHeavenLayer(rDoc.GetInvisibleHeavenId()),
372 : 144 : mnHellLayer(rDoc.GetInvisibleHellId()),
373 : 144 : mnFormLayer(rDoc.GetInvisibleControlsId())
374 : : {
375 : 144 : }
376 : :
377 : 42 : SetLayer::SetLayer(const SetLayer& rOther) throw()
378 : : : mnHeavenLayer(rOther.mnHeavenLayer),
379 : : mnHellLayer(rOther.mnHellLayer),
380 : 42 : mnFormLayer(rOther.mnFormLayer)
381 : : {
382 : 42 : }
383 : :
384 : 0 : SetLayer& SetLayer::operator=(const SetLayer& rOther) throw()
385 : : {
386 : 0 : SetLayer aTemp(rOther);
387 : 0 : Swap(aTemp);
388 : 0 : return *this;
389 : : }
390 : : //SetLayer boilerplate end
391 : :
392 : 2667 : void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems, bool bExportParentItemSet )
393 : : {
394 [ + + ]: 2667 : if( bExportParentItemSet )
395 : : {
396 : 1107 : sal_uInt16 nTotal = rSet.TotalCount();
397 [ + + ]: 101889 : for( sal_uInt16 nItem =0; nItem < nTotal; ++nItem )
398 : : {
399 : 100782 : const SfxPoolItem* pItem = 0;
400 [ + - ][ + - ]: 100782 : if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetWhichByPos( nItem ), true, &pItem ) )
[ + + ]
401 : : {
402 [ + - ]: 5781 : rItems[pItem->Which()] = pItem;
403 : : }
404 : : }
405 : : }
406 [ + + ]: 1560 : else if( rSet.Count())
407 : : {
408 [ + - ]: 1245 : SfxItemIter aIter(rSet);
409 [ + - ]: 1245 : if (const SfxPoolItem *pItem = aIter.GetCurItem())
410 : : {
411 [ + - ][ + - ]: 7746 : do
[ + + ][ + + ]
412 [ + - ]: 7746 : rItems[pItem->Which()] = pItem;
413 : 7746 : while (!aIter.IsAtEnd() && 0 != (pItem = aIter.NextItem()));
414 [ + - ]: 1245 : }
415 : : }
416 : 2667 : }
417 : :
418 : 384 : const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
419 : : sal_uInt16 eType)
420 : : {
421 [ + - ]: 384 : sw::cPoolItemIter aIter = rItems.find(eType);
422 [ + - ][ - + ]: 384 : if (aIter != rItems.end())
423 [ # # ]: 0 : return aIter->second;
424 : 384 : return 0;
425 : : }
426 : :
427 : 0 : void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet)
428 : : {
429 [ # # ]: 0 : if (const SwCharFmt* pCharFmt = rFmt.GetCharFmt())
430 : : {
431 [ # # ]: 0 : if (pCharFmt->GetAttrSet().Count())
432 : : {
433 [ # # ]: 0 : SfxItemIter aIter(pCharFmt->GetAttrSet());
434 : 0 : const SfxPoolItem *pItem = aIter.GetCurItem();
435 [ # # ][ # # ]: 0 : do
[ # # ][ # # ]
436 [ # # ]: 0 : rSet.ClearItem(pItem->Which());
437 [ # # ]: 0 : while (!aIter.IsAtEnd() && 0 != (pItem = aIter.NextItem()));
438 : : }
439 : : }
440 : 0 : }
441 : :
442 : 102 : ParaStyles GetParaStyles(const SwDoc &rDoc)
443 : : {
444 : 102 : ParaStyles aStyles;
445 : : typedef ParaStyles::size_type mysizet;
446 : :
447 : 102 : const SwTxtFmtColls *pColls = rDoc.GetTxtFmtColls();
448 [ + - ]: 102 : mysizet nCount = pColls ? pColls->size() : 0;
449 [ + - ]: 102 : aStyles.reserve(nCount);
450 [ + + ]: 1359 : for (mysizet nI = 0; nI < nCount; ++nI)
451 [ + - ][ + - ]: 1257 : aStyles.push_back((*pColls)[ static_cast< sal_uInt16 >(nI) ]);
452 : 102 : return aStyles;
453 : : }
454 : :
455 : 447 : SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const rtl::OUString& rName)
456 : : {
457 : : // Search first in the Doc-Styles
458 [ + - ]: 447 : SwTxtFmtColl* pColl = rDoc.FindTxtFmtCollByName(rName);
459 [ + + ]: 447 : if (!pColl)
460 : : {
461 : : // Collection not found, try in Pool ?
462 : : sal_uInt16 n = SwStyleNameMapper::GetPoolIdFromUIName(rName,
463 [ + - ]: 396 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
464 [ + + ]: 396 : if (n != SAL_MAX_UINT16) // found or standard
465 : 33 : pColl = rDoc.GetTxtCollFromPool(n, false);
466 : : }
467 : 447 : return pColl;
468 : : }
469 : :
470 : 444 : SwCharFmt* GetCharStyle(SwDoc &rDoc, const rtl::OUString& rName)
471 : : {
472 [ + - ]: 444 : SwCharFmt *pFmt = rDoc.FindCharFmtByName(rName);
473 [ + + ]: 444 : if (!pFmt)
474 : : {
475 : : // Collection not found, try in Pool ?
476 : : sal_uInt16 n = SwStyleNameMapper::GetPoolIdFromUIName(rName,
477 [ + - ]: 321 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
478 [ + + ]: 321 : if (n != SAL_MAX_UINT16) // found or standard
479 : 27 : pFmt = rDoc.GetCharFmtFromPool(n);
480 : : }
481 : 444 : return pFmt;
482 : : }
483 : :
484 : : // #i98791# - adjust sorting algorithm
485 : 102 : void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles)
486 : : {
487 [ + - ]: 102 : std::sort(rStyles.begin(), rStyles.end(), outlinecmp());
488 : 102 : }
489 : :
490 : : /*
491 : : Utility to extract flyfmts from a document, potentially from a
492 : : selection.
493 : : */
494 : 144 : Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM /*, bool bAll*/)
495 : : {
496 [ + - ]: 144 : SwPosFlyFrms aFlys;
497 [ + - ]: 144 : rDoc.GetAllFlyFmts(aFlys, pPaM, true);
498 [ + - ]: 144 : sw::Frames aRet(SwPosFlyFrmsToFrames(aFlys));
499 [ + - ][ + - ]: 153 : for(SwPosFlyFrms::const_reverse_iterator it = aFlys.rbegin(); it != aFlys.rend(); ++it)
[ + + ]
500 [ + - ][ + - ]: 9 : delete *it;
[ + - ]
501 : 144 : return aRet;
502 : : }
503 : :
504 : 300 : Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode)
505 : : {
506 : 300 : Frames aRet;
507 : : my_copy_if(rFrames.begin(), rFrames.end(),
508 [ + - ][ + - ]: 300 : std::back_inserter(aRet), anchoredto(rNode.GetIndex()));
509 : 300 : return aRet;
510 : : }
511 : :
512 : 1305 : const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode)
513 : : {
514 : 1305 : const SwNumRule *pRule = 0;
515 [ + - ][ + + ]: 1458 : if (
[ + + + - ]
516 : 1458 : rTxtNode.IsNumbered() && rTxtNode.IsCountedInList() &&
517 : : 0 != (pRule = rTxtNode.GetNumRule())
518 : : )
519 : : {
520 : 153 : return &(pRule->Get( static_cast< sal_uInt16 >(rTxtNode.GetActualListLevel()) ));
521 : : }
522 : :
523 : : OSL_ENSURE(rTxtNode.GetDoc(), "No document for node?, suspicious");
524 [ - + ]: 1152 : if (!rTxtNode.GetDoc())
525 : 0 : return 0;
526 : :
527 [ - + ][ - + : 1152 : if (
# # # # ]
528 : 1152 : rTxtNode.IsNumbered() && rTxtNode.IsCountedInList() &&
529 : 0 : 0 != (pRule = rTxtNode.GetDoc()->GetOutlineNumRule())
530 : : )
531 : : {
532 : 0 : return &(pRule->Get( static_cast< sal_uInt16 >(rTxtNode.GetActualListLevel()) ));
533 : : }
534 : :
535 : 1305 : return 0;
536 : : }
537 : :
538 : 5487 : const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNode)
539 : : {
540 : 5487 : return GetNormalNumRuleFromTxtNode(rTxtNode);
541 : : }
542 : :
543 : 5487 : const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNode)
544 : : {
545 : 5487 : const SwNumRule *pRule = 0;
546 : :
547 [ + - ][ + + ]: 6336 : if (
[ + + + - ]
548 : 6336 : rTxtNode.IsNumbered() && rTxtNode.IsCountedInList() &&
549 : : 0 != (pRule = rTxtNode.GetNumRule())
550 : : )
551 : : {
552 : 849 : return pRule;
553 : : }
554 : 5487 : return 0;
555 : : }
556 : :
557 : :
558 : 3 : SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt)
559 : : {
560 [ + - ]: 3 : const SwNodeIndex *pIndex = rFmt.GetCntnt().GetCntntIdx();
561 : : OSL_ENSURE(pIndex, "No NodeIndex in SwFrmFmt ?, suspicious");
562 [ - + ]: 3 : if (!pIndex)
563 : 0 : return 0;
564 [ + - ]: 3 : SwNodeIndex aIdx(*pIndex, 1);
565 [ + - ]: 3 : return aIdx.GetNode().GetNoTxtNode();
566 : : }
567 : :
568 : 0 : bool HasPageBreak(const SwNode &rNd)
569 : : {
570 : 0 : const SvxFmtBreakItem *pBreak = 0;
571 [ # # ][ # # ]: 0 : if (rNd.IsTableNode() && rNd.GetTableNode())
[ # # ]
572 : : {
573 : 0 : const SwTable& rTable = rNd.GetTableNode()->GetTable();
574 : 0 : const SwFrmFmt* pApply = rTable.GetFrmFmt();
575 : : OSL_ENSURE(pApply, "impossible");
576 [ # # ]: 0 : if (pApply)
577 : 0 : pBreak = &(ItemGet<SvxFmtBreakItem>(*pApply, RES_BREAK));
578 : : }
579 [ # # ]: 0 : else if (const SwCntntNode *pNd = rNd.GetCntntNode())
580 : 0 : pBreak = &(ItemGet<SvxFmtBreakItem>(*pNd, RES_BREAK));
581 : :
582 [ # # ][ # # ]: 0 : if (pBreak && pBreak->GetBreak() == SVX_BREAK_PAGE_BEFORE)
[ # # ]
583 : 0 : return true;
584 : 0 : return false;
585 : : }
586 : :
587 : 0 : Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly)
588 : : {
589 [ # # ]: 0 : if(1 == rPolyPoly.Count())
590 : : {
591 : 0 : return rPolyPoly[0];
592 : : }
593 : : else
594 : : {
595 : : // This method will now just concatenate the polygons contained
596 : : // in the given PolyPolygon. Anything else which might be thought of
597 : : // for reducing to a single polygon will just need nore power and
598 : : // cannot create more correct results.
599 : 0 : sal_uInt32 nPointCount(0L);
600 : : sal_uInt16 a;
601 : :
602 [ # # ][ # # ]: 0 : for(a = 0; a < rPolyPoly.Count(); a++)
603 : : {
604 [ # # ][ # # ]: 0 : nPointCount += (sal_uInt32)rPolyPoly[a].GetSize();
605 : : }
606 : :
607 [ # # ]: 0 : if(nPointCount > 0x0000ffff)
608 : : {
609 : : OSL_FAIL("PolygonFromPolyPolygon: too many points for a single polygon (!)");
610 : 0 : nPointCount = 0x0000ffff;
611 : : }
612 : :
613 [ # # ]: 0 : Polygon aRetval((sal_uInt16)nPointCount);
614 : 0 : sal_uInt32 nAppendIndex(0L);
615 : :
616 [ # # ][ # # ]: 0 : for(a = 0; a < rPolyPoly.Count(); a++)
617 : : {
618 [ # # ]: 0 : const Polygon& rCandidate = rPolyPoly[a];
619 : :
620 [ # # ][ # # ]: 0 : for(sal_uInt16 b(0); nAppendIndex <= nPointCount && b < rCandidate.GetSize(); b++)
[ # # ][ # # ]
621 : : {
622 [ # # ][ # # ]: 0 : aRetval[(sal_uInt16)nAppendIndex++] = rCandidate[b];
623 : : }
624 : : }
625 : :
626 [ # # ][ # # ]: 0 : return aRetval;
627 : : }
628 : : }
629 : :
630 : 2460 : bool IsStarSymbol(const rtl::OUString &rFontName)
631 : : {
632 : 2460 : xub_StrLen nIndex = 0;
633 [ + - ][ + - ]: 2460 : rtl::OUString sFamilyNm(GetNextFontToken(rFontName, nIndex));
[ + - ][ + - ]
[ + - ]
634 : 2460 : return (sFamilyNm.equalsIgnoreAsciiCase("starsymbol") ||
635 [ + + ][ + - ]: 2460 : sFamilyNm.equalsIgnoreAsciiCase("opensymbol"));
636 : : }
637 : :
638 : 303 : Size GetSwappedInSize(const SwNoTxtNode& rNd)
639 : : {
640 : 303 : Size aGrTwipSz(rNd.GetTwipSize());
641 [ - + ][ - + ]: 303 : if ((!aGrTwipSz.Width() || !aGrTwipSz.Height()))
[ + - ]
642 : : {
643 : 0 : SwGrfNode *pGrfNode = const_cast<SwGrfNode*>(rNd.GetGrfNode());
644 [ # # ][ # # ]: 0 : if (pGrfNode && (GRAPHIC_NONE != pGrfNode->GetGrf().GetType()))
[ # # ]
645 : : {
646 : 0 : bool bWasSwappedOut = pGrfNode->GetGrfObj().IsSwappedOut();
647 : 0 : pGrfNode->SwapIn();
648 : 0 : aGrTwipSz = pGrfNode->GetTwipSize();
649 [ # # ]: 0 : if (bWasSwappedOut)
650 : 0 : pGrfNode->SwapOut();
651 : : }
652 : : }
653 : :
654 : : OSL_ENSURE(aGrTwipSz.Width() && aGrTwipSz.Height(), "0 x 0 graphic ?");
655 : 303 : return aGrTwipSz;
656 : : }
657 : :
658 : 0 : void RedlineStack::open(const SwPosition& rPos, const SfxPoolItem& rAttr)
659 : : {
660 : : OSL_ENSURE(rAttr.Which() == RES_FLTR_REDLINE, "not a redline");
661 [ # # ][ # # ]: 0 : maStack.push_back(new SwFltStackEntry(rPos,rAttr.Clone()));
662 : 0 : }
663 : :
664 : :
665 : : class SameOpenRedlineType :
666 : : public std::unary_function<const SwFltStackEntry*, bool>
667 : : {
668 : : private:
669 : : RedlineType_t meType;
670 : : public:
671 : 0 : SameOpenRedlineType(RedlineType_t eType) : meType(eType) {}
672 : 0 : bool operator()(const SwFltStackEntry *pEntry) const
673 : : {
674 : : const SwFltRedline *pTest = static_cast<const SwFltRedline *>
675 : 0 : (pEntry->pAttr);
676 [ # # ][ # # ]: 0 : return (pEntry->bOpen && (pTest->eType == meType));
677 : : }
678 : : };
679 : :
680 : 0 : bool RedlineStack::close(const SwPosition& rPos, RedlineType_t eType)
681 : : {
682 : : //Search from end for same type
683 : : myriter aResult = std::find_if(maStack.rbegin(), maStack.rend(),
684 [ # # ]: 0 : SameOpenRedlineType(eType));
685 [ # # ][ # # ]: 0 : if (aResult != maStack.rend())
686 : : {
687 [ # # ][ # # ]: 0 : (*aResult)->SetEndPos(rPos);
688 : 0 : return true;
689 : : }
690 : 0 : return false;
691 : : }
692 : :
693 : 378 : void RedlineStack::closeall(const SwPosition& rPos)
694 : : {
695 [ + - ]: 378 : std::for_each(maStack.begin(), maStack.end(), SetEndIfOpen(rPos));
696 : 378 : }
697 : :
698 : 0 : void SetInDocAndDelete::operator()(SwFltStackEntry *pEntry)
699 : : {
700 [ # # ]: 0 : SwPaM aRegion(pEntry->m_aMkPos.m_nNode);
701 [ # # ][ # # ]: 0 : if (
[ # # ]
702 [ # # ]: 0 : pEntry->MakeRegion(&mrDoc, aRegion, true) &&
703 [ # # ]: 0 : (*aRegion.GetPoint() != *aRegion.GetMark())
704 : : )
705 : : {
706 : : mrDoc.SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_ON | nsRedlineMode_t::REDLINE_SHOW_INSERT |
707 [ # # ]: 0 : nsRedlineMode_t::REDLINE_SHOW_DELETE));
708 : : const SwFltRedline *pFltRedline = static_cast<const SwFltRedline*>
709 : 0 : (pEntry->pAttr);
710 : :
711 [ # # ]: 0 : if (USHRT_MAX != pFltRedline->nAutorNoPrev)
712 : : {
713 : : SwRedlineData aData(pFltRedline->eTypePrev,
714 : : pFltRedline->nAutorNoPrev, pFltRedline->aStampPrev, aEmptyStr,
715 [ # # ]: 0 : 0);
716 : :
717 [ # # ][ # # ]: 0 : mrDoc.AppendRedline(new SwRedline(aData, aRegion), true);
[ # # ][ # # ]
718 : : }
719 : :
720 : : SwRedlineData aData(pFltRedline->eType, pFltRedline->nAutorNo,
721 [ # # ]: 0 : pFltRedline->aStamp, aEmptyStr, 0);
722 : :
723 [ # # ][ # # ]: 0 : mrDoc.AppendRedline(new SwRedline(aData, aRegion), true);
[ # # ]
724 : : mrDoc.SetRedlineMode((RedlineMode_t)(nsRedlineMode_t::REDLINE_NONE | nsRedlineMode_t::REDLINE_SHOW_INSERT |
725 [ # # ][ # # ]: 0 : nsRedlineMode_t::REDLINE_SHOW_DELETE ));
726 : : }
727 [ # # ][ # # ]: 0 : delete pEntry;
[ # # ]
728 : 0 : }
729 : :
730 : :
731 : 0 : bool CompareRedlines::operator()(const SwFltStackEntry *pOneE,
732 : : const SwFltStackEntry *pTwoE) const
733 : : {
734 : : const SwFltRedline *pOne= static_cast<const SwFltRedline*>
735 : 0 : (pOneE->pAttr);
736 : : const SwFltRedline *pTwo= static_cast<const SwFltRedline*>
737 : 0 : (pTwoE->pAttr);
738 : :
739 : : //Return the earlier time, if two have the same time, prioritize
740 : : //inserts over deletes
741 [ # # ]: 0 : if (pOne->aStamp == pTwo->aStamp)
742 [ # # ][ # # ]: 0 : return (pOne->eType == nsRedlineType_t::REDLINE_INSERT && pTwo->eType != nsRedlineType_t::REDLINE_INSERT);
743 : : else
744 : 0 : return (pOne->aStamp < pTwo->aStamp) ? true : false;
745 : : }
746 : :
747 : :
748 : 378 : RedlineStack::~RedlineStack()
749 : : {
750 [ + - ]: 378 : std::sort(maStack.begin(), maStack.end(), CompareRedlines());
751 [ + - ]: 378 : std::for_each(maStack.begin(), maStack.end(), SetInDocAndDelete(mrDoc));
752 : 378 : }
753 : :
754 : 0 : sal_uInt16 WrtRedlineAuthor::AddName( const rtl::OUString& rNm )
755 : : {
756 : : sal_uInt16 nRet;
757 : : typedef std::vector<rtl::OUString>::iterator myiter;
758 [ # # ]: 0 : myiter aIter = std::find(maAuthors.begin(), maAuthors.end(), rNm);
759 [ # # ][ # # ]: 0 : if (aIter != maAuthors.end())
760 [ # # ]: 0 : nRet = static_cast< sal_uInt16 >(aIter - maAuthors.begin());
761 : : else
762 : : {
763 : 0 : nRet = static_cast< sal_uInt16 >(maAuthors.size());
764 [ # # ]: 0 : maAuthors.push_back(rNm);
765 : : }
766 : 0 : return nRet;
767 : : }
768 : : }
769 : : }
770 : :
771 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|