summaryrefslogtreecommitdiffstats
path: root/editeng/source/outliner/outlobj.cxx
blob: e6dc6e691c6c5277d7b402e5247dee1b35d7b6ac (plain)
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
/* -*- 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 <editeng/editdata.hxx>

#include <editeng/outliner.hxx>
#include <editeng/outlobj.hxx>
#include <editeng/editobj.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>

#include <o3tl/cow_wrapper.hxx>
#include <o3tl/safeint.hxx>
#include <libxml/xmlwriter.h>

OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr<EditTextObject> pEditTextObject, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
    mpEditTextObject(std::move(pEditTextObject)),
    maParagraphDataVector(std::move(rParagraphDataVector)),
    mbIsEditDoc(bIsEditDoc)
{
    if( maParagraphDataVector.empty() && (mpEditTextObject->GetParagraphCount() != 0) )
        maParagraphDataVector.resize(mpEditTextObject->GetParagraphCount());
}

OutlinerParaObjData::OutlinerParaObjData( const OutlinerParaObjData& r ):
    mpEditTextObject(r.mpEditTextObject->Clone()),
    maParagraphDataVector(r.maParagraphDataVector),
    mbIsEditDoc(r.mbIsEditDoc)
{
}

OutlinerParaObjData::~OutlinerParaObjData()
{
}

bool OutlinerParaObjData::operator==(const OutlinerParaObjData& rCandidate) const
{
    return (*mpEditTextObject == *rCandidate.mpEditTextObject
        && maParagraphDataVector == rCandidate.maParagraphDataVector
        && mbIsEditDoc == rCandidate.mbIsEditDoc);
}

bool OutlinerParaObjData::isWrongListEqual(const OutlinerParaObjData& rCompare) const
{
    return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject);
}

OutlinerParaObject::OutlinerParaObject(
    std::unique_ptr<EditTextObject> xTextObj, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ) :
    mpImpl(OutlinerParaObjData(std::move(xTextObj), std::move(rParagraphDataVector), bIsEditDoc))
{
}

OutlinerParaObject::OutlinerParaObject( std::unique_ptr<EditTextObject> pTextObj ) :
    mpImpl(OutlinerParaObjData(std::move(pTextObj), ParagraphDataVector(), true))
{
}

OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) :
    mpImpl(r.mpImpl)
{
}

OutlinerParaObject::OutlinerParaObject( OutlinerParaObject&& r ) noexcept :
    mpImpl(std::move(r.mpImpl))
{
}

OutlinerParaObject::~OutlinerParaObject()
{
}

OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r )
{
    mpImpl = r.mpImpl;
    return *this;
}

OutlinerParaObject& OutlinerParaObject::operator=( OutlinerParaObject&& r ) noexcept
{
    mpImpl = std::move(r.mpImpl);
    return *this;
}

bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const
{
    return r.mpImpl == mpImpl;
}

// #i102062#
bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const
{
    if (r.mpImpl.same_object(mpImpl))
    {
        return true;
    }

    return mpImpl->isWrongListEqual(*r.mpImpl);
}

OutlinerMode OutlinerParaObject::GetOutlinerMode() const
{
    return mpImpl->mpEditTextObject->GetUserType();
}

void OutlinerParaObject::SetOutlinerMode(OutlinerMode nNew)
{
    // create a const pointer to avoid an early call to
    // make_unique() in the dereference of mpImpl
    const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl;
    if ( ( *pImpl )->mpEditTextObject->GetUserType() != nNew )
    {
        mpImpl->mpEditTextObject->SetUserType(nNew);
    }
}

bool OutlinerParaObject::IsEffectivelyVertical() const
{
    return mpImpl->mpEditTextObject->IsEffectivelyVertical();
}

bool OutlinerParaObject::GetVertical() const
{
    return mpImpl->mpEditTextObject->GetVertical();
}

bool OutlinerParaObject::IsTopToBottom() const
{
    return mpImpl->mpEditTextObject->IsTopToBottom();
}

void OutlinerParaObject::SetVertical(bool bNew)
{
    const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl;
    if ( ( *pImpl )->mpEditTextObject->IsEffectivelyVertical() != bNew)
    {
        mpImpl->mpEditTextObject->SetVertical(bNew);
    }
}
void OutlinerParaObject::SetRotation(TextRotation nRotation)
{
    mpImpl->mpEditTextObject->SetRotation(nRotation);
}

TextRotation OutlinerParaObject::GetRotation() const
{
    return mpImpl->mpEditTextObject->GetRotation();
}

sal_Int32 OutlinerParaObject::Count() const
{
    size_t nSize = mpImpl->maParagraphDataVector.size();
    if (nSize > EE_PARA_MAX_COUNT)
    {
        SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize);
        return EE_PARA_MAX_COUNT;
    }
    return static_cast<sal_Int32>(nSize);
}

sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
{
    if(0 <= nPara && o3tl::make_unsigned(nPara) < mpImpl->maParagraphDataVector.size())
    {
        return mpImpl->maParagraphDataVector[nPara].getDepth();
    }
    else
    {
        return -1;
    }
}

const EditTextObject& OutlinerParaObject::GetTextObject() const
{
    return *mpImpl->mpEditTextObject;
}

const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
{
    if(0 <= nIndex && o3tl::make_unsigned(nIndex) < mpImpl->maParagraphDataVector.size())
    {
        return mpImpl->maParagraphDataVector[nIndex];
    }
    else
    {
        OSL_FAIL("OutlinerParaObject::GetParagraphData: Access out of range (!)");
        static ParagraphData aEmptyParagraphData;
        return aEmptyParagraphData;
    }
}

void OutlinerParaObject::ClearPortionInfo()
{
    mpImpl->mpEditTextObject->ClearPortionInfo();
}

bool OutlinerParaObject::ChangeStyleSheets(std::u16string_view rOldName,
    SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily)
{
    return mpImpl->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily);
}

void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily,
    std::u16string_view rOldName, const OUString& rNewName)
{
    mpImpl->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName);
}

void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName,
    const SfxStyleFamily& rNewFamily)
{
    const sal_Int32 nCount(Count());

    if(nCount)
    {
        sal_Int32 nDecrementer(nCount);

        while(nDecrementer > 0)
        {
            if(GetDepth(--nDecrementer) == nLevel)
            {
                mpImpl->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily);
            }
        }
    }
}

void OutlinerParaObject::dumpAsXml(xmlTextWriterPtr pWriter) const
{
    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("OutlinerParaObject"));
    (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
    mpImpl->mpEditTextObject->dumpAsXml(pWriter);
    for (ParagraphData const & p : mpImpl->maParagraphDataVector)
        Paragraph(p).dumpAsXml(pWriter);
    (void)xmlTextWriterEndElement(pWriter);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */