1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/intitem.hxx>
21 #include <editeng/editeng.hxx>
22 #include <editeng/editview.hxx>
23 #include <editeng/editdata.hxx>
24 #include <editeng/eerdll.hxx>
25 #include <editeng/lrspitem.hxx>
26 #include <editeng/fhgtitem.hxx>
28 #include <editeng/outliner.hxx>
29 #include <editeng/outlobj.hxx>
30 #include <outleeng.hxx>
31 #include <editeng/editobj.hxx>
32 #include <vcl/bitmap.hxx>
33 #include <tools/stream.hxx>
35 #include <boost/intrusive_ptr.hpp>
36 #include <libxml/xmlwriter.h>
39 * This is the guts of OutlinerParaObject, refcounted and shared among
40 * multiple instances of OutlinerParaObject.
42 struct OutlinerParaObjData
45 EditTextObject
* mpEditTextObject
;
46 ParagraphDataVector maParagraphDataVector
;
50 mutable size_t mnRefCount
;
53 OutlinerParaObjData( EditTextObject
* pEditTextObject
, const ParagraphDataVector
& rParagraphDataVector
, bool bIsEditDoc
) :
54 mpEditTextObject(pEditTextObject
),
55 maParagraphDataVector(rParagraphDataVector
),
56 mbIsEditDoc(bIsEditDoc
),
59 if( maParagraphDataVector
.empty() && (pEditTextObject
->GetParagraphCount() != 0) )
60 maParagraphDataVector
.resize(pEditTextObject
->GetParagraphCount());
63 OutlinerParaObjData( const OutlinerParaObjData
& r
) :
64 mpEditTextObject(r
.mpEditTextObject
->Clone()),
65 maParagraphDataVector(r
.maParagraphDataVector
),
66 mbIsEditDoc(r
.mbIsEditDoc
),
71 ~OutlinerParaObjData()
73 delete mpEditTextObject
;
76 bool operator==(const OutlinerParaObjData
& rCandidate
) const
78 return (*mpEditTextObject
== *rCandidate
.mpEditTextObject
79 && maParagraphDataVector
== rCandidate
.maParagraphDataVector
80 && mbIsEditDoc
== rCandidate
.mbIsEditDoc
);
84 bool isWrongListEqual(const OutlinerParaObjData
& rCompare
) const
86 return mpEditTextObject
->isWrongListEqual(*rCompare
.mpEditTextObject
);
90 inline void intrusive_ptr_add_ref(const OutlinerParaObjData
* p
)
95 inline void intrusive_ptr_release(const OutlinerParaObjData
* p
)
102 struct OutlinerParaObject::Impl
104 typedef boost::intrusive_ptr
<OutlinerParaObjData
> DataRef
;
107 Impl( const EditTextObject
& rTextObj
, const ParagraphDataVector
& rParaData
, bool bIsEditDoc
) :
108 mxData(new OutlinerParaObjData(rTextObj
.Clone(), rParaData
, bIsEditDoc
)) {}
110 Impl( const EditTextObject
& rTextObj
) :
111 mxData(new OutlinerParaObjData(rTextObj
.Clone(), ParagraphDataVector(), true)) {}
113 Impl( const Impl
& r
) : mxData(r
.mxData
) {}
118 void OutlinerParaObject::ImplMakeUnique()
120 mpImpl
->mxData
.reset(new OutlinerParaObjData(*mpImpl
->mxData
));
123 OutlinerParaObject::OutlinerParaObject(
124 const EditTextObject
& rTextObj
, const ParagraphDataVector
& rParagraphDataVector
, bool bIsEditDoc
) :
125 mpImpl(new Impl(rTextObj
, rParagraphDataVector
, bIsEditDoc
)) {}
127 OutlinerParaObject::OutlinerParaObject( const EditTextObject
& rTextObj
) :
128 mpImpl(new Impl(rTextObj
))
132 OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject
& r
) :
133 mpImpl(new Impl(*r
.mpImpl
)) {}
135 OutlinerParaObject::~OutlinerParaObject()
140 OutlinerParaObject
& OutlinerParaObject::operator=( const OutlinerParaObject
& r
)
142 mpImpl
->mxData
= r
.mpImpl
->mxData
;
146 bool OutlinerParaObject::operator==( const OutlinerParaObject
& r
) const
148 if (r
.mpImpl
->mxData
.get() == mpImpl
->mxData
.get())
153 return (*r
.mpImpl
->mxData
== *mpImpl
->mxData
);
157 bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject
& r
) const
159 if (r
.mpImpl
->mxData
.get() == mpImpl
->mxData
.get())
164 return mpImpl
->mxData
->isWrongListEqual(*r
.mpImpl
->mxData
);
167 sal_uInt16
OutlinerParaObject::GetOutlinerMode() const
169 return mpImpl
->mxData
->mpEditTextObject
->GetUserType();
172 void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew
)
174 if (mpImpl
->mxData
->mpEditTextObject
->GetUserType() != nNew
)
177 mpImpl
->mxData
->mpEditTextObject
->SetUserType(nNew
);
181 bool OutlinerParaObject::IsVertical() const
183 return mpImpl
->mxData
->mpEditTextObject
->IsVertical();
186 void OutlinerParaObject::SetVertical(bool bNew
)
188 if (mpImpl
->mxData
->mpEditTextObject
->IsVertical() != bNew
)
191 mpImpl
->mxData
->mpEditTextObject
->SetVertical(bNew
);
195 sal_Int32
OutlinerParaObject::Count() const
197 size_t nSize
= mpImpl
->mxData
->maParagraphDataVector
.size();
198 if (nSize
> EE_PARA_MAX_COUNT
)
200 SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize
);
201 return EE_PARA_MAX_COUNT
;
203 return static_cast<sal_Int32
>(nSize
);
206 sal_Int16
OutlinerParaObject::GetDepth(sal_Int32 nPara
) const
208 if(0 <= nPara
&& static_cast<size_t>(nPara
) < mpImpl
->mxData
->maParagraphDataVector
.size())
210 return mpImpl
->mxData
->maParagraphDataVector
[nPara
].getDepth();
218 const EditTextObject
& OutlinerParaObject::GetTextObject() const
220 return *mpImpl
->mxData
->mpEditTextObject
;
223 bool OutlinerParaObject::IsEditDoc() const
225 return mpImpl
->mxData
->mbIsEditDoc
;
228 const ParagraphData
& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex
) const
230 if(0 <= nIndex
&& static_cast<size_t>(nIndex
) < mpImpl
->mxData
->maParagraphDataVector
.size())
232 return mpImpl
->mxData
->maParagraphDataVector
[nIndex
];
236 OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
237 static ParagraphData aEmptyParagraphData
;
238 return aEmptyParagraphData
;
242 void OutlinerParaObject::ClearPortionInfo()
245 mpImpl
->mxData
->mpEditTextObject
->ClearPortionInfo();
248 bool OutlinerParaObject::ChangeStyleSheets(const OUString
& rOldName
,
249 SfxStyleFamily eOldFamily
, const OUString
& rNewName
, SfxStyleFamily eNewFamily
)
252 return mpImpl
->mxData
->mpEditTextObject
->ChangeStyleSheets(rOldName
, eOldFamily
, rNewName
, eNewFamily
);
255 void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily
,
256 const OUString
& rOldName
, const OUString
& rNewName
)
259 mpImpl
->mxData
->mpEditTextObject
->ChangeStyleSheetName(eFamily
, rOldName
, rNewName
);
262 void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel
, const OUString
& rNewName
,
263 const SfxStyleFamily
& rNewFamily
)
265 const sal_Int32
nCount(Count());
270 sal_Int32
nDecrementer(nCount
);
274 if(GetDepth(--nDecrementer
) == nLevel
)
276 mpImpl
->mxData
->mpEditTextObject
->SetStyleSheet(nDecrementer
, rNewName
, rNewFamily
);
282 void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter
) const
284 xmlTextWriterStartElement(pWriter
, BAD_CAST("outlinerParaObject"));
285 xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
286 GetTextObject().dumpAsXml(pWriter
);
287 xmlTextWriterEndElement(pWriter
);
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */