Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / Paint.cxx
blobcaa371d2acf6498c25277c2257e0ed03c2e7c460
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 #include "Paint.hxx"
20 #include <sfx2/sidebar/Tools.hxx>
21 #include <com/sun/star/awt/Gradient.hpp>
23 using namespace css;
25 namespace sfx2 { namespace sidebar {
27 Paint::Paint()
28 : meType(NoPaint)
32 Paint::Paint (const Color& rColor)
33 : meType(ColorPaint),
34 maValue(rColor)
38 Paint::Paint (const Gradient& rGradient)
39 : meType(GradientPaint),
40 maValue(rGradient)
44 Paint Paint::Create (const css::uno::Any& rValue)
46 ColorData aColor (0);
47 if (rValue >>= aColor)
48 return Paint(Color(aColor));
50 awt::Gradient aAwtGradient;
51 if (rValue >>= aAwtGradient)
52 return Paint(Tools::AwtToVclGradient(aAwtGradient));
54 return Paint();
57 const Color& Paint::GetColor() const
59 if (meType != ColorPaint)
61 assert(meType==ColorPaint);
62 static Color aErrorColor;
63 return aErrorColor;
65 else
66 return ::boost::get<Color>(maValue);
69 const Gradient& Paint::GetGradient() const
71 if (meType != GradientPaint)
73 assert(meType==GradientPaint);
74 static Gradient aErrorGradient;
75 return aErrorGradient;
77 else
78 return ::boost::get<Gradient>(maValue);
81 Wallpaper Paint::GetWallpaper() const
83 switch (meType)
85 case Paint::NoPaint:
86 default:
87 return Wallpaper();
88 break;
90 case Paint::ColorPaint:
91 return Wallpaper(GetColor());
92 break;
94 case Paint::GradientPaint:
95 return Wallpaper(GetGradient());
96 break;
100 } } // end of namespace sfx2::sidebar
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */