LibreOffice Module editeng (master) 1
outlobj.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <editeng/editdata.hxx>
21
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>
27
28#include <o3tl/cow_wrapper.hxx>
29#include <o3tl/safeint.hxx>
30#include <libxml/xmlwriter.h>
31
32OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr<EditTextObject> pEditTextObject, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
33 mpEditTextObject(std::move(pEditTextObject)),
34 maParagraphDataVector(std::move(rParagraphDataVector)),
35 mbIsEditDoc(bIsEditDoc)
36{
37 if( maParagraphDataVector.empty() && (mpEditTextObject->GetParagraphCount() != 0) )
38 maParagraphDataVector.resize(mpEditTextObject->GetParagraphCount());
39}
40
42 mpEditTextObject(r.mpEditTextObject->Clone()),
43 maParagraphDataVector(r.maParagraphDataVector),
44 mbIsEditDoc(r.mbIsEditDoc)
45{
46}
47
49{
50}
51
53{
54 return (*mpEditTextObject == *rCandidate.mpEditTextObject
56 && mbIsEditDoc == rCandidate.mbIsEditDoc);
57}
58
60{
61 return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
62}
63
65 std::unique_ptr<EditTextObject> xTextObj, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
66 mpImpl(OutlinerParaObjData(std::move(xTextObj), std::move(rParagraphDataVector), bIsEditDoc))
67{
68}
69
70OutlinerParaObject::OutlinerParaObject( std::unique_ptr<EditTextObject> pTextObj ) :
71 mpImpl(OutlinerParaObjData(std::move(pTextObj), ParagraphDataVector(), true))
72{
73}
74
76 mpImpl(r.mpImpl)
77{
78}
79
81 mpImpl(std::move(r.mpImpl))
82{
83}
84
86{
87}
88
90{
91 mpImpl = r.mpImpl;
92 return *this;
93}
94
96{
97 mpImpl = std::move(r.mpImpl);
98 return *this;
99}
100
102{
103 return r.mpImpl == mpImpl;
104}
105
106// #i102062#
108{
110 {
111 return true;
112 }
113
114 return mpImpl->isWrongListEqual(*r.mpImpl);
115}
116
118{
119 return mpImpl->mpEditTextObject->GetUserType();
120}
121
123{
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 )
128 {
129 mpImpl->mpEditTextObject->SetUserType(nNew);
130 }
131}
132
134{
135 return mpImpl->mpEditTextObject->IsEffectivelyVertical();
136}
137
139{
140 return mpImpl->mpEditTextObject->GetVertical();
141}
142
144{
145 return mpImpl->mpEditTextObject->IsTopToBottom();
146}
147
149{
150 const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl;
151 if ( ( *pImpl )->mpEditTextObject->IsEffectivelyVertical() != bNew)
152 {
153 mpImpl->mpEditTextObject->SetVertical(bNew);
154 }
155}
157{
158 mpImpl->mpEditTextObject->SetRotation(nRotation);
159}
160
162{
163 return mpImpl->mpEditTextObject->GetRotation();
164}
165
167{
168 size_t nSize = mpImpl->maParagraphDataVector.size();
169 if (nSize > EE_PARA_MAX_COUNT)
170 {
171 SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
172 return EE_PARA_MAX_COUNT;
173 }
174 return static_cast<sal_Int32>(nSize);
175}
176
177sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
178{
179 if(0 <= nPara && o3tl::make_unsigned(nPara) < mpImpl->maParagraphDataVector.size())
180 {
181 return mpImpl->maParagraphDataVector[nPara].getDepth();
182 }
183 else
184 {
185 return -1;
186 }
187}
188
190{
191 return *mpImpl->mpEditTextObject;
192}
193
195{
196 if(0 <= nIndex && o3tl::make_unsigned(nIndex) < mpImpl->maParagraphDataVector.size())
197 {
198 return mpImpl->maParagraphDataVector[nIndex];
199 }
200 else
201 {
202 OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
203 static ParagraphData aEmptyParagraphData;
204 return aEmptyParagraphData;
205 }
206}
207
209{
210 mpImpl->mpEditTextObject->ClearPortionInfo();
211}
212
213bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName,
214 SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
215{
216 return mpImpl->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
217}
218
220 std::u16string_view rOldName, const OUString& rNewName)
221{
222 mpImpl->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
223}
224
225void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
226 const SfxStyleFamily& rNewFamily)
227{
228 const sal_Int32 nCount(Count());
229
230 if(nCount)
231 {
232 sal_Int32 nDecrementer(nCount);
233
234 while(nDecrementer > 0)
235 {
236 if(GetDepth(--nDecrementer) == nLevel)
237 {
238 mpImpl->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
239 }
240 }
241 }
242}
243
245{
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);
252}
253
254/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isWrongListEqual(const OutlinerParaObject &rCompare) const
Definition: outlobj.cxx:107
const ParagraphData & GetParagraphData(sal_Int32 nIndex) const
Definition: outlobj.cxx:194
bool GetVertical() const
Definition: outlobj.cxx:138
sal_Int32 Count() const
Definition: outlobj.cxx:166
void SetOutlinerMode(OutlinerMode nNew)
Definition: outlobj.cxx:122
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: outlobj.cxx:244
const EditTextObject & GetTextObject() const
Definition: outlobj.cxx:189
bool ChangeStyleSheets(std::u16string_view rOldName, SfxStyleFamily eOldFamily, const OUString &rNewName, SfxStyleFamily eNewFamily)
Definition: outlobj.cxx:213
bool operator==(const OutlinerParaObject &rCandidate) const
Definition: outlobj.cxx:101
void SetVertical(bool bNew)
Definition: outlobj.cxx:148
OutlinerParaObject & operator=(const OutlinerParaObject &rCandidate)
Definition: outlobj.cxx:89
void ChangeStyleSheetName(SfxStyleFamily eFamily, std::u16string_view rOldName, const OUString &rNewName)
Definition: outlobj.cxx:219
bool IsTopToBottom() const
Definition: outlobj.cxx:143
sal_Int16 GetDepth(sal_Int32 nPara) const
Definition: outlobj.cxx:177
bool IsEffectivelyVertical() const
Definition: outlobj.cxx:133
void SetStyleSheets(sal_uInt16 nLevel, const OUString &rNewName, const SfxStyleFamily &rNewFamily)
Definition: outlobj.cxx:225
OutlinerMode GetOutlinerMode() const
Definition: outlobj.cxx:117
::o3tl::cow_wrapper< OutlinerParaObjData > mpImpl
Definition: outlobj.hxx:68
TextRotation GetRotation() const
Definition: outlobj.cxx:161
void ClearPortionInfo()
Definition: outlobj.cxx:208
void SetRotation(TextRotation nRotation)
Definition: outlobj.cxx:156
OutlinerParaObject(std::nullopt_t) noexcept
Definition: outlobj.hxx:70
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: paralist.cxx:84
bool same_object(const cow_wrapper &rOther) const
int nCount
#define EE_PARA_MAX_COUNT
Definition: editdata.hxx:51
TextRotation
Definition: editobj.hxx:55
struct _xmlTextWriter * xmlTextWriterPtr
sal_Int32 nIndex
void * p
#define SAL_WARN(area, stream)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
OutlinerMode
Definition: outliner.hxx:563
::std::vector< ParagraphData > ParagraphDataVector
This is the guts of OutlinerParaObject, refcounted and shared among multiple instances of OutlinerPar...
Definition: outlobj.hxx:40
bool operator==(const OutlinerParaObjData &rCandidate) const
Definition: outlobj.cxx:52
bool isWrongListEqual(const OutlinerParaObjData &rCompare) const
Definition: outlobj.cxx:59
ParagraphDataVector maParagraphDataVector
Definition: outlobj.hxx:43
std::unique_ptr< EditTextObject > mpEditTextObject
Definition: outlobj.hxx:42
OutlinerParaObjData(std::unique_ptr< EditTextObject > pEditTextObject, ParagraphDataVector &&rParagraphDataVector, bool bIsEditDoc)
Definition: outlobj.cxx:32
SfxStyleFamily