1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "LineProperties.hxx"
31 #include "macros.hxx"
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/drawing/LineStyle.hpp>
34 #include <com/sun/star/drawing/LineDash.hpp>
35 #include <com/sun/star/drawing/LineJoint.hpp>
36 
37 using namespace ::com::sun::star;
38 
39 using ::com::sun::star::beans::Property;
40 
41 namespace chart
42 {
43 
44 void LineProperties::AddPropertiesToVector(
45     ::std::vector< Property > & rOutProperties )
46 {
47     // Line Properties see service drawing::LineProperties
48     // ---------------
49     rOutProperties.push_back(
50         Property( C2U( "LineStyle" ),
51                   PROP_LINE_STYLE,
52                   ::getCppuType( reinterpret_cast< const drawing::LineStyle * >(0)),
53                   beans::PropertyAttribute::BOUND
54                   | beans::PropertyAttribute::MAYBEDEFAULT ));
55 
56      rOutProperties.push_back(
57          Property( C2U( "LineDash" ),
58                    PROP_LINE_DASH,
59                    ::getCppuType( reinterpret_cast< const drawing::LineDash * >(0)),
60                    beans::PropertyAttribute::BOUND
61                    | beans::PropertyAttribute::MAYBEVOID ));
62 
63 //not in service description
64     rOutProperties.push_back(
65         Property( C2U( "LineDashName" ),
66                   PROP_LINE_DASH_NAME,
67                   ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)),
68                   beans::PropertyAttribute::BOUND
69                   | beans::PropertyAttribute::MAYBEDEFAULT
70                   | beans::PropertyAttribute::MAYBEVOID ));
71 
72     rOutProperties.push_back(
73         Property( C2U( "LineColor" ),
74                   PROP_LINE_COLOR,
75                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
76                   beans::PropertyAttribute::BOUND
77                   | beans::PropertyAttribute::MAYBEDEFAULT ));
78 
79     rOutProperties.push_back(
80         Property( C2U( "LineTransparence" ),
81                   PROP_LINE_TRANSPARENCE,
82                   ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)),
83                   beans::PropertyAttribute::BOUND
84                   | beans::PropertyAttribute::MAYBEDEFAULT ));
85 
86     rOutProperties.push_back(
87         Property( C2U( "LineWidth" ),
88                   PROP_LINE_WIDTH,
89                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
90                   beans::PropertyAttribute::BOUND
91                   | beans::PropertyAttribute::MAYBEDEFAULT ));
92 
93     rOutProperties.push_back(
94         Property( C2U( "LineJoint" ),
95                   PROP_LINE_JOINT,
96                   ::getCppuType( reinterpret_cast< const drawing::LineJoint * >(0)),
97                   beans::PropertyAttribute::BOUND
98                   | beans::PropertyAttribute::MAYBEDEFAULT ));
99 }
100 
101 void LineProperties::AddDefaultsToMap(
102     ::chart::tPropertyValueMap & rOutMap )
103 {
104     ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINE_STYLE, drawing::LineStyle_SOLID );
105     ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINE_WIDTH, 0 );
106     ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINE_COLOR, 0x000000 );  // black
107     ::chart::PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, PROP_LINE_TRANSPARENCE, 0 );
108     ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINE_JOINT, drawing::LineJoint_ROUND );
109 }
110 
111 bool LineProperties::IsLineVisible( const ::com::sun::star::uno::Reference<
112         ::com::sun::star::beans::XPropertySet >& xLineProperties )
113 {
114     bool bRet = false;
115     try
116     {
117         if( xLineProperties.is() )
118         {
119             drawing::LineStyle aLineStyle(drawing::LineStyle_SOLID);
120             xLineProperties->getPropertyValue( C2U( "LineStyle" ) ) >>= aLineStyle;
121             if( aLineStyle != drawing::LineStyle_NONE )
122             {
123                 sal_Int16 nLineTransparence=0;
124                 xLineProperties->getPropertyValue( C2U( "LineTransparence" ) ) >>= nLineTransparence;
125                 if(100!=nLineTransparence)
126                 {
127                     bRet = true;
128                 }
129             }
130         }
131     }
132     catch( const uno::Exception & ex )
133     {
134         ASSERT_EXCEPTION( ex );
135     }
136     return bRet;
137 }
138 
139 void LineProperties::SetLineVisible( const ::com::sun::star::uno::Reference<
140     ::com::sun::star::beans::XPropertySet >& xLineProperties )
141 {
142     try
143     {
144         if( xLineProperties.is() )
145         {
146             drawing::LineStyle aLineStyle(drawing::LineStyle_SOLID);
147             xLineProperties->getPropertyValue( C2U( "LineStyle" ) ) >>= aLineStyle;
148             if( aLineStyle == drawing::LineStyle_NONE )
149                 xLineProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID ) );
150 
151             sal_Int16 nLineTransparence=0;
152             xLineProperties->getPropertyValue( C2U( "LineTransparence" ) ) >>= nLineTransparence;
153             if(100==nLineTransparence)
154                 xLineProperties->setPropertyValue( C2U( "LineTransparence" ), uno::makeAny( sal_Int16(0) ) );
155         }
156     }
157     catch( const uno::Exception & ex )
158     {
159         ASSERT_EXCEPTION( ex );
160     }
161 }
162 
163 void LineProperties::SetLineInvisible( const ::com::sun::star::uno::Reference<
164     ::com::sun::star::beans::XPropertySet >& xLineProperties )
165 {
166     try
167     {
168         if( xLineProperties.is() )
169         {
170             drawing::LineStyle aLineStyle(drawing::LineStyle_SOLID);
171             xLineProperties->getPropertyValue( C2U( "LineStyle" ) ) >>= aLineStyle;
172             if( aLineStyle != drawing::LineStyle_NONE )
173                 xLineProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
174         }
175     }
176     catch( const uno::Exception & ex )
177     {
178         ASSERT_EXCEPTION( ex );
179     }
180 }
181 
182 } //  namespace chart
183