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 .
22 #include <editeng/paragraphdata.hxx>
23 #include <editeng/editengdllapi.h>
24 #include <rtl/ustring.hxx>
25 #include <svl/poolitem.hxx>
26 #include <svl/style.hxx>
27 #include <o3tl/cow_wrapper.hxx>
32 enum class OutlinerMode
;
33 enum class TextRotation
;
36 * This is the guts of OutlinerParaObject, refcounted and shared among
37 * multiple instances of OutlinerParaObject.
39 struct EDITENG_DLLPUBLIC OutlinerParaObjData
42 std::unique_ptr
<EditTextObject
> mpEditTextObject
;
43 ParagraphDataVector maParagraphDataVector
;
47 OutlinerParaObjData( std::unique_ptr
<EditTextObject
> pEditTextObject
, ParagraphDataVector
&& rParagraphDataVector
, bool bIsEditDoc
);
49 OutlinerParaObjData( const OutlinerParaObjData
& r
);
51 OutlinerParaObjData( OutlinerParaObjData
&& r
) = default;
53 // assignment operator
54 OutlinerParaObjData
& operator=(const OutlinerParaObjData
& rCandidate
) = delete;
57 ~OutlinerParaObjData();
59 bool operator==(const OutlinerParaObjData
& rCandidate
) const;
62 bool isWrongListEqual(const OutlinerParaObjData
& rCompare
) const;
65 class EDITENG_DLLPUBLIC OutlinerParaObject
67 friend class std::optional
<OutlinerParaObject
>;
68 ::o3tl::cow_wrapper
< OutlinerParaObjData
> mpImpl
;
70 OutlinerParaObject(std::nullopt_t
) noexcept
71 : mpImpl(std::nullopt
) {}
72 OutlinerParaObject( const OutlinerParaObject
& other
, std::nullopt_t
) noexcept
73 : mpImpl(other
.mpImpl
, std::nullopt
) {}
76 // constructors/destructor
77 OutlinerParaObject(std::unique_ptr
<EditTextObject
>, ParagraphDataVector
&&, bool bIsEditDoc
);
78 OutlinerParaObject( std::unique_ptr
<EditTextObject
> );
79 OutlinerParaObject( const OutlinerParaObject
&);
80 OutlinerParaObject(OutlinerParaObject
&&) noexcept
;
81 ~OutlinerParaObject();
83 // assignment operator
84 OutlinerParaObject
& operator=(const OutlinerParaObject
& rCandidate
);
85 OutlinerParaObject
& operator=(OutlinerParaObject
&&) noexcept
;
88 bool operator==(const OutlinerParaObject
& rCandidate
) const;
89 bool operator!=(const OutlinerParaObject
& rCandidate
) const { return !operator==(rCandidate
); }
92 bool isWrongListEqual(const OutlinerParaObject
& rCompare
) const;
94 // outliner mode access
95 OutlinerMode
GetOutlinerMode() const;
96 void SetOutlinerMode(OutlinerMode nNew
);
99 bool IsEffectivelyVertical() const;
100 bool GetVertical() const;
101 bool IsTopToBottom() const;
102 void SetVertical(bool bNew
);
103 void SetRotation(TextRotation nRotation
);
104 TextRotation
GetRotation() const;
107 sal_Int32
Count() const;
108 sal_Int16
GetDepth(sal_Int32 nPara
) const;
109 const EditTextObject
& GetTextObject() const;
110 const ParagraphData
& GetParagraphData(sal_Int32 nIndex
) const;
112 // portion info support
113 void ClearPortionInfo();
115 // StyleSheet support
116 bool ChangeStyleSheets(std::u16string_view rOldName
, SfxStyleFamily eOldFamily
,
117 const OUString
& rNewName
, SfxStyleFamily eNewFamily
);
118 void ChangeStyleSheetName(SfxStyleFamily eFamily
, std::u16string_view rOldName
,
119 const OUString
& rNewName
);
120 void SetStyleSheets(sal_uInt16 nLevel
, const OUString
& rNewName
,
121 const SfxStyleFamily
& rNewFamily
);
123 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
128 /** Specialise std::optional template for the case where we are wrapping a o3tl::cow_wrapper
129 type, and we can make the pointer inside the cow_wrapper act as an empty value,
130 and save ourselves some storage */
132 class optional
<OutlinerParaObject
>
135 optional() noexcept
: maParaObject(std::nullopt
) {}
136 optional(std::nullopt_t
) noexcept
: maParaObject(std::nullopt
) {}
137 optional(const optional
& other
) :
138 maParaObject(other
.maParaObject
, std::nullopt
) {}
139 optional(optional
&& other
) noexcept
:
140 maParaObject(std::move(other
.maParaObject
)) {}
141 optional(OutlinerParaObject
&& para
) noexcept
:
142 maParaObject(std::move(para
)) {}
143 optional(const OutlinerParaObject
& para
) noexcept
:
144 maParaObject(para
) {}
145 template< class... Args
>
146 explicit optional( std::in_place_t
, Args
&&... args
) :
147 maParaObject(std::forward
<Args
>(args
)...) {}
149 optional
& operator=(optional
const & other
)
151 maParaObject
= other
.maParaObject
;
154 optional
& operator=(optional
&& other
) noexcept
156 maParaObject
= std::move(other
.maParaObject
);
159 template< class... Args
>
160 void emplace(Args
&&... args
)
162 maParaObject
= OutlinerParaObject(std::forward
<Args
>(args
)...);
165 bool has_value() const noexcept
{ return !maParaObject
.mpImpl
.empty(); }
166 explicit operator bool() const noexcept
{ return !maParaObject
.mpImpl
.empty(); }
167 void reset() { maParaObject
.mpImpl
.set_empty(); }
169 OutlinerParaObject
& value()
174 OutlinerParaObject
& operator*()
179 const OutlinerParaObject
& operator*() const
184 OutlinerParaObject
* operator->()
187 return &maParaObject
;
189 const OutlinerParaObject
* operator->() const
192 return &maParaObject
;
195 void throwIfEmpty() const
197 if (maParaObject
.mpImpl
.empty())
198 throw std::logic_error("empty std::optional<OutlinerParaObject>");
200 OutlinerParaObject maParaObject
;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */