LibreOffice Module vbahelper (master) 1
vbafillformat.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include <com/sun/star/beans/XPropertySet.hpp>
20#include <com/sun/star/awt/Gradient.hpp>
21#include <com/sun/star/awt/GradientStyle.hpp>
22#include <ooo/vba/office/MsoGradientStyle.hpp>
23#include "vbafillformat.hxx"
24#include "vbacolorformat.hxx"
25
26using namespace ooo::vba;
27using namespace com::sun::star;
28
29ScVbaFillFormat::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 )
30{
31 m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
32 m_nFillStyle = drawing::FillStyle_SOLID;
33 m_nForeColor = 0;
35}
36
37void
38ScVbaFillFormat::setFillStyle( drawing::FillStyle nFillStyle )
39{
40 m_nFillStyle = nFillStyle;
41 if( m_nFillStyle == drawing::FillStyle_GRADIENT )
42 {
43 m_xPropertySet->setPropertyValue( "FillStyle" , uno::Any( drawing::FillStyle_GRADIENT ) );
44 awt::Gradient aGradient;
45 // AXIAL
46 // RADIAL
47 // ELLIPTICAL
48 // SQUARE
49 // RECT
50 aGradient.Style = awt::GradientStyle_LINEAR;
51 aGradient.StartColor = ForeColor()->getRGB();
52 aGradient.EndColor = BackColor()->getRGB();
53 aGradient.Angle = m_nGradientAngle;
54 aGradient.Border = 0;
55 aGradient.XOffset = 0;
56 aGradient.YOffset = 0;
57 aGradient.StartIntensity = 100;
58 aGradient.EndIntensity = 100;
59 aGradient.StepCount = 1;
60 m_xPropertySet->setPropertyValue( "FillGradient" , uno::Any( aGradient ) );
61 }
62 else if( m_nFillStyle == drawing::FillStyle_SOLID )
63 {
64 m_xPropertySet->setPropertyValue( "FillStyle" , uno::Any(drawing::FillStyle_SOLID) );
65 }
66}
67
68void
70{
71 m_nForeColor = nForeColor;
73}
74
75// Attributes
76sal_Bool SAL_CALL
78{
79 drawing::FillStyle nFillStyle;
80 m_xPropertySet->getPropertyValue( "FillStyle" ) >>= nFillStyle;
81 if( nFillStyle == drawing::FillStyle_NONE )
82 return false;
83 return true;
84}
85
86void SAL_CALL
88{
89 drawing::FillStyle aFillStyle;
90 m_xPropertySet->getPropertyValue( "FillStyle" ) >>= aFillStyle;
91 if( !_visible )
92 {
93 m_xPropertySet->setPropertyValue( "FillStyle" , uno::Any( drawing::FillStyle_NONE ) );
94 }
95 else
96 {
97 if( aFillStyle == drawing::FillStyle_NONE )
98 {
100 }
101 }
102}
103
104double SAL_CALL
106{
107 sal_Int16 nTransparence = 0;
108 double dTransparence = 0;
109 m_xPropertySet->getPropertyValue( "FillTransparence" ) >>= nTransparence;
110 dTransparence = static_cast<double>( nTransparence );
111 dTransparence /= 100;
112 return dTransparence;
113}
114
115void SAL_CALL
116ScVbaFillFormat::setTransparency( double _transparency )
117{
118 sal_Int16 nTransparence = static_cast< sal_Int16 >( _transparency * 100 );
119 m_xPropertySet->setPropertyValue( "FillTransparence" , uno::Any( nTransparence ) );
120}
121
122
123// Methods
124void SAL_CALL
126{
127 setFillStyle( drawing::FillStyle_SOLID );
128}
129
130void SAL_CALL
131ScVbaFillFormat::TwoColorGradient( sal_Int32 style, sal_Int32 /*variant*/ )
132{
133 if( style == office::MsoGradientStyle::msoGradientHorizontal )
134 {
136 setFillStyle( drawing::FillStyle_GRADIENT );
137 }
138 else if( style == office::MsoGradientStyle::msoGradientVertical )
139 {
140 m_nGradientAngle = 900;
141 setFillStyle( drawing::FillStyle_GRADIENT );
142 }
143 else if( style == office::MsoGradientStyle::msoGradientDiagonalDown )
144 {
145 m_nGradientAngle = 450;
146 setFillStyle( drawing::FillStyle_GRADIENT );
147 }
148 else if( style == office::MsoGradientStyle::msoGradientDiagonalUp )
149 {
150 m_nGradientAngle = 900 + 450;
151 setFillStyle( drawing::FillStyle_GRADIENT );
152 }
153}
154
155uno::Reference< msforms::XColorFormat > SAL_CALL
157{
158 if( !m_xColorFormat.is() )
160 return m_xColorFormat;
161}
162
163uno::Reference< msforms::XColorFormat > SAL_CALL
165{
166 if( !m_xColorFormat.is() )
168 return m_xColorFormat;
169}
170
171OUString
173{
174 return "ScVbaFillFormat";
175}
176
177uno::Sequence< OUString >
179{
180 static uno::Sequence< OUString > const aServiceNames
181 {
182 "ooo.vba.msforms.FillFormat"
183 };
184 return aServiceNames;
185}
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const sal_Int16 FILLFORMAT_FORECOLOR
static const sal_Int16 FILLFORMAT_BACKCOLOR
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
css::uno::Reference< css::beans::XPropertySet > m_xPropertySet
virtual OUString getServiceImplName() override
sal_Int32 m_nForeColor
virtual void SAL_CALL setTransparency(double _transparency) override
virtual sal_Bool SAL_CALL getVisible() override
virtual void SAL_CALL Solid() override
void setForeColorAndInternalStyle(sal_Int32 nForeColor)
css::uno::Reference< css::drawing::XShape > m_xShape
ScVbaFillFormat(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::drawing::XShape > &xShape)
virtual css::uno::Sequence< OUString > getServiceNames() override
void setFillStyle(css::drawing::FillStyle nFillStyle)
virtual void SAL_CALL setVisible(sal_Bool _visible) override
sal_Int16 m_nGradientAngle
virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL ForeColor() override
css::uno::Reference< ov::msforms::XColorFormat > m_xColorFormat
virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL BackColor() override
virtual double SAL_CALL getTransparency() override
virtual void SAL_CALL TwoColorGradient(sal_Int32 style, sal_Int32 variant) override
css::drawing::FillStyle m_nFillStyle
Sequence< OUString > aServiceNames
unsigned char sal_Bool