LibreOffice Module oox (master)  1
ColorPropertySet.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 
20 // FIXME? This file is nearly identical to xmloff/source/chart/ColorPropertySet.cxx
21 
22 #include "ColorPropertySet.hxx"
23 
24 #include <cppuhelper/implbase.hxx>
25 #include <osl/diagnose.h>
26 #include <com/sun/star/drawing/FillStyle.hpp>
27 
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::beans;
30 
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Sequence;
33 
34 namespace
35 {
36 class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper<
37  XPropertySetInfo >
38 {
39 public:
40  explicit lcl_ColorPropertySetInfo( bool bFillColor );
41 
42 protected:
43  // ____ XPropertySetInfo ____
44  virtual Sequence< Property > SAL_CALL getProperties() override;
45  virtual Property SAL_CALL getPropertyByName( const OUString& aName ) override;
46  virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override;
47 
48 private:
49  OUString m_aColorPropName;
50  Property m_aColorProp;
51 };
52 
53 lcl_ColorPropertySetInfo::lcl_ColorPropertySetInfo( bool bFillColor ) :
54  // note: length of FillColor and LineColor is 9
55  m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
56  m_aColorProp( m_aColorPropName, -1,
57  cppu::UnoType<sal_Int32>::get(), 0)
58 {}
59 
60 Sequence< Property > SAL_CALL lcl_ColorPropertySetInfo::getProperties()
61 {
62 
63  return Sequence< Property >( & m_aColorProp, 1 );
64 }
65 
66 Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
67 {
68  if( aName == m_aColorPropName )
69  return m_aColorProp;
70  throw UnknownPropertyException( m_aColorPropName, static_cast< uno::XWeak * >( this ));
71 }
72 
73 sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
74 {
75  return Name == m_aColorPropName;
76 }
77 
78 } // anonymous namespace
79 
80 namespace oox::drawingml
81 {
82 
83 ColorPropertySet::ColorPropertySet( ::Color nColor, bool bFillColor /* = true */ ) :
84  // note: length of FillColor and LineColor is 9
85  m_aColorPropName( (bFillColor ? "FillColor" : "LineColor"), 9, RTL_TEXTENCODING_ASCII_US ),
86  m_nColor( nColor ),
87  m_bIsFillColor( bFillColor ),
88  m_nDefaultColor( 0x0099ccff ) // blue 8
89 {}
90 
92 {}
93 
94 // ____ XPropertySet ____
95 
97 {
98  if( ! m_xInfo.is())
99  m_xInfo.set( new lcl_ColorPropertySetInfo( m_bIsFillColor ));
100 
101  return m_xInfo;
102 }
103 
104 void SAL_CALL ColorPropertySet::setPropertyValue( const OUString& rPropertyName, const uno::Any& aValue )
105 {
106  if (rPropertyName != m_aColorPropName)
107  {
108  // trying to catch these cases in the next crash testing
109  assert(false);
110  return;
111  }
112 
113  aValue >>= m_nColor;
114 }
115 
116 uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& aPropertyName )
117 {
118  if( aPropertyName == "FillStyle" && m_bIsFillColor )
119  {
120  return uno::makeAny(css::drawing::FillStyle_SOLID);
121  }
122  else if (aPropertyName == m_aColorPropName)
123  return uno::makeAny( m_nColor );
124 
125  throw UnknownPropertyException(aPropertyName);
126 }
127 
128 void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
129 {
130  OSL_FAIL( "Not Implemented" );
131 }
132 
133 void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
134 {
135  OSL_FAIL( "Not Implemented" );
136 }
137 
138 void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
139 {
140  OSL_FAIL( "Not Implemented" );
141 }
142 
143 void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
144 {
145  OSL_FAIL( "Not Implemented" );
146 }
147 
148 // ____ XPropertyState ____
149 
150 PropertyState SAL_CALL ColorPropertySet::getPropertyState( const OUString& /* PropertyName */ )
151 {
152  return PropertyState_DIRECT_VALUE;
153 }
154 
156 {
157  PropertyState aState = PropertyState_DIRECT_VALUE;
158  // coverity[overrun-buffer-arg : FALSE] - coverity has difficulty with css::uno::Sequence
159  return Sequence<PropertyState>(&aState, 1);
160 }
161 
162 void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
163 {
164  if( PropertyName == m_aColorPropName )
166 }
167 
168 uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
169 {
170  if( aPropertyName == m_aColorPropName )
171  return uno::makeAny( m_nDefaultColor );
172 
173  return uno::Any();
174 }
175 
176 } // namespace oox::drawingml
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
unsigned char sal_Bool
ColorPropertySet(::Color nColor, bool bFillColor=true)
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override