Fix typo
[LibreOffice.git] / include / svx / xtable.hxx
blob273cc918210ea8cb288163bb6a782d4af4d42a38
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 .
19 #ifndef INCLUDED_SVX_XTABLE_HXX
20 #define INCLUDED_SVX_XTABLE_HXX
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>
28 #include <tools/color.hxx>
30 #include <cppuhelper/weak.hxx>
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>
39 #include <limits>
40 #include <memory>
42 class SVXCORE_DLLPUBLIC XColorEntry final : public XPropertyEntry
44 private:
45 Color m_aColor;
47 public:
48 XColorEntry(const Color& rColor, const OUString& rName);
50 const Color& GetColor() const
52 return m_aColor;
56 class SVXCORE_DLLPUBLIC XLineEndEntry final : public XPropertyEntry
58 private:
59 basegfx::B2DPolyPolygon aB2DPolyPolygon;
61 public:
62 XLineEndEntry(basegfx::B2DPolyPolygon aB2DPolyPolygon, const OUString& rName);
63 XLineEndEntry(const XLineEndEntry& rOther);
65 const basegfx::B2DPolyPolygon& GetLineEnd() const
67 return aB2DPolyPolygon;
71 class SVXCORE_DLLPUBLIC XDashEntry final : public XPropertyEntry
73 private:
74 XDash m_aDash;
76 public:
77 XDashEntry(const XDash& rDash, const OUString& rName);
78 XDashEntry(const XDashEntry& rOther);
80 const XDash& GetDash() const
82 return m_aDash;
86 class SVXCORE_DLLPUBLIC XHatchEntry final : public XPropertyEntry
88 private:
89 XHatch aHatch;
91 public:
92 XHatchEntry(const XHatch& rHatch, const OUString& rName);
93 XHatchEntry(const XHatchEntry& rOther);
95 const XHatch& GetHatch() const
97 return aHatch;
101 class SVXCORE_DLLPUBLIC XGradientEntry final : public XPropertyEntry
103 private:
104 basegfx::BGradient aGradient;
106 public:
107 XGradientEntry(const basegfx::BGradient& rGradient, const OUString& rName);
108 XGradientEntry(const XGradientEntry& rOther);
110 const basegfx::BGradient& GetGradient() const
112 return aGradient;
116 class SVXCORE_DLLPUBLIC XBitmapEntry final : public XPropertyEntry
118 private:
119 GraphicObject maGraphicObject;
121 public:
122 XBitmapEntry(const GraphicObject& rGraphicObject, const OUString& rName);
123 XBitmapEntry(const XBitmapEntry& rOther);
125 const GraphicObject& GetGraphicObject() const
127 return maGraphicObject;
131 enum class XPropertyListType {
132 Unknown = -1,
133 Color,
134 LineEnd,
135 Dash,
136 Hatch,
137 Gradient,
138 Bitmap,
139 Pattern,
140 LAST = Pattern
143 typedef rtl::Reference< class XPropertyList > XPropertyListRef;
145 class XDashList ; typedef rtl::Reference< class XDashList > XDashListRef;
146 class XHatchList ; typedef rtl::Reference< class XHatchList > XHatchListRef;
147 class XColorList ; typedef rtl::Reference< class XColorList > XColorListRef;
148 class XBitmapList ; typedef rtl::Reference< class XBitmapList > XBitmapListRef;
149 class XPatternList ; typedef rtl::Reference< class XPatternList > XPatternListRef;
150 class XLineEndList ; typedef rtl::Reference< class XLineEndList > XLineEndListRef;
151 class XGradientList ; typedef rtl::Reference< class XGradientList > XGradientListRef;
153 class SVXCORE_DLLPUBLIC XPropertyList : public cppu::OWeakObject
155 protected:
156 XPropertyListType meType;
157 OUString maName; // not persistent
158 OUString maPath;
159 OUString maReferer;
161 std::vector< std::unique_ptr<XPropertyEntry> > maList;
163 bool mbListDirty;
164 bool mbEmbedInDocument;
166 XPropertyList(XPropertyListType t, OUString aPath, OUString aReferer);
167 bool isValidIdx(tools::Long nIndex) const;
168 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) = 0;
170 public:
171 XPropertyList(const XPropertyList&) = delete;
172 XPropertyList& operator=(const XPropertyList&) = delete;
173 virtual ~XPropertyList() override;
175 XPropertyListType Type() const { return meType; }
176 tools::Long Count() const;
178 void Insert(std::unique_ptr<XPropertyEntry> pEntry, tools::Long nIndex = std::numeric_limits<tools::Long>::max());
179 void Replace(std::unique_ptr<XPropertyEntry> pEntry, tools::Long nIndex);
180 void Remove(tools::Long nIndex);
182 XPropertyEntry* Get(tools::Long nIndex) const;
183 tools::Long GetIndex(std::u16string_view rName) const;
184 BitmapEx GetUiBitmap(tools::Long nIndex) const;
186 const OUString& GetName() const { return maName; }
187 void SetName(const OUString& rString);
189 const OUString& GetPath() const { return maPath; }
190 void SetPath(const OUString& rString) { maPath = rString; }
192 void SetDirty(bool bDirty) { mbListDirty = bDirty; }
194 bool IsEmbedInDocument() const { return mbEmbedInDocument; }
196 static OUString GetDefaultExt(XPropertyListType t);
197 OUString GetDefaultExt() const { return GetDefaultExt(meType); }
199 virtual css::uno::Reference< css::container::XNameContainer >
200 createInstance() = 0;
201 bool Load();
202 bool LoadFrom(const css::uno::Reference<
203 css::embed::XStorage > &xStorage,
204 const OUString &rURL, const OUString &rReferer);
205 bool Save();
206 bool SaveTo (const css::uno::Reference<
207 css::embed::XStorage > &xStorage,
208 const OUString &rURL,
209 OUString *pOptName);
210 virtual bool Create() = 0;
212 // Factory method for sub-classes
213 static XPropertyListRef CreatePropertyList(XPropertyListType t,
214 const OUString& rPath,
215 const OUString& rReferer);
216 // as above but initializes name as expected
217 static XPropertyListRef CreatePropertyListFromURL(XPropertyListType t,
218 std::u16string_view rUrl);
220 // helper accessors
221 static inline XDashListRef AsDashList(
222 rtl::Reference<XPropertyList> const & plist);
223 static inline XHatchListRef AsHatchList(
224 rtl::Reference<XPropertyList> const & plist);
225 static inline XColorListRef AsColorList(
226 rtl::Reference<XPropertyList> const & plist);
227 static inline XBitmapListRef AsBitmapList(
228 rtl::Reference<XPropertyList> const & plist);
229 static inline XPatternListRef AsPatternList(
230 rtl::Reference<XPropertyList> const & plist);
231 static inline XLineEndListRef AsLineEndList(
232 rtl::Reference<XPropertyList> const & plist);
233 static inline XGradientListRef AsGradientList(
234 rtl::Reference<XPropertyList> const & plist);
237 class SVXCORE_DLLPUBLIC XColorList final : public XPropertyList
239 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
241 public:
242 XColorList(const OUString& rPath, const OUString& rReferer)
243 : XPropertyList(XPropertyListType::Color, rPath, rReferer) {}
245 void Replace(tools::Long nIndex, std::unique_ptr<XColorEntry> pEntry);
246 XColorEntry* GetColor(tools::Long nIndex) const;
247 tools::Long GetIndexOfColor( const Color& rColor) const;
248 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
249 virtual bool Create() override;
251 static XColorListRef CreateStdColorList();
252 static XColorListRef GetStdColorList(); // returns a singleton
255 class SVXCORE_DLLPUBLIC XLineEndList final : public XPropertyList
257 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
259 public:
260 XLineEndList(const OUString& rPath, const OUString& rReferer);
261 virtual ~XLineEndList() override;
263 XLineEndEntry* GetLineEnd(tools::Long nIndex) const;
265 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
266 virtual bool Create() override;
269 class SVXCORE_DLLPUBLIC XDashList final : public XPropertyList
271 private:
272 BitmapEx maBitmapSolidLine;
273 OUString maStringSolidLine;
274 OUString maStringNoLine;
276 static double ImpGetDefaultLineThickness();
277 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
279 public:
280 XDashList(const OUString& rPath, const OUString& rReferer);
281 virtual ~XDashList() override;
283 void Replace(std::unique_ptr<XDashEntry> pEntry, tools::Long nIndex);
284 XDashEntry* GetDash(tools::Long nIndex) const;
286 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
287 virtual bool Create() override;
289 // Special call to get a bitmap for the solid line representation. It
290 // creates a bitmap fitting in size and style to the ones you get by
291 // using GetUiBitmap for existing entries.
292 BitmapEx const & GetBitmapForUISolidLine() const;
294 static BitmapEx CreateBitmapForXDash(const XDash* pDash, double fLineThickness);
296 // Special calls to get the translated strings for the UI entry for no
297 // line style (XLINE_NONE) and solid line style (XLINE_SOLID) for dialogs
298 OUString const & GetStringForUiSolidLine() const;
299 OUString const & GetStringForUiNoLine() const;
302 class SVXCORE_DLLPUBLIC XHatchList final : public XPropertyList
304 private:
305 BitmapEx CreateBitmap(tools::Long nIndex, const Size& rSize) const;
306 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
307 public:
308 XHatchList(const OUString& rPath, const OUString& rReferer);
309 virtual ~XHatchList() override;
311 void Replace(std::unique_ptr<XHatchEntry> pEntry, tools::Long nIndex);
312 XHatchEntry* GetHatch(tools::Long nIndex) const;
313 BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
315 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
316 virtual bool Create() override;
319 class SVXCORE_DLLPUBLIC XGradientList final : public XPropertyList
321 private:
322 BitmapEx CreateBitmap(tools::Long nIndex, const Size& rSize) const;
323 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
325 public:
326 XGradientList(const OUString& rPath, const OUString& rReferer);
327 virtual ~XGradientList() override;
329 void Replace(std::unique_ptr<XGradientEntry> pEntry, tools::Long nIndex);
330 XGradientEntry* GetGradient(tools::Long nIndex) const;
331 BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
333 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
334 virtual bool Create() override;
337 class SVXCORE_DLLPUBLIC XBitmapList final : public XPropertyList
339 private:
340 BitmapEx CreateBitmap( tools::Long nIndex, const Size& rSize ) const;
341 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
343 public:
344 XBitmapList(const OUString& rPath, const OUString& rReferer)
345 : XPropertyList(XPropertyListType::Bitmap, rPath, rReferer) {}
347 XBitmapEntry* GetBitmap(tools::Long nIndex) const;
348 BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
350 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
351 virtual bool Create() override;
354 class SVXCORE_DLLPUBLIC XPatternList final : public XPropertyList
356 private:
357 BitmapEx CreateBitmap( tools::Long nIndex, const Size& rSize ) const;
358 virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override;
360 public:
361 XPatternList(const OUString& rPath, const OUString& rReferer)
362 : XPropertyList(XPropertyListType::Pattern, rPath, rReferer) {}
364 XBitmapEntry* GetBitmap(tools::Long nIndex) const;
365 BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size& rSize);
367 virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
368 virtual bool Create() override;
371 // FIXME: could add type checking too ...
372 inline XDashListRef XPropertyList::AsDashList(
373 rtl::Reference<XPropertyList> const & plist)
374 { return XDashListRef( static_cast<XDashList *> (plist.get()) ); }
375 inline XHatchListRef XPropertyList::AsHatchList(
376 rtl::Reference<XPropertyList> const & plist)
377 { return XHatchListRef( static_cast<XHatchList *> (plist.get()) ); }
378 inline XColorListRef XPropertyList::AsColorList(
379 rtl::Reference<XPropertyList> const & plist)
380 { return XColorListRef( static_cast<XColorList *> (plist.get()) ); }
381 inline XBitmapListRef XPropertyList::AsBitmapList(
382 rtl::Reference<XPropertyList> const & plist)
383 { return XBitmapListRef( static_cast<XBitmapList *> (plist.get()) ); }
384 inline XPatternListRef XPropertyList::AsPatternList(
385 rtl::Reference<XPropertyList> const & plist)
386 { return XPatternListRef( static_cast<XPatternList *> (plist.get()) ); }
387 inline XLineEndListRef XPropertyList::AsLineEndList(
388 rtl::Reference<XPropertyList> const & plist)
389 { return XLineEndListRef( static_cast<XLineEndList *> (plist.get()) ); }
390 inline XGradientListRef XPropertyList::AsGradientList(
391 rtl::Reference<XPropertyList> const & plist)
392 { return XGradientListRef( static_cast<XGradientList *> (plist.get()) ); }
394 #endif // INCLUDED_SVX_XTABLE_HXX
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */