/src/libreoffice/include/editeng/outlobj.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
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> |
30 | | |
31 | | class EditTextObject; |
32 | | enum class OutlinerMode; |
33 | | enum class TextRotation; |
34 | | |
35 | | /** |
36 | | * This is the guts of OutlinerParaObject, refcounted and shared among |
37 | | * multiple instances of OutlinerParaObject. |
38 | | */ |
39 | | struct EDITENG_DLLPUBLIC OutlinerParaObjData |
40 | | { |
41 | | // data members |
42 | | std::unique_ptr<EditTextObject> mpEditTextObject; |
43 | | ParagraphDataVector maParagraphDataVector; |
44 | | bool mbIsEditDoc; |
45 | | |
46 | | // constructor |
47 | | OutlinerParaObjData( std::unique_ptr<EditTextObject> pEditTextObject, ParagraphDataVector&& rParagraphDataVector, bool bIsEditDoc ); |
48 | | |
49 | | OutlinerParaObjData( const OutlinerParaObjData& r ); |
50 | | |
51 | 3.77M | OutlinerParaObjData( OutlinerParaObjData&& r ) = default; |
52 | | |
53 | | // assignment operator |
54 | | OutlinerParaObjData& operator=(const OutlinerParaObjData& rCandidate) = delete; |
55 | | |
56 | | // destructor |
57 | | ~OutlinerParaObjData(); |
58 | | |
59 | | bool operator==(const OutlinerParaObjData& rCandidate) const; |
60 | | |
61 | | // #i102062# |
62 | | bool isWrongListEqual(const OutlinerParaObjData& rCompare) const; |
63 | | }; |
64 | | |
65 | | class EDITENG_DLLPUBLIC OutlinerParaObject |
66 | | { |
67 | | friend class std::optional<OutlinerParaObject>; |
68 | | ::o3tl::cow_wrapper< OutlinerParaObjData > mpImpl; |
69 | | |
70 | | OutlinerParaObject(std::nullopt_t) noexcept |
71 | 3.27M | : mpImpl(std::nullopt) {} |
72 | | OutlinerParaObject( const OutlinerParaObject& other, std::nullopt_t ) noexcept |
73 | 0 | : mpImpl(other.mpImpl, std::nullopt) {} |
74 | | |
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(); |
82 | | |
83 | | // assignment operator |
84 | | OutlinerParaObject& operator=(const OutlinerParaObject& rCandidate); |
85 | | OutlinerParaObject& operator=(OutlinerParaObject&&) noexcept; |
86 | | |
87 | | // compare operator |
88 | | bool operator==(const OutlinerParaObject& rCandidate) const; |
89 | 351 | bool operator!=(const OutlinerParaObject& rCandidate) const { return !operator==(rCandidate); } |
90 | | |
91 | | // #i102062# |
92 | | bool isWrongListEqual(const OutlinerParaObject& rCompare) const; |
93 | | |
94 | | // outliner mode access |
95 | | OutlinerMode GetOutlinerMode() const; |
96 | | void SetOutlinerMode(OutlinerMode nNew); |
97 | | |
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; |
105 | | |
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; |
111 | | |
112 | | // portion info support |
113 | | void ClearPortionInfo(); |
114 | | |
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); |
122 | | |
123 | | void dumpAsXml(xmlTextWriterPtr pWriter) const; |
124 | | }; |
125 | | |
126 | | namespace std |
127 | | { |
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> |
133 | | { |
134 | | public: |
135 | 2.81M | optional() noexcept : maParaObject(std::nullopt) {} |
136 | 457k | optional(std::nullopt_t) noexcept : maParaObject(std::nullopt) {} |
137 | | optional(const optional& other) : |
138 | 0 | maParaObject(other.maParaObject, std::nullopt) {} |
139 | | optional(optional&& other) noexcept : |
140 | 8.99M | maParaObject(std::move(other.maParaObject)) {} |
141 | | optional(OutlinerParaObject&& para) noexcept : |
142 | 3.73M | maParaObject(std::move(para)) {} |
143 | | optional(const OutlinerParaObject& para) noexcept : |
144 | 345k | maParaObject(para) {} |
145 | | template< class... Args > |
146 | | explicit optional( std::in_place_t, Args&&... args ) : |
147 | | maParaObject(std::forward<Args>(args)...) {} |
148 | | |
149 | | optional& operator=(optional const & other) |
150 | 0 | { |
151 | 0 | maParaObject = other.maParaObject; |
152 | 0 | return *this; |
153 | 0 | } |
154 | | optional& operator=(optional&& other) noexcept |
155 | 4.39M | { |
156 | 4.39M | maParaObject = std::move(other.maParaObject); |
157 | 4.39M | return *this; |
158 | 4.39M | } |
159 | | template< class... Args > |
160 | | void emplace(Args&&... args ) |
161 | 39.5k | { |
162 | 39.5k | maParaObject = OutlinerParaObject(std::forward<Args>(args)...); |
163 | 39.5k | } void std::__1::optional<OutlinerParaObject>::emplace<OutlinerParaObject const&>(OutlinerParaObject const&) Line | Count | Source | 161 | 702 | { | 162 | 702 | maParaObject = OutlinerParaObject(std::forward<Args>(args)...); | 163 | 702 | } |
void std::__1::optional<OutlinerParaObject>::emplace<std::__1::unique_ptr<EditTextObject, std::__1::default_delete<EditTextObject> > >(std::__1::unique_ptr<EditTextObject, std::__1::default_delete<EditTextObject> >&&) Line | Count | Source | 161 | 38.8k | { | 162 | 38.8k | maParaObject = OutlinerParaObject(std::forward<Args>(args)...); | 163 | 38.8k | } |
|
164 | | |
165 | 0 | bool has_value() const noexcept { return !maParaObject.mpImpl.empty(); } |
166 | 38.8M | explicit operator bool() const noexcept { return !maParaObject.mpImpl.empty(); } |
167 | 568k | void reset() { maParaObject.mpImpl.set_empty(); } |
168 | | |
169 | | OutlinerParaObject& value() |
170 | 0 | { |
171 | 0 | throwIfEmpty(); |
172 | 0 | return maParaObject; |
173 | 0 | } |
174 | | OutlinerParaObject& operator*() |
175 | 27.4M | { |
176 | 27.4M | throwIfEmpty(); |
177 | 27.4M | return maParaObject; |
178 | 27.4M | } |
179 | | const OutlinerParaObject& operator*() const |
180 | 208k | { |
181 | 208k | throwIfEmpty(); |
182 | 208k | return maParaObject; |
183 | 208k | } |
184 | | OutlinerParaObject* operator->() |
185 | 39.5k | { |
186 | 39.5k | throwIfEmpty(); |
187 | 39.5k | return &maParaObject; |
188 | 39.5k | } |
189 | | const OutlinerParaObject* operator->() const |
190 | 0 | { |
191 | 0 | throwIfEmpty(); |
192 | 0 | return &maParaObject; |
193 | 0 | } |
194 | | private: |
195 | | void throwIfEmpty() const |
196 | 27.6M | { |
197 | 27.6M | if (maParaObject.mpImpl.empty()) |
198 | 0 | throw std::logic_error("empty std::optional<OutlinerParaObject>"); |
199 | 27.6M | } |
200 | | OutlinerParaObject maParaObject; |
201 | | }; |
202 | | }; |
203 | | |
204 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |