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