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 <editeng/editdata.hxx>
22 #include <editeng/outliner.hxx>
23 #include <editeng/outlobj.hxx>
24 #include <editeng/editobj.hxx>
25 #include <sal/log.hxx>
26 #include <osl/diagnose.h>
28 #include <o3tl/cow_wrapper.hxx>
29 #include <o3tl/safeint.hxx>
30 #include <libxml/xmlwriter.h>
32 OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr
<EditTextObject
> pEditTextObject
, ParagraphDataVector
&& rParagraphDataVector
, bool bIsEditDoc
) :
33 mpEditTextObject(std::move(pEditTextObject
)),
34 maParagraphDataVector(std::move(rParagraphDataVector
)),
35 mbIsEditDoc(bIsEditDoc
)
37 if( maParagraphDataVector
.empty() && (mpEditTextObject
->GetParagraphCount() != 0) )
38 maParagraphDataVector
.resize(mpEditTextObject
->GetParagraphCount());
41 OutlinerParaObjData::OutlinerParaObjData( const OutlinerParaObjData
& r
):
42 mpEditTextObject(r
.mpEditTextObject
->Clone()),
43 maParagraphDataVector(r
.maParagraphDataVector
),
44 mbIsEditDoc(r
.mbIsEditDoc
)
48 OutlinerParaObjData::~OutlinerParaObjData()
52 bool OutlinerParaObjData::operator==(const OutlinerParaObjData
& rCandidate
) const
54 return (*mpEditTextObject
== *rCandidate
.mpEditTextObject
55 && maParagraphDataVector
== rCandidate
.maParagraphDataVector
56 && mbIsEditDoc
== rCandidate
.mbIsEditDoc
);
59 bool OutlinerParaObjData::isWrongListEqual(const OutlinerParaObjData
& rCompare
) const
61 return mpEditTextObject
->isWrongListEqual(*rCompare
.mpEditTextObject
);
64 OutlinerParaObject::OutlinerParaObject(
65 std::unique_ptr
<EditTextObject
> xTextObj
, ParagraphDataVector
&& rParagraphDataVector
, bool bIsEditDoc
) :
66 mpImpl(OutlinerParaObjData(std::move(xTextObj
), std::move(rParagraphDataVector
), bIsEditDoc
))
70 OutlinerParaObject::OutlinerParaObject( std::unique_ptr
<EditTextObject
> pTextObj
) :
71 mpImpl(OutlinerParaObjData(std::move(pTextObj
), ParagraphDataVector(), true))
75 OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject
& r
) :
80 OutlinerParaObject::OutlinerParaObject( OutlinerParaObject
&& r
) noexcept
:
81 mpImpl(std::move(r
.mpImpl
))
85 OutlinerParaObject::~OutlinerParaObject()
89 OutlinerParaObject
& OutlinerParaObject::operator=( const OutlinerParaObject
& r
)
95 OutlinerParaObject
& OutlinerParaObject::operator=( OutlinerParaObject
&& r
) noexcept
97 mpImpl
= std::move(r
.mpImpl
);
101 bool OutlinerParaObject::operator==( const OutlinerParaObject
& r
) const
103 return r
.mpImpl
== mpImpl
;
107 bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject
& r
) const
109 if (r
.mpImpl
.same_object(mpImpl
))
114 return mpImpl
->isWrongListEqual(*r
.mpImpl
);
117 OutlinerMode
OutlinerParaObject::GetOutlinerMode() const
119 return mpImpl
->mpEditTextObject
->GetUserType();
122 void OutlinerParaObject::SetOutlinerMode(OutlinerMode nNew
)
124 // create a const pointer to avoid an early call to
125 // make_unique() in the dereference of mpImpl
126 const ::o3tl::cow_wrapper
< OutlinerParaObjData
>* pImpl
= &mpImpl
;
127 if ( ( *pImpl
)->mpEditTextObject
->GetUserType() != nNew
)
129 mpImpl
->mpEditTextObject
->SetUserType(nNew
);
133 bool OutlinerParaObject::IsEffectivelyVertical() const
135 return mpImpl
->mpEditTextObject
->IsEffectivelyVertical();
138 bool OutlinerParaObject::GetVertical() const
140 return mpImpl
->mpEditTextObject
->GetVertical();
143 bool OutlinerParaObject::IsTopToBottom() const
145 return mpImpl
->mpEditTextObject
->IsTopToBottom();
148 void OutlinerParaObject::SetVertical(bool bNew
)
150 const ::o3tl::cow_wrapper
< OutlinerParaObjData
>* pImpl
= &mpImpl
;
151 if ( ( *pImpl
)->mpEditTextObject
->IsEffectivelyVertical() != bNew
)
153 mpImpl
->mpEditTextObject
->SetVertical(bNew
);
156 void OutlinerParaObject::SetRotation(TextRotation nRotation
)
158 mpImpl
->mpEditTextObject
->SetRotation(nRotation
);
161 TextRotation
OutlinerParaObject::GetRotation() const
163 return mpImpl
->mpEditTextObject
->GetRotation();
166 sal_Int32
OutlinerParaObject::Count() const
168 size_t nSize
= mpImpl
->maParagraphDataVector
.size();
169 if (nSize
> EE_PARA_MAX_COUNT
)
171 SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize
);
172 return EE_PARA_MAX_COUNT
;
174 return static_cast<sal_Int32
>(nSize
);
177 sal_Int16
OutlinerParaObject::GetDepth(sal_Int32 nPara
) const
179 if(0 <= nPara
&& o3tl::make_unsigned(nPara
) < mpImpl
->maParagraphDataVector
.size())
181 return mpImpl
->maParagraphDataVector
[nPara
].getDepth();
189 const EditTextObject
& OutlinerParaObject::GetTextObject() const
191 return *mpImpl
->mpEditTextObject
;
194 const ParagraphData
& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex
) const
196 if(0 <= nIndex
&& o3tl::make_unsigned(nIndex
) < mpImpl
->maParagraphDataVector
.size())
198 return mpImpl
->maParagraphDataVector
[nIndex
];
202 OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
203 static ParagraphData aEmptyParagraphData
;
204 return aEmptyParagraphData
;
208 void OutlinerParaObject::ClearPortionInfo()
210 mpImpl
->mpEditTextObject
->ClearPortionInfo();
213 bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName
,
214 SfxStyleFamily eOldFamily
, const OUString
& rNewName
, SfxStyleFamily eNewFamily
)
216 return mpImpl
->mpEditTextObject
->ChangeStyleSheets(rOldName
, eOldFamily
, rNewName
, eNewFamily
);
219 void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily
,
220 std::u16string_view rOldName
, const OUString
& rNewName
)
222 mpImpl
->mpEditTextObject
->ChangeStyleSheetName(eFamily
, rOldName
, rNewName
);
225 void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel
, const OUString
& rNewName
,
226 const SfxStyleFamily
& rNewFamily
)
228 const sal_Int32
nCount(Count());
232 sal_Int32
nDecrementer(nCount
);
234 while(nDecrementer
> 0)
236 if(GetDepth(--nDecrementer
) == nLevel
)
238 mpImpl
->mpEditTextObject
->SetStyleSheet(nDecrementer
, rNewName
, rNewFamily
);
244 void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter
) const
246 (void)xmlTextWriterStartElement(pWriter
, BAD_CAST("OutlinerParaObject"));
247 (void)xmlTextWriterWriteFormatAttribute(pWriter
, BAD_CAST("ptr"), "%p", this);
248 mpImpl
->mpEditTextObject
->dumpAsXml(pWriter
);
249 for (ParagraphData
const & p
: mpImpl
->maParagraphDataVector
)
250 Paragraph(p
).dumpAsXml(pWriter
);
251 (void)xmlTextWriterEndElement(pWriter
);
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */