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_SVX_XTABLE_HXX
20 #define INCLUDED_SVX_XTABLE_HXX
21
22 #include <rtl/ref.hxx>
23 #include <rtl/ustring.hxx>
24 #include <svx/xdash.hxx>
25 #include <svx/xhatch.hxx>
26 #include <basegfx/utils/bgradient.hxx>
27
28 #include <tools/color.hxx>
29
30 #include <cppuhelper/weak.hxx>
31
32 #include <svx/svxdllapi.h>
33 #include <com/sun/star/embed/XStorage.hpp>
34 #include <basegfx/polygon/b2dpolypolygon.hxx>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <vcl/GraphicObject.hxx>
37 #include <svx/XPropertyEntry.hxx>
38
39 #include <limits>
40 #include <memory>
41
42 class SVXCORE_DLLPUBLIC XColorEntry final : public XPropertyEntry
43 {
44 private:
45 Color m_aColor;
46
47 public:
48 XColorEntry(const Color& rColor, const OUString& rName);
49 std::unique_ptr<XPropertyEntry> Clone() const override;
50
GetColor() const51 const Color& GetColor() const
52 {
53 return m_aColor;
54 }
55 };
56
57 class SVXCORE_DLLPUBLIC XLineEndEntry final : public XPropertyEntry
58 {
59 private:
60 basegfx::B2DPolyPolygon m_aB2DPolyPolygon;
61
62 public:
63 XLineEndEntry(basegfx::B2DPolyPolygon aB2DPolyPolygon, const OUString& rName);
64 XLineEndEntry(const XLineEndEntry& rOther);
65 std::unique_ptr<XPropertyEntry> Clone() const override;
66
GetLineEnd() const67 const basegfx::B2DPolyPolygon& GetLineEnd() const
68 {
69 return m_aB2DPolyPolygon;
70 }
71 };
72
73 class SVXCORE_DLLPUBLIC XDashEntry final : public XPropertyEntry
74 {
75 private:
76 XDash m_aDash;
77
78 public:
79 XDashEntry(const XDash& rDash, const OUString& rName);
80 XDashEntry(const XDashEntry& rOther);
81 std::unique_ptr<XPropertyEntry> Clone() const override;
82
GetDash() const83 const XDash& GetDash() const
84 {
85 return m_aDash;
86 }
87 };
88
89 class SVXCORE_DLLPUBLIC XHatchEntry final : public XPropertyEntry
90 {
91 private:
92 XHatch m_aHatch;
93
94 public:
95 XHatchEntry(const XHatch& rHatch, const OUString& rName);
96 XHatchEntry(const XHatchEntry& rOther);
97 std::unique_ptr<XPropertyEntry> Clone() const override;
98
GetHatch() const99 const XHatch& GetHatch() const
100 {
101 return m_aHatch;
102 }
103 };
104
105 class SVXCORE_DLLPUBLIC XGradientEntry final : public XPropertyEntry
106 {
107 private:
108 basegfx::BGradient m_aGradient;
109
110 public:
111 XGradientEntry(const basegfx::BGradient& rGradient, const OUString& rName);
112 XGradientEntry(const XGradientEntry& rOther);
113 std::unique_ptr<XPropertyEntry> Clone() const override;
114
GetGradient() const115 const basegfx::BGradient& GetGradient() const
116 {
117 return m_aGradient;
118 }
119 };
120
121 class SVXCORE_DLLPUBLIC XBitmapEntry final : public XPropertyEntry
122 {
123 private:
124 GraphicObject maGraphicObject;
125
126 public:
127 XBitmapEntry(const GraphicObject& rGraphicObject, const OUString& rName);
128 XBitmapEntry(const XBitmapEntry& rOther);
129 std::unique_ptr<XPropertyEntry> Clone() const override;
130
GetGraphicObject() const131 const GraphicObject& GetGraphicObject() const
132 {
133 return maGraphicObject;
134 }
135 };
136
137 enum class XPropertyListType {
138 Unknown = -1,
139 Color,
140 LineEnd,
141 Dash,
142 Hatch,
143 Gradient,
144 Bitmap,
145 Pattern,
146 LAST = Pattern
147 };
148
149 typedef rtl::Reference< class XPropertyList > XPropertyListRef;
150
151 typedef rtl::Reference< class XDashList > XDashListRef;
152 typedef rtl::Reference< class XHatchList > XHatchListRef;
153 typedef rtl::Reference< class XColorList > XColorListRef;
154 typedef rtl::Reference< class XBitmapList > XBitmapListRef;
155 typedef rtl::Reference< class XPatternList > XPatternListRef;
156 typedef rtl::Reference< class XLineEndList > XLineEndListRef;
157 typedef rtl::Reference< class XGradientList > XGradientListRef;
158
159 class SVXCORE_DLLPUBLIC XPropertyList : public cppu::OWeakObject
160 {
161 protected:
162 XPropertyListType meType;
163 OUString maName; // not persistent
164 OUString maPath;
165 OUString maReferer;
166
167 std::vector< std::unique_ptr<XPropertyEntry> > maList;
168
169 bool mbListDirty;
170 bool mbEmbedInDocument;
171
172 XPropertyList(XPropertyListType t, OUString aPath, OUString aReferer);
173 bool isValidIdx(tools::Long nIndex) const;
174 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) = 0;
175
176 private:
177 bool mbNeedsExportableList; // impl: avoid seldom-needed, expensive list cloning
178
179 public:
180 XPropertyList(const XPropertyList&) = delete;
181 XPropertyList& operator=(const XPropertyList&) = delete;
182 virtual ~XPropertyList() override;
183
Type() const184 XPropertyListType Type() const { return meType; }
185 tools::Long Count() const;
186
187 void Insert(std::unique_ptr<XPropertyEntry> pEntry, tools::Long nIndex = std::numeric_limits<tools::Long>::max());
188 void Replace(std::unique_ptr<XPropertyEntry> pEntry, tools::Long nIndex);
189 void Remove(tools::Long nIndex);
190
191 XPropertyEntry* Get(tools::Long nIndex) const;
192 tools::Long GetIndex(std::u16string_view rName) const;
193 Bitmap GetUiBitmap(tools::Long nIndex) const;
194
GetName() const195 const OUString& GetName() const { return maName; }
196 void SetName(const OUString& rString);
197
GetPath() const198 const OUString& GetPath() const { return maPath; }
SetPath(const OUString & rString)199 void SetPath(const OUString& rString) { maPath = rString; }
200
SetDirty(bool bDirty)201 void SetDirty(bool bDirty) { mbListDirty = bDirty; }
202
IsEmbedInDocument() const203 bool IsEmbedInDocument() const { return mbEmbedInDocument; }
204
205 static OUString GetDefaultExt(XPropertyListType t);
GetDefaultExt() const206 OUString GetDefaultExt() const { return GetDefaultExt(meType); }
207
208 virtual css::uno::Reference< css::container::XNameContainer >
209 createInstance() = 0;
210 bool Load();
211 bool LoadFrom(const css::uno::Reference<
212 css::embed::XStorage > &xStorage,
213 const OUString &rURL, const OUString &rReferer);
214 bool Save();
215 bool SaveTo (const css::uno::Reference<
216 css::embed::XStorage > &xStorage,
217 const OUString &rURL,
218 OUString *pOptName);
219 virtual bool Create() = 0;
220
221 // Factory method for sub-classes
222 static XPropertyListRef CreatePropertyList(XPropertyListType t,
223 const OUString& rPath,
224 const OUString& rReferer);
225 // as above but initializes name as expected
226 static XPropertyListRef CreatePropertyListFromURL(XPropertyListType t,
227 std::u16string_view rUrl);
228
229 // helper accessors
230 static inline XDashListRef AsDashList(
231 rtl::Reference<XPropertyList> const & plist);
232 static inline XHatchListRef AsHatchList(
233 rtl::Reference<XPropertyList> const & plist);
234 static inline XColorListRef AsColorList(
235 rtl::Reference<XPropertyList> const & plist);
236 static inline XBitmapListRef AsBitmapList(
237 rtl::Reference<XPropertyList> const & plist);
238 static inline XPatternListRef AsPatternList(
239 rtl::Reference<XPropertyList> const & plist);
240 static inline XLineEndListRef AsLineEndList(
241 rtl::Reference<XPropertyList> const & plist);
242 static inline XGradientListRef AsGradientList(
243 rtl::Reference<XPropertyList> const & plist);
244 };
245
246 class SVXCORE_DLLPUBLIC XColorList final : public XPropertyList
247 {
248 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
249
250 public:
XColorList(const OUString & rPath,const OUString & rReferer)251 XColorList(const OUString& rPath, const OUString& rReferer)
252 : XPropertyList(XPropertyListType::Color, rPath, rReferer) {}
253
254 void Replace(tools::Long nIndex, std::unique_ptr<XColorEntry> pEntry);
255 XColorEntry* GetColor(tools::Long nIndex) const;
256 tools::Long GetIndexOfColor( const Color& rColor) const;
257 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
258 virtual bool Create() override;
259
260 static XColorListRef CreateStdColorList();
261 static XColorListRef GetStdColorList(); // returns a singleton
262 };
263
264 class SVXCORE_DLLPUBLIC XLineEndList final : public XPropertyList
265 {
266 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
267
268 public:
269 XLineEndList(const OUString& rPath, const OUString& rReferer);
270 virtual ~XLineEndList() override;
271
272 XLineEndEntry* GetLineEnd(tools::Long nIndex) const;
273
274 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
275 virtual bool Create() override;
276 };
277
278 class SVXCORE_DLLPUBLIC XDashList final : public XPropertyList
279 {
280 private:
281 Bitmap maBitmapSolidLine;
282 OUString maStringSolidLine;
283 OUString maStringNoLine;
284
285 static double ImpGetDefaultLineThickness();
286 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
287
288 public:
289 XDashList(const OUString& rPath, const OUString& rReferer);
290 virtual ~XDashList() override;
291
292 void Replace(std::unique_ptr<XDashEntry> pEntry, tools::Long nIndex);
293 XDashEntry* GetDash(tools::Long nIndex) const;
294
295 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
296 virtual bool Create() override;
297
298 // Special call to get a bitmap for the solid line representation. It
299 // creates a bitmap fitting in size and style to the ones you get by
300 // using GetUiBitmap for existing entries.
301 Bitmap const & GetBitmapForUISolidLine() const;
302
303 static Bitmap CreateBitmapForXDash(const XDash* pDash, double fLineThickness);
304
305 // Special calls to get the translated strings for the UI entry for no
306 // line style (XLINE_NONE) and solid line style (XLINE_SOLID) for dialogs
307 OUString const & GetStringForUiSolidLine() const;
308 OUString const & GetStringForUiNoLine() const;
309 };
310
311 class SVXCORE_DLLPUBLIC XHatchList final : public XPropertyList
312 {
313 private:
314 Bitmap CreateBitmap(tools::Long nIndex, const Size& rSize) const;
315 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
316 public:
317 XHatchList(const OUString& rPath, const OUString& rReferer);
318 virtual ~XHatchList() override;
319
320 void Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex);
321 XHatchEntry* GetHatch(tools::Long nIndex) const;
322 Bitmap GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
323
324 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
325 virtual bool Create() override;
326 };
327
328 class SVXCORE_DLLPUBLIC XGradientList final : public XPropertyList
329 {
330 private:
331 Bitmap CreateBitmap(tools::Long nIndex, const Size& rSize) const;
332 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
333
334 public:
335 XGradientList(const OUString& rPath, const OUString& rReferer);
336 virtual ~XGradientList() override;
337
338 void Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex);
339 XGradientEntry* GetGradient(tools::Long nIndex) const;
340 Bitmap GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
341
342 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
343 virtual bool Create() override;
344 };
345
346 class SVXCORE_DLLPUBLIC XBitmapList final : public XPropertyList
347 {
348 private:
349 Bitmap CreateBitmap( tools::Long nIndex, const Size& rSize ) const;
350 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
351
352 public:
XBitmapList(const OUString & rPath,const OUString & rReferer)353 XBitmapList(const OUString& rPath, const OUString& rReferer)
354 : XPropertyList(XPropertyListType::Bitmap, rPath, rReferer) {}
355
356 XBitmapEntry* GetBitmap(tools::Long nIndex) const;
357 Bitmap GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
358
359 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
360 virtual bool Create() override;
361 };
362
363 class SVXCORE_DLLPUBLIC XPatternList final : public XPropertyList
364 {
365 private:
366 Bitmap CreateBitmap( tools::Long nIndex, const Size& rSize ) const;
367 virtual Bitmap CreateBitmapForUI(tools::Long nIndex) override;
368
369 public:
XPatternList(const OUString & rPath,const OUString & rReferer)370 XPatternList(const OUString& rPath, const OUString& rReferer)
371 : XPropertyList(XPropertyListType::Pattern, rPath, rReferer) {}
372
373 XBitmapEntry* GetBitmap(tools::Long nIndex) const;
374 Bitmap GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
375
376 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
377 virtual bool Create() override;
378 };
379
380 // FIXME: could add type checking too ...
AsDashList(rtl::Reference<XPropertyList> const & plist)381 inline XDashListRef XPropertyList::AsDashList(
382 rtl::Reference<XPropertyList> const & plist)
383 { return XDashListRef( static_cast<XDashList *> (plist.get()) ); }
AsHatchList(rtl::Reference<XPropertyList> const & plist)384 inline XHatchListRef XPropertyList::AsHatchList(
385 rtl::Reference<XPropertyList> const & plist)
386 { return XHatchListRef( static_cast<XHatchList *> (plist.get()) ); }
AsColorList(rtl::Reference<XPropertyList> const & plist)387 inline XColorListRef XPropertyList::AsColorList(
388 rtl::Reference<XPropertyList> const & plist)
389 { return XColorListRef( static_cast<XColorList *> (plist.get()) ); }
AsBitmapList(rtl::Reference<XPropertyList> const & plist)390 inline XBitmapListRef XPropertyList::AsBitmapList(
391 rtl::Reference<XPropertyList> const & plist)
392 { return XBitmapListRef( static_cast<XBitmapList *> (plist.get()) ); }
AsPatternList(rtl::Reference<XPropertyList> const & plist)393 inline XPatternListRef XPropertyList::AsPatternList(
394 rtl::Reference<XPropertyList> const & plist)
395 { return XPatternListRef( static_cast<XPatternList *> (plist.get()) ); }
AsLineEndList(rtl::Reference<XPropertyList> const & plist)396 inline XLineEndListRef XPropertyList::AsLineEndList(
397 rtl::Reference<XPropertyList> const & plist)
398 { return XLineEndListRef( static_cast<XLineEndList *> (plist.get()) ); }
AsGradientList(rtl::Reference<XPropertyList> const & plist)399 inline XGradientListRef XPropertyList::AsGradientList(
400 rtl::Reference<XPropertyList> const & plist)
401 { return XGradientListRef( static_cast<XGradientList *> (plist.get()) ); }
402
403 #endif // INCLUDED_SVX_XTABLE_HXX
404
405 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
406