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