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