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 "vbapictureformat.hxx"
24 
25 using namespace ooo::vba;
26 using namespace com::sun::star;
27 
ScVbaPictureFormat(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,uno::Reference<drawing::XShape> xShape)28 ScVbaPictureFormat::ScVbaPictureFormat( const css::uno::Reference< ov::XHelperInterface >& xParent,
29     const css::uno::Reference< css::uno::XComponentContext >& xContext,
30     uno::Reference< drawing::XShape > xShape )
31     throw( lang::IllegalArgumentException ) : ScVbaPictureFormat_BASE( xParent, xContext ), m_xShape( xShape )
32 {
33     m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW );
34 }
35 
36 void
checkParameterRangeInDouble(double nRange,double nMin,double nMax)37 ScVbaPictureFormat::checkParameterRangeInDouble( double nRange, double nMin, double nMax ) throw (css::uno::RuntimeException)
38 {
39     if( nRange < nMin )
40     {
41         throw uno::RuntimeException( rtl::OUString::createFromAscii("Parameter out of range, value is too small.") , uno::Reference< uno::XInterface >() );
42     }
43     if( nRange > nMax )
44     {
45         throw uno::RuntimeException( rtl::OUString::createFromAscii("Parameter out of range, value is too high.") , uno::Reference< uno::XInterface >() );
46     }
47 }
48 
49 // Attributes
50 double SAL_CALL
getBrightness()51 ScVbaPictureFormat::getBrightness() throw (uno::RuntimeException)
52 {
53     sal_Int16 nLuminance = 0;
54     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("AdjustLuminance") ) >>= nLuminance;
55     double fBrightness = static_cast< double >( nLuminance );
56     fBrightness = ( fBrightness +100 ) / 200;
57     return fBrightness;
58 }
59 
60 void SAL_CALL
setBrightness(double _brightness)61 ScVbaPictureFormat::setBrightness( double _brightness ) throw (uno::RuntimeException)
62 {
63     checkParameterRangeInDouble( _brightness, 0.0, 1.0 );
64     double fLuminance = _brightness * 200 - 100;
65     sal_Int16 nLuminance = static_cast< sal_Int16 >( fLuminance );
66     m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("AdjustLuminance"), uno::makeAny( nLuminance ) );
67 }
68 
69 double SAL_CALL
getContrast()70 ScVbaPictureFormat::getContrast() throw (uno::RuntimeException)
71 {
72     sal_Int16 nContrast = 0;
73     m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("AdjustContrast") ) >>= nContrast;
74     double fContrast = static_cast< double >( nContrast );
75     fContrast = ( fContrast + 100 ) / 200;
76     return fContrast;
77 }
78 
79 void SAL_CALL
setContrast(double _contrast)80 ScVbaPictureFormat::setContrast( double _contrast ) throw (uno::RuntimeException)
81 {
82     checkParameterRangeInDouble( _contrast, 0.0, 1.0 );
83     double fContrast = _contrast * 200 - 100;
84     sal_Int16 nContrast = static_cast< sal_Int16 >( fContrast );
85     m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("AdjustContrast"), uno::makeAny( nContrast ) );
86 }
87 
88 
89 // Methods
90 void SAL_CALL
IncrementBrightness(double increment)91 ScVbaPictureFormat::IncrementBrightness( double increment ) throw (uno::RuntimeException)
92 {
93     double fBrightness = getBrightness();
94     fBrightness += increment;
95     if( fBrightness < 0 )
96     {
97         fBrightness = 0.0;
98     }
99     if( fBrightness > 1 )
100     {
101         fBrightness = 1;
102     }
103     setBrightness( fBrightness );
104 }
105 
106 void SAL_CALL
IncrementContrast(double increment)107 ScVbaPictureFormat::IncrementContrast( double increment ) throw (uno::RuntimeException)
108 {
109     double nContrast = getContrast();
110     nContrast += increment;
111     if( increment < 0 )
112     {
113         increment = 0.0;
114     }
115     if( increment > 1 )
116     {
117         increment = 1.0;
118     }
119     setContrast( nContrast );
120 }
121 
122 
123 rtl::OUString&
getServiceImplName()124 ScVbaPictureFormat::getServiceImplName()
125 {
126     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPictureFormat") );
127     return sImplName;
128 }
129 
130 uno::Sequence< rtl::OUString >
getServiceNames()131 ScVbaPictureFormat::getServiceNames()
132 {
133     static uno::Sequence< rtl::OUString > aServiceNames;
134     if ( aServiceNames.getLength() == 0 )
135     {
136         aServiceNames.realloc( 1 );
137         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.PictureFormat" ) );
138     }
139     return aServiceNames;
140 }
141