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 
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/awt/Gradient.hpp>
25 #include <com/sun/star/awt/GradientStyle.hpp>
26 #include <ooo/vba/office/MsoGradientStyle.hpp>
27 #include "vbafillformat.hxx"
28 #include "vbacolorformat.hxx"
29 
30 using namespace ooo::vba;
31 using namespace com::sun::star;
32 
ScVbaFillFormat(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<drawing::XShape> xShape)33 ScVbaFillFormat::ScVbaFillFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape > xShape ) : ScVbaFillFormat_BASE( xParent, xContext ), m_xShape( xShape )
34 {
35     m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
36     m_nFillStyle = drawing::FillStyle_SOLID;
37     m_nForeColor = 0;
38     m_nBackColor = 0;
39     m_nGradientAngle = 0;
40 }
41 
42 void
setFillStyle(drawing::FillStyle nFillStyle)43 ScVbaFillFormat::setFillStyle( drawing::FillStyle nFillStyle ) throw (uno::RuntimeException)
44 {
45     m_nFillStyle = nFillStyle;
46     if( m_nFillStyle == drawing::FillStyle_GRADIENT )
47     {
48         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny( drawing::FillStyle_GRADIENT ) );
49         awt::Gradient aGradient;
50         // AXIAL
51         // RADIAL
52         // ELLIPTICAL
53         // SQUARE
54         // RECT
55         aGradient.Style = awt::GradientStyle_LINEAR;
56         aGradient.StartColor = ForeColor()->getRGB();
57         aGradient.EndColor = BackColor()->getRGB();
58         aGradient.Angle = m_nGradientAngle;
59         aGradient.Border = 0;
60         aGradient.XOffset = 0;
61         aGradient.YOffset = 0;
62         aGradient.StartIntensity = 100;
63         aGradient.EndIntensity = 100;
64         aGradient.StepCount = 1;
65         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillGradient"), uno::makeAny( aGradient ) );
66     }
67     else if( m_nFillStyle == drawing::FillStyle_SOLID )
68     {
69         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny(drawing::FillStyle_SOLID) );
70     }
71 }
72 
73 void
setForeColorAndInternalStyle(sal_Int32 nForeColor)74 ScVbaFillFormat::setForeColorAndInternalStyle( sal_Int32 nForeColor ) throw (css::uno::RuntimeException)
75 {
76     m_nForeColor = nForeColor;
77     setFillStyle( m_nFillStyle );
78 }
79 
80 // Attributes
81 sal_Bool SAL_CALL
getVisible()82 ScVbaFillFormat::getVisible() throw (uno::RuntimeException)
83 {
84     drawing::FillStyle nFillStyle;
85     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillStyle") ) >>= nFillStyle;
86     if( nFillStyle == drawing::FillStyle_NONE )
87         return sal_False;
88     return sal_True;
89 }
90 
91 void SAL_CALL
setVisible(sal_Bool _visible)92 ScVbaFillFormat::setVisible( sal_Bool _visible ) throw (uno::RuntimeException)
93 {
94     drawing::FillStyle aFillStyle;
95     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillStyle") ) >>= aFillStyle;
96     if( !_visible )
97     {
98         m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny( drawing::FillStyle_NONE ) );
99     }
100     else
101     {
102         if( aFillStyle == drawing::FillStyle_NONE )
103         {
104             setFillStyle( m_nFillStyle );
105         }
106     }
107 }
108 
109 double SAL_CALL
getTransparency()110 ScVbaFillFormat::getTransparency() throw (uno::RuntimeException)
111 {
112     sal_Int16 nTransparence = 0;
113     double dTransparence = 0;
114     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "FillTransparence" ) ) >>= nTransparence;
115     dTransparence = static_cast<double>( nTransparence );
116     dTransparence /= 100;
117     return dTransparence;
118 }
119 
120 void SAL_CALL
setTransparency(double _transparency)121 ScVbaFillFormat::setTransparency( double _transparency ) throw (uno::RuntimeException)
122 {
123     sal_Int16 nTransparence = static_cast< sal_Int16 >( _transparency * 100 );
124     m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillTransparence" ), uno::makeAny( nTransparence ) );
125 }
126 
127 
128 // Methods
129 void SAL_CALL
Solid()130 ScVbaFillFormat::Solid() throw (uno::RuntimeException)
131 {
132     setFillStyle( drawing::FillStyle_SOLID );
133 }
134 
135 void SAL_CALL
TwoColorGradient(sal_Int32 style,sal_Int32)136 ScVbaFillFormat::TwoColorGradient( sal_Int32 style, sal_Int32 /*variant*/ ) throw (uno::RuntimeException)
137 {
138     if( style == office::MsoGradientStyle::msoGradientHorizontal )
139     {
140         m_nGradientAngle = 0;
141         setFillStyle( drawing::FillStyle_GRADIENT );
142     }
143     else if( style == office::MsoGradientStyle::msoGradientVertical )
144     {
145         m_nGradientAngle = 900;
146         setFillStyle( drawing::FillStyle_GRADIENT );
147     }
148     else if( style == office::MsoGradientStyle::msoGradientDiagonalDown )
149     {
150         m_nGradientAngle = 450;
151         setFillStyle( drawing::FillStyle_GRADIENT );
152     }
153     else if( style == office::MsoGradientStyle::msoGradientDiagonalUp )
154     {
155         m_nGradientAngle = 900 + 450;
156         setFillStyle( drawing::FillStyle_GRADIENT );
157     }
158 }
159 
160 uno::Reference< msforms::XColorFormat > SAL_CALL
BackColor()161 ScVbaFillFormat::BackColor() throw (uno::RuntimeException)
162 {
163     if( !m_xColorFormat.is() )
164         m_xColorFormat.set( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ColorFormatType::FILLFORMAT_BACKCOLOR ) );
165     return m_xColorFormat;
166 }
167 
168 uno::Reference< msforms::XColorFormat > SAL_CALL
ForeColor()169 ScVbaFillFormat::ForeColor() throw (uno::RuntimeException)
170 {
171     if( !m_xColorFormat.is() )
172         m_xColorFormat.set( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ColorFormatType::FILLFORMAT_FORECOLOR ) );
173     return m_xColorFormat;
174 }
175 
176 
177 rtl::OUString&
getServiceImplName()178 ScVbaFillFormat::getServiceImplName()
179 {
180     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFillFormat") );
181     return sImplName;
182 }
183 
184 uno::Sequence< rtl::OUString >
getServiceNames()185 ScVbaFillFormat::getServiceNames()
186 {
187     static uno::Sequence< rtl::OUString > aServiceNames;
188     if ( aServiceNames.getLength() == 0 )
189     {
190         aServiceNames.realloc( 1 );
191         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.FillFormat" ) );
192     }
193     return aServiceNames;
194 }
195 
196