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