/src/libreoffice/sw/inc/tblafmt.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 | | #ifndef INCLUDED_SW_INC_TBLAFMT_HXX |
20 | | #define INCLUDED_SW_INC_TBLAFMT_HXX |
21 | | |
22 | | #include <memory> |
23 | | |
24 | | #include <editeng/keepitem.hxx> |
25 | | #include <editeng/frmdiritem.hxx> |
26 | | #include <editeng/shaditem.hxx> |
27 | | #include <svx/autoformathelper.hxx> |
28 | | #include <unotools/weakref.hxx> |
29 | | #include <rtl/ref.hxx> |
30 | | #include <svx/TableAutoFmt.hxx> |
31 | | #include "fmtornt.hxx" |
32 | | #include "node.hxx" |
33 | | #include "swdllapi.h" |
34 | | |
35 | | using namespace Autoformat; |
36 | | |
37 | | class SvNumberFormatter; |
38 | | class SwTable; |
39 | | class SwXTextCellStyle; |
40 | | class SwXTextTableStyle; |
41 | | |
42 | | class SW_DLLPUBLIC SwBoxAutoFormat : public SvxAutoFormatDataField |
43 | | { |
44 | | private: |
45 | | std::unique_ptr<SvxFrameDirectionItem> m_aTextOrientation; |
46 | | std::unique_ptr<SwFormatVertOrient> m_aVerticalAlignment; |
47 | | |
48 | | // associated UNO object, if such exists |
49 | | unotools::WeakReference<SwXTextCellStyle> m_xAutoFormatUnoObject; |
50 | | |
51 | | public: |
52 | | SwBoxAutoFormat(); |
53 | | SwBoxAutoFormat(const SwBoxAutoFormat& rNew); |
54 | | SwBoxAutoFormat(const SvxAutoFormatDataField& rNew); |
55 | | ~SwBoxAutoFormat(); |
56 | | |
57 | | /// assignment-op (still used) |
58 | | SwBoxAutoFormat& operator=(const SwBoxAutoFormat& rRef); |
59 | | |
60 | | /// Comparing based of boxes backgrounds. |
61 | | bool operator==(const SwBoxAutoFormat& rRight) const; |
62 | | |
63 | 11.4k | const SvxFrameDirectionItem& GetTextOrientation() const { return *m_aTextOrientation; } |
64 | 9.96k | const SwFormatVertOrient& GetVerticalAlignment() const { return *m_aVerticalAlignment; } |
65 | | |
66 | | void SetTextOrientation(const SvxFrameDirectionItem& rNew) |
67 | 997 | { |
68 | 997 | m_aTextOrientation.reset(rNew.Clone()); |
69 | 997 | } |
70 | | void SetVerticalAlignment(const SwFormatVertOrient& rNew) |
71 | 0 | { |
72 | 0 | m_aVerticalAlignment.reset(rNew.Clone()); |
73 | 0 | } |
74 | | |
75 | | void UpdateAlignment(bool bSvxUpdate = false); |
76 | | |
77 | | unotools::WeakReference<SwXTextCellStyle> const& GetXObject() const |
78 | 3.36k | { |
79 | 3.36k | return m_xAutoFormatUnoObject; |
80 | 3.36k | } |
81 | | void SetXObject(rtl::Reference<SwXTextCellStyle> const& xObject); |
82 | | }; |
83 | | |
84 | | enum class SwTableAutoFormatUpdateFlags |
85 | | { |
86 | | Char = 1, |
87 | | Box = 2 |
88 | | }; |
89 | | namespace o3tl |
90 | | { |
91 | | template <> |
92 | | struct typed_flags<SwTableAutoFormatUpdateFlags> |
93 | | : is_typed_flags<SwTableAutoFormatUpdateFlags, 0x03> |
94 | | { |
95 | | }; |
96 | | }; |
97 | | |
98 | | class SW_DLLPUBLIC SwTableAutoFormat : public SvxAutoFormatData |
99 | | { |
100 | | friend class SwDocTest; |
101 | | friend void FinitCore(); // To destroy default pointer. |
102 | | |
103 | | TableStyleName m_aName; // note that this could be a ProgName __or__ a UIName |
104 | | sal_uInt16 m_nStrResId; |
105 | | bool m_bHidden; |
106 | | bool m_bUserDefined; |
107 | | |
108 | | static SwBoxAutoFormat* s_pDefaultBoxAutoFormat; |
109 | | std::array<std::unique_ptr<SwBoxAutoFormat>, ELEMENT_COUNT> m_aBoxAutoFormat; |
110 | | |
111 | | unotools::WeakReference<SwXTextTableStyle> m_xUnoTextTableStyle; |
112 | | |
113 | | public: |
114 | | SwTableAutoFormat(const TableStyleName& aName); |
115 | | SwTableAutoFormat(const SwTableAutoFormat& rNew); |
116 | | SwTableAutoFormat(const SvxAutoFormatData& rNew); |
117 | | |
118 | | SwTableAutoFormat& operator=(const SwTableAutoFormat& rNew); |
119 | | |
120 | 0 | void SetHidden(bool bHidden) { m_bHidden = bHidden; } |
121 | 0 | void SetUserDefined(bool bUserDefined) { m_bUserDefined = bUserDefined; } |
122 | | void SetName(const TableStyleName& rNew); |
123 | | void SetBoxFormat(const SwBoxAutoFormat& rNew, size_t nIndex); |
124 | | void DisableAll(); |
125 | | |
126 | 0 | bool IsHidden() const { return m_bHidden; } |
127 | 0 | bool IsUserDefined() const { return m_bUserDefined; } |
128 | | |
129 | 0 | const TableStyleName& GetName() const { return m_aName; } |
130 | | static const SwBoxAutoFormat& GetDefaultBoxFormat(); |
131 | | size_t GetIndex(const SwBoxAutoFormat& rBoxFormat) const; |
132 | | |
133 | | void SetName(const OUString& rName) override; |
134 | | SwBoxAutoFormat* GetField(size_t nIndex) override; |
135 | | const SwBoxAutoFormat* GetField(size_t nIndex) const override; |
136 | | bool SetField(size_t nIndex, const SvxAutoFormatDataField& aField) override; |
137 | 0 | SvxAutoFormatData* MakeCopy() const override { return new SwTableAutoFormat(*this); }; |
138 | | |
139 | 0 | SwBoxAutoFormat* GetDefaultField() const override { return new SwBoxAutoFormat; } |
140 | | |
141 | | void RestoreToOriginal(SwContentNode* rContentNode, SfxItemSet& aDummySet, size_t nRow, |
142 | | size_t nCol, size_t nRows, size_t nCols) const; |
143 | | void UpdateToSet(SfxItemSet& aItemSet, size_t nRow, size_t nCol, size_t nRows, size_t nCols, |
144 | | SvNumberFormatter* pNFormatr) const; |
145 | | void UpdateFromSet(size_t nPos, const SfxItemSet& rSet, SwTableAutoFormatUpdateFlags eFlags, |
146 | | SvNumberFormatter const*); |
147 | | void FillToItemSet(size_t nIndex, SfxItemSet& rItemSet, SvNumberFormatter* pNFormatr) const; |
148 | | |
149 | | /// These methods returns what style (row or column) is applied first on given Cell |
150 | | bool FirstRowEndColumnIsRow(); |
151 | | bool FirstRowStartColumnIsRow(); |
152 | | bool LastRowEndColumnIsRow(); |
153 | | bool LastRowStartColumnIsRow(); |
154 | | bool HasHeaderRow() const; |
155 | | |
156 | | unotools::WeakReference<SwXTextTableStyle> const& GetXObject() const |
157 | 0 | { |
158 | 0 | return m_xUnoTextTableStyle; |
159 | 0 | } |
160 | | void SetXObject(rtl::Reference<SwXTextTableStyle> const& xObject); |
161 | | }; |
162 | | |
163 | | class SW_DLLPUBLIC SwTableAutoFormatTable : public SvxAutoFormat |
164 | | { |
165 | | struct Impl; |
166 | | std::unique_ptr<Impl> m_pImpl; |
167 | | |
168 | | public: |
169 | | SwTableAutoFormatTable(); |
170 | | ~SwTableAutoFormatTable(); |
171 | | |
172 | | size_t size() const override; |
173 | | SwTableAutoFormat const& operator[](size_t i) const; |
174 | | SwTableAutoFormat& operator[](size_t i); |
175 | | |
176 | | const SwTableAutoFormat* GetData(size_t nIndex) const override; |
177 | | SwTableAutoFormat* GetData(size_t nIndex) override; |
178 | | |
179 | | /// Append table style to the existing styles. |
180 | | void AddAutoFormat(const SwTableAutoFormat& rFormat); |
181 | | |
182 | | bool InsertAutoFormat(SvxAutoFormatData* pFormat) override; |
183 | | SwTableAutoFormat* FindAutoFormat(const OUString& rName) const override; |
184 | | const SwTableAutoFormat* GetResolvedStyle(const SvxAutoFormatData* pData) const override; |
185 | | SwTableAutoFormat* ReleaseAutoFormat(const OUString& rName) override; |
186 | | SwTableAutoFormat* GetDefaultData() override |
187 | 0 | { |
188 | 0 | return new SwTableAutoFormat(TableStyleName("")); |
189 | 0 | } |
190 | 0 | SwBoxAutoFormat* GetDefaultField() override { return new SwBoxAutoFormat; } |
191 | | SwTableAutoFormat* FindAutoFormat(const TableStyleName& rName) const; |
192 | | std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(const TableStyleName& rName); |
193 | | }; |
194 | | |
195 | | class SwCellStyleDescriptor |
196 | | { |
197 | | const std::pair<UIName, std::unique_ptr<SwBoxAutoFormat>>& m_rCellStyleDesc; |
198 | | |
199 | | public: |
200 | | SwCellStyleDescriptor(const std::pair<UIName, std::unique_ptr<SwBoxAutoFormat>>& rCellStyleDesc) |
201 | 0 | : m_rCellStyleDesc(rCellStyleDesc) |
202 | 0 | { |
203 | 0 | } |
204 | | |
205 | 0 | const UIName& GetName() const { return m_rCellStyleDesc.first; } |
206 | 0 | const SwBoxAutoFormat& GetAutoFormat() const { return *m_rCellStyleDesc.second; } |
207 | | }; |
208 | | |
209 | | class SwCellStyleTable |
210 | | { |
211 | | std::vector<std::pair<UIName, std::unique_ptr<SwBoxAutoFormat>>> m_aCellStyles; |
212 | | |
213 | | public: |
214 | | SwCellStyleTable(); |
215 | | ~SwCellStyleTable(); |
216 | | |
217 | | size_t size() const; |
218 | | SwCellStyleDescriptor operator[](size_t i) const; |
219 | | void clear(); |
220 | | |
221 | | /// Add a copy of rBoxFormat |
222 | | void AddBoxFormat(const SwBoxAutoFormat& rBoxFormat, const UIName& sName); |
223 | | void RemoveBoxFormat(const OUString& sName); |
224 | | void ChangeBoxFormatName(std::u16string_view sFromName, const UIName& sToName); |
225 | | /// If found returns its name. If not found returns an empty UIName |
226 | | UIName GetBoxFormatName(const SwBoxAutoFormat& rBoxFormat) const; |
227 | | /// If found returns a ptr to a BoxFormat. If not found returns nullptr |
228 | | SwBoxAutoFormat* GetBoxFormat(const UIName& sName) const; |
229 | | }; |
230 | | |
231 | | #endif |
232 | | |
233 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |