LibreOffice Module svx (master)  1
xtable.hxx
Go to the documentation of this file.
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 <svx/xgrad.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>
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 
43 {
44 private:
46 
47 public:
48  XColorEntry(const Color& rColor, const OUString& rName);
49 
50  const Color& GetColor() const
51  {
52  return aColor;
53  }
54 };
55 
57 {
58 private:
60 
61 public:
62  XLineEndEntry(const basegfx::B2DPolyPolygon& rB2DPolyPolygon, const OUString& rName);
63  XLineEndEntry(const XLineEndEntry& rOther);
64 
66  {
67  return aB2DPolyPolygon;
68  }
69 };
70 
72 {
73 private:
74  XDash const aDash;
75 
76 public:
77  XDashEntry(const XDash& rDash, const OUString& rName);
78  XDashEntry(const XDashEntry& rOther);
79 
80  const XDash& GetDash() const
81  {
82  return aDash;
83  }
84 };
85 
87 {
88 private:
89  XHatch const aHatch;
90 
91 public:
92  XHatchEntry(const XHatch& rHatch, const OUString& rName);
93  XHatchEntry(const XHatchEntry& rOther);
94 
95  const XHatch& GetHatch() const
96  {
97  return aHatch;
98  }
99 };
100 
102 {
103 private:
105 
106 public:
107  XGradientEntry(const XGradient& rGradient, const OUString& rName);
108  XGradientEntry(const XGradientEntry& rOther);
109 
110  const XGradient& GetGradient() const
111  {
112  return aGradient;
113  }
114 };
115 
117 {
118 private:
120 
121 public:
122  XBitmapEntry(const GraphicObject& rGraphicObject, const OUString& rName);
123  XBitmapEntry(const XBitmapEntry& rOther);
124 
126  {
127  return maGraphicObject;
128  }
129 };
130 
131 enum class XPropertyListType {
132  Unknown = -1,
133  Color,
134  LineEnd,
135  Dash,
136  Hatch,
137  Gradient,
138  Bitmap,
139  Pattern,
140  LAST = Pattern
141 };
142 
144 
152 
154 {
155 protected:
157  OUString maName; // not persistent
158  OUString maPath;
159  OUString const maReferer;
160 
161  std::vector< std::unique_ptr<XPropertyEntry> > maList;
162 
165 
166  XPropertyList(XPropertyListType t, const OUString& rPath, const OUString& rReferer);
167  bool isValidIdx(long nIndex) const;
168  virtual BitmapEx CreateBitmapForUI(long nIndex) = 0;
169 
170 public:
171  XPropertyList(const XPropertyList&) = delete;
172  XPropertyList& operator=(const XPropertyList&) = delete;
173  virtual ~XPropertyList() override;
174 
175  XPropertyListType Type() const { return meType; }
176  long Count() const;
177 
178  void Insert(std::unique_ptr<XPropertyEntry> pEntry, long nIndex = std::numeric_limits<long>::max());
179  void Replace(std::unique_ptr<XPropertyEntry> pEntry, long nIndex);
180  void Remove(long nIndex);
181 
182  XPropertyEntry* Get(long nIndex) const;
183  long GetIndex(const OUString& rName) const;
184  BitmapEx GetUiBitmap(long nIndex) const;
185 
186  const OUString& GetName() const { return maName; }
187  void SetName(const OUString& rString);
188 
189  const OUString& GetPath() const { return maPath; }
190  void SetPath(const OUString& rString) { maPath = rString; }
191 
192  void SetDirty(bool bDirty) { mbListDirty = bDirty; }
193 
194  bool IsEmbedInDocument() const { return mbEmbedInDocument; }
195 
196  static OUString GetDefaultExt(XPropertyListType t);
197  OUString GetDefaultExt() const { return GetDefaultExt(meType); }
198 
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;
211 
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  const OUString & rUrl);
219 
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);
235 };
236 
238 {
239 protected:
240  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
241 
242 public:
243  XColorList(const OUString& rPath, const OUString& rReferer)
244  : XPropertyList(XPropertyListType::Color, rPath, rReferer) {}
245 
246  void Replace(long nIndex, std::unique_ptr<XColorEntry> pEntry);
247  XColorEntry* GetColor(long nIndex) const;
248  long GetIndexOfColor( const Color& rColor) const;
249  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
250  virtual bool Create() override;
251 
252  static XColorListRef CreateStdColorList();
253  static XColorListRef GetStdColorList(); // returns a singleton
254 };
255 
257 {
258 protected:
259  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
260 
261 public:
262  XLineEndList(const OUString& rPath, const OUString& rReferer);
263  virtual ~XLineEndList() override;
264 
265  XLineEndEntry* GetLineEnd(long nIndex) const;
266 
267  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
268  virtual bool Create() override;
269 };
270 
272 {
273 private:
276  OUString maStringNoLine;
277 
278 protected:
279  static BitmapEx ImpCreateBitmapForXDash(const XDash* pDash);
280  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
281 
282 public:
283  XDashList(const OUString& rPath, const OUString& rReferer);
284  virtual ~XDashList() override;
285 
286  void Replace(std::unique_ptr<XDashEntry> pEntry, long nIndex);
287  XDashEntry* GetDash(long nIndex) const;
288 
289  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
290  virtual bool Create() override;
291 
292  // Special call to get a bitmap for the solid line representation. It
293  // creates a bitmap fitting in size and style to the ones you get by
294  // using GetUiBitmap for existing entries.
295  BitmapEx const & GetBitmapForUISolidLine() const;
296 
297  // Special calls to get the translated strings for the UI entry for no
298  // line style (XLINE_NONE) and solid line style (XLINE_SOLID) for dialogs
299  OUString const & GetStringForUiSolidLine() const;
300  OUString const & GetStringForUiNoLine() const;
301 };
302 
304 {
305 private:
306  BitmapEx CreateBitmap(long nIndex, const Size& rSize) const;
307 protected:
308  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
309 public:
310  XHatchList(const OUString& rPath, const OUString& rReferer);
311  virtual ~XHatchList() override;
312 
313  void Replace(std::unique_ptr<XHatchEntry> pEntry, long nIndex);
314  XHatchEntry* GetHatch(long nIndex) const;
315  BitmapEx GetBitmapForPreview(long nIndex, const Size& rSize);
316 
317  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
318  virtual bool Create() override;
319 };
320 
322 {
323 private:
324  BitmapEx CreateBitmap(long nIndex, const Size& rSize) const;
325 
326 protected:
327  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
328 
329 public:
330  XGradientList(const OUString& rPath, const OUString& rReferer);
331  virtual ~XGradientList() override;
332 
333  void Replace(std::unique_ptr<XGradientEntry> pEntry, long nIndex);
334  XGradientEntry* GetGradient(long nIndex) const;
335  BitmapEx GetBitmapForPreview(long nIndex, const Size& rSize);
336 
337  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
338  virtual bool Create() override;
339 };
340 
342 {
343 private:
344  BitmapEx CreateBitmap( long nIndex, const Size& rSize ) const;
345 
346 protected:
347  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
348 
349 public:
350  XBitmapList(const OUString& rPath, const OUString& rReferer)
351  : XPropertyList(XPropertyListType::Bitmap, rPath, rReferer) {}
352 
353  XBitmapEntry* GetBitmap(long nIndex) const;
354  BitmapEx GetBitmapForPreview(long nIndex, const Size& rSize);
355 
356  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
357  virtual bool Create() override;
358 };
359 
361 {
362 private:
363  BitmapEx CreateBitmap( long nIndex, const Size& rSize ) const;
364 
365 protected:
366  virtual BitmapEx CreateBitmapForUI(long nIndex) override;
367 
368 public:
369  XPatternList(const OUString& rPath, const OUString& rReferer)
370  : XPropertyList(XPropertyListType::Pattern, rPath, rReferer) {}
371 
372  XBitmapEntry* GetBitmap(long nIndex) const;
373  BitmapEx GetBitmapForPreview(long nIndex, const Size& rSize);
374 
375  virtual css::uno::Reference< css::container::XNameContainer > createInstance() override;
376  virtual bool Create() override;
377 };
378 
379 // FIXME: could add type checking too ...
381  rtl::Reference<XPropertyList> const & plist)
382 { return XDashListRef( static_cast<XDashList *> (plist.get()) ); }
384  rtl::Reference<XPropertyList> const & plist)
385 { return XHatchListRef( static_cast<XHatchList *> (plist.get()) ); }
387  rtl::Reference<XPropertyList> const & plist)
388 { return XColorListRef( static_cast<XColorList *> (plist.get()) ); }
390  rtl::Reference<XPropertyList> const & plist)
391 { return XBitmapListRef( static_cast<XBitmapList *> (plist.get()) ); }
393  rtl::Reference<XPropertyList> const & plist)
394 { return XPatternListRef( static_cast<XPatternList *> (plist.get()) ); }
396  rtl::Reference<XPropertyList> const & plist)
397 { return XLineEndListRef( static_cast<XLineEndList *> (plist.get()) ); }
399  rtl::Reference<XPropertyList> const & plist)
400 { return XGradientListRef( static_cast<XGradientList *> (plist.get()) ); }
401 
402 #endif // INCLUDED_SVX_XTABLE_HXX
403 
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OWeakObject &SAL_CALL operator=(const OWeakObject &)
OUString maStringNoLine
Definition: xtable.hxx:276
sal_Int32 nIndex
rtl::Reference< class XBitmapList > XBitmapListRef
Definition: xtable.hxx:148
XHatch const aHatch
Definition: xtable.hxx:89
XPropertyListType Type() const
Definition: xtable.hxx:175
static XLineEndListRef AsLineEndList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:395
XBitmapList(const OUString &rPath, const OUString &rReferer)
Definition: xtable.hxx:350
const OUString & GetName() const
Definition: xtable.hxx:186
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
static XBitmapListRef AsBitmapList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:389
OUString GetDefaultExt() const
Definition: xtable.hxx:197
rtl::Reference< class XColorList > XColorListRef
Definition: xtable.hxx:147
rtl::Reference< class XPatternList > XPatternListRef
Definition: xtable.hxx:149
BitmapEx maBitmapSolidLine
Definition: xtable.hxx:274
#define SVX_DLLPUBLIC
Definition: svxdllapi.h:28
virtual BitmapEx CreateBitmapForUI(long nIndex)=0
virtual bool Create()=0
rtl::Reference< class XHatchList > XHatchListRef
Definition: xtable.hxx:146
void Replace(std::unique_ptr< XPropertyEntry > pEntry, long nIndex)
Definition: xtable.cxx:195
static XPatternListRef AsPatternList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:392
const XGradient & GetGradient() const
Definition: xtable.hxx:110
Definition: xdash.hxx:31
Color aColor
Definition: xtable.hxx:45
rtl::Reference< class XGradientList > XGradientListRef
Definition: xtable.hxx:151
const XDash & GetDash() const
Definition: xtable.hxx:80
const GraphicObject & GetGraphicObject() const
Definition: xtable.hxx:125
OUString maName
Definition: xtable.hxx:157
static XColorListRef AsColorList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:386
OUString const maReferer
Definition: xtable.hxx:159
OUString maStringSolidLine
Definition: xtable.hxx:275
XPropertyListType
Definition: xtable.hxx:131
XColorList(const OUString &rPath, const OUString &rReferer)
Definition: xtable.hxx:243
GraphicObject const maGraphicObject
Definition: xtable.hxx:119
bool IsEmbedInDocument() const
Definition: xtable.hxx:194
bool mbListDirty
Definition: xtable.hxx:163
Count
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
XPatternList(const OUString &rPath, const OUString &rReferer)
Definition: xtable.hxx:369
rtl::Reference< class XPropertyList > XPropertyListRef
Definition: xtable.hxx:143
const OUString & GetPath() const
Definition: xtable.hxx:189
void SetDirty(bool bDirty)
Definition: xtable.hxx:192
void SetPath(const OUString &rString)
Definition: xtable.hxx:190
LineEnd
const basegfx::B2DPolyPolygon & GetLineEnd() const
Definition: xtable.hxx:65
bool mbEmbedInDocument
Definition: xtable.hxx:164
static XGradientListRef AsGradientList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:398
basegfx::B2DPolyPolygon const aB2DPolyPolygon
Definition: xtable.hxx:59
const XHatch & GetHatch() const
Definition: xtable.hxx:95
XPropertyListType const t
Definition: xtable.cxx:373
OUString maPath
Definition: xtable.hxx:158
XPropertyListType const meType
Definition: xtable.hxx:156
XDash const aDash
Definition: xtable.hxx:74
const Color & GetColor() const
Definition: xtable.hxx:50
static XDashListRef AsDashList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:380
rtl::Reference< class XLineEndList > XLineEndListRef
Definition: xtable.hxx:150
static XHatchListRef AsHatchList(rtl::Reference< XPropertyList > const &plist)
Definition: xtable.hxx:383
std::vector< std::unique_ptr< XPropertyEntry > > maList
Definition: xtable.hxx:161
virtual css::uno::Reference< css::container::XNameContainer > createInstance()=0
STDMETHOD() Get(VARIANT *val)=0
XGradient const aGradient
Definition: xtable.hxx:104
rtl::Reference< class XDashList > XDashListRef
Definition: xtable.hxx:145