Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / editeng / outlobj.hxx
blob1703cf09cf34396682ff1bb001b4639b5815659f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
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>
28 #include <stdexcept>
29 #include <memory>
31 class EditTextObject;
32 enum class OutlinerMode;
33 enum class TextRotation;
35 /**
36 * This is the guts of OutlinerParaObject, refcounted and shared among
37 * multiple instances of OutlinerParaObject.
39 struct EDITENG_DLLPUBLIC OutlinerParaObjData
41 // data members
42 std::unique_ptr<EditTextObject> mpEditTextObject;
43 ParagraphDataVector maParagraphDataVector;
44 bool mbIsEditDoc;
46 // constructor
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;
56 // destructor
57 ~OutlinerParaObjData();
59 bool operator==(const OutlinerParaObjData& rCandidate) const;
61 // #i102062#
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) {}
75 public:
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;
87 // compare operator
88 bool operator==(const OutlinerParaObject& rCandidate) const;
89 bool operator!=(const OutlinerParaObject& rCandidate) const { return !operator==(rCandidate); }
91 // #i102062#
92 bool isWrongListEqual(const OutlinerParaObject& rCompare) const;
94 // outliner mode access
95 OutlinerMode GetOutlinerMode() const;
96 void SetOutlinerMode(OutlinerMode nNew);
98 // vertical access
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;
106 // data read access
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;
126 namespace std
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 */
131 template<>
132 class optional<OutlinerParaObject>
134 public:
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;
152 return *this;
154 optional& operator=(optional&& other) noexcept
156 maParaObject = std::move(other.maParaObject);
157 return *this;
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()
171 throwIfEmpty();
172 return maParaObject;
174 OutlinerParaObject& operator*()
176 throwIfEmpty();
177 return maParaObject;
179 const OutlinerParaObject& operator*() const
181 throwIfEmpty();
182 return maParaObject;
184 OutlinerParaObject* operator->()
186 throwIfEmpty();
187 return &maParaObject;
189 const OutlinerParaObject* operator->() const
191 throwIfEmpty();
192 return &maParaObject;
194 private:
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: */