xref: /trunk/main/sfx2/source/sidebar/Paint.cxx (revision f35c6d02)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "Paint.hxx"
25 #include "sfx2/sidebar/Tools.hxx"
26 #include <com/sun/star/awt/Gradient.hpp>
27 
28 
29 using namespace ::com::sun::star;
30 
31 namespace sfx2 { namespace sidebar {
32 
Paint(void)33 Paint::Paint (void)
34     : meType(NoPaint)
35 {
36 }
37 
38 
39 
40 
Paint(const Color & rColor)41 Paint::Paint (const Color& rColor)
42     : meType(ColorPaint),
43       maValue(rColor)
44 {
45 }
46 
47 
48 
49 
Paint(const Gradient & rGradient)50 Paint::Paint (const Gradient& rGradient)
51     : meType(GradientPaint),
52       maValue(rGradient)
53 {
54 }
55 
56 
57 
58 
Create(const cssu::Any & rValue)59 Paint Paint::Create (const cssu::Any& rValue)
60 {
61     ColorData aColor (0);
62     if (rValue >>= aColor)
63         return Paint(Color(aColor));
64 
65     awt::Gradient aAwtGradient;
66     if (rValue >>= aAwtGradient)
67         return Paint(Tools::AwtToVclGradient(aAwtGradient));
68 
69     return Paint();
70 }
71 
72 
73 
74 
Set(const Paint & rOther)75 void Paint::Set (const Paint& rOther)
76 {
77     meType = rOther.meType;
78     maValue = rOther.maValue;
79 }
80 
81 
82 
83 
GetType(void) const84 Paint::Type Paint::GetType (void) const
85 {
86     return meType;
87 }
88 
89 
90 
91 
GetColor(void) const92 const Color& Paint::GetColor (void) const
93 {
94     if (meType != ColorPaint)
95     {
96         assert(meType==ColorPaint);
97         static Color aErrorColor;
98         return aErrorColor;
99     }
100     else
101         return ::boost::get<Color>(maValue);
102 }
103 
104 
105 
106 
GetGradient(void) const107 const Gradient& Paint::GetGradient (void) const
108 {
109     if (meType != GradientPaint)
110     {
111         assert(meType==GradientPaint);
112         static Gradient aErrorGradient;
113         return aErrorGradient;
114     }
115     else
116         return ::boost::get<Gradient>(maValue);
117 }
118 
119 
120 
121 
GetWallpaper(void) const122 Wallpaper Paint::GetWallpaper (void) const
123 {
124     switch (meType)
125     {
126         case Paint::NoPaint:
127         default:
128             return Wallpaper();
129             break;
130 
131         case Paint::ColorPaint:
132             return Wallpaper(GetColor());
133             break;
134 
135         case Paint::GradientPaint:
136             return Wallpaper(GetGradient());
137             break;
138     }
139 }
140 
141 
142 } } // end of namespace sfx2::sidebar
143