1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <svx/xgrad.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>
42 class SVX_DLLPUBLIC XColorEntry final
: public XPropertyEntry
48 XColorEntry(const Color
& rColor
, const OUString
& rName
);
50 const Color
& GetColor() const
56 class SVX_DLLPUBLIC XLineEndEntry final
: public XPropertyEntry
59 basegfx::B2DPolyPolygon
const aB2DPolyPolygon
;
62 XLineEndEntry(const basegfx::B2DPolyPolygon
& rB2DPolyPolygon
, const OUString
& rName
);
63 XLineEndEntry(const XLineEndEntry
& rOther
);
65 const basegfx::B2DPolyPolygon
& GetLineEnd() const
67 return aB2DPolyPolygon
;
71 class SVX_DLLPUBLIC XDashEntry final
: public XPropertyEntry
77 XDashEntry(const XDash
& rDash
, const OUString
& rName
);
78 XDashEntry(const XDashEntry
& rOther
);
80 const XDash
& GetDash() const
86 class SVX_DLLPUBLIC XHatchEntry final
: public XPropertyEntry
92 XHatchEntry(const XHatch
& rHatch
, const OUString
& rName
);
93 XHatchEntry(const XHatchEntry
& rOther
);
95 const XHatch
& GetHatch() const
101 class SVX_DLLPUBLIC XGradientEntry final
: public XPropertyEntry
104 XGradient
const aGradient
;
107 XGradientEntry(const XGradient
& rGradient
, const OUString
& rName
);
108 XGradientEntry(const XGradientEntry
& rOther
);
110 const XGradient
& GetGradient() const
116 class SVX_DLLPUBLIC XBitmapEntry final
: public XPropertyEntry
119 GraphicObject
const maGraphicObject
;
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
{
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 SVX_DLLPUBLIC XPropertyList
: public cppu::OWeakObject
156 XPropertyListType
const meType
;
157 OUString maName
; // not persistent
159 OUString
const maReferer
;
161 std::vector
< std::unique_ptr
<XPropertyEntry
> > maList
;
164 bool mbEmbedInDocument
;
166 XPropertyList(XPropertyListType t
, const OUString
& rPath
, const OUString
& rReferer
);
167 bool isValidIdx(long nIndex
) const;
168 virtual BitmapEx
CreateBitmapForUI(long nIndex
) = 0;
171 XPropertyList(const XPropertyList
&) = delete;
172 XPropertyList
& operator=(const XPropertyList
&) = delete;
173 virtual ~XPropertyList() override
;
175 XPropertyListType
Type() const { return meType
; }
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
);
182 XPropertyEntry
* Get(long nIndex
) const;
183 long GetIndex(const OUString
& rName
) const;
184 BitmapEx
GetUiBitmap(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;
202 bool LoadFrom(const css::uno::Reference
<
203 css::embed::XStorage
> &xStorage
,
204 const OUString
&rURL
, const OUString
&rReferer
);
206 bool SaveTo (const css::uno::Reference
<
207 css::embed::XStorage
> &xStorage
,
208 const OUString
&rURL
,
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 const OUString
& rUrl
);
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 SVX_DLLPUBLIC XColorList
: public XPropertyList
240 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
243 XColorList(const OUString
& rPath
, const OUString
& rReferer
)
244 : XPropertyList(XPropertyListType::Color
, rPath
, rReferer
) {}
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
;
252 static XColorListRef
CreateStdColorList();
253 static XColorListRef
GetStdColorList(); // returns a singleton
256 class SVX_DLLPUBLIC XLineEndList
: public XPropertyList
259 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
262 XLineEndList(const OUString
& rPath
, const OUString
& rReferer
);
263 virtual ~XLineEndList() override
;
265 XLineEndEntry
* GetLineEnd(long nIndex
) const;
267 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
268 virtual bool Create() override
;
271 class SVX_DLLPUBLIC XDashList
: public XPropertyList
274 BitmapEx maBitmapSolidLine
;
275 OUString maStringSolidLine
;
276 OUString maStringNoLine
;
279 static BitmapEx
ImpCreateBitmapForXDash(const XDash
* pDash
);
280 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
283 XDashList(const OUString
& rPath
, const OUString
& rReferer
);
284 virtual ~XDashList() override
;
286 void Replace(std::unique_ptr
<XDashEntry
> pEntry
, long nIndex
);
287 XDashEntry
* GetDash(long nIndex
) const;
289 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
290 virtual bool Create() override
;
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;
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;
303 class SVX_DLLPUBLIC XHatchList
: public XPropertyList
306 BitmapEx
CreateBitmap(long nIndex
, const Size
& rSize
) const;
308 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
310 XHatchList(const OUString
& rPath
, const OUString
& rReferer
);
311 virtual ~XHatchList() override
;
313 void Replace(std::unique_ptr
<XHatchEntry
> pEntry
, long nIndex
);
314 XHatchEntry
* GetHatch(long nIndex
) const;
315 BitmapEx
GetBitmapForPreview(long nIndex
, const Size
& rSize
);
317 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
318 virtual bool Create() override
;
321 class SVX_DLLPUBLIC XGradientList
: public XPropertyList
324 BitmapEx
CreateBitmap(long nIndex
, const Size
& rSize
) const;
327 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
330 XGradientList(const OUString
& rPath
, const OUString
& rReferer
);
331 virtual ~XGradientList() override
;
333 void Replace(std::unique_ptr
<XGradientEntry
> pEntry
, long nIndex
);
334 XGradientEntry
* GetGradient(long nIndex
) const;
335 BitmapEx
GetBitmapForPreview(long nIndex
, const Size
& rSize
);
337 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
338 virtual bool Create() override
;
341 class SVX_DLLPUBLIC XBitmapList
: public XPropertyList
344 BitmapEx
CreateBitmap( long nIndex
, const Size
& rSize
) const;
347 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
350 XBitmapList(const OUString
& rPath
, const OUString
& rReferer
)
351 : XPropertyList(XPropertyListType::Bitmap
, rPath
, rReferer
) {}
353 XBitmapEntry
* GetBitmap(long nIndex
) const;
354 BitmapEx
GetBitmapForPreview(long nIndex
, const Size
& rSize
);
356 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
357 virtual bool Create() override
;
360 class SVX_DLLPUBLIC XPatternList
: public XPropertyList
363 BitmapEx
CreateBitmap( long nIndex
, const Size
& rSize
) const;
366 virtual BitmapEx
CreateBitmapForUI(long nIndex
) override
;
369 XPatternList(const OUString
& rPath
, const OUString
& rReferer
)
370 : XPropertyList(XPropertyListType::Pattern
, rPath
, rReferer
) {}
372 XBitmapEntry
* GetBitmap(long nIndex
) const;
373 BitmapEx
GetBitmapForPreview(long nIndex
, const Size
& rSize
);
375 virtual css::uno::Reference
< css::container::XNameContainer
> createInstance() override
;
376 virtual bool Create() override
;
379 // FIXME: could add type checking too ...
380 inline XDashListRef
XPropertyList::AsDashList(
381 rtl::Reference
<XPropertyList
> const & plist
)
382 { return XDashListRef( static_cast<XDashList
*> (plist
.get()) ); }
383 inline XHatchListRef
XPropertyList::AsHatchList(
384 rtl::Reference
<XPropertyList
> const & plist
)
385 { return XHatchListRef( static_cast<XHatchList
*> (plist
.get()) ); }
386 inline XColorListRef
XPropertyList::AsColorList(
387 rtl::Reference
<XPropertyList
> const & plist
)
388 { return XColorListRef( static_cast<XColorList
*> (plist
.get()) ); }
389 inline XBitmapListRef
XPropertyList::AsBitmapList(
390 rtl::Reference
<XPropertyList
> const & plist
)
391 { return XBitmapListRef( static_cast<XBitmapList
*> (plist
.get()) ); }
392 inline XPatternListRef
XPropertyList::AsPatternList(
393 rtl::Reference
<XPropertyList
> const & plist
)
394 { return XPatternListRef( static_cast<XPatternList
*> (plist
.get()) ); }
395 inline XLineEndListRef
XPropertyList::AsLineEndList(
396 rtl::Reference
<XPropertyList
> const & plist
)
397 { return XLineEndListRef( static_cast<XLineEndList
*> (plist
.get()) ); }
398 inline XGradientListRef
XPropertyList::AsGradientList(
399 rtl::Reference
<XPropertyList
> const & plist
)
400 { return XGradientListRef( static_cast<XGradientList
*> (plist
.get()) ); }
402 #endif // INCLUDED_SVX_XTABLE_HXX
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */