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
25#include <osl/diagnose.h>
26#include <com/sun/star/drawing/FillStyle.hpp>
27
28using namespace ::com::sun::star;
29using namespace ::com::sun::star::beans;
30
31using ::com::sun::star::uno::Reference;
32using ::com::sun::star::uno::Sequence;
33
34namespace
35{
36class lcl_ColorPropertySetInfo : public ::cppu::WeakImplHelper<
37 XPropertySetInfo >
38{
39public:
40 explicit lcl_ColorPropertySetInfo( bool bFillColor );
41
42protected:
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
48private:
49 OUString m_aColorPropName;
50 Property m_aColorProp;
51};
52
53lcl_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
60Sequence< Property > SAL_CALL lcl_ColorPropertySetInfo::getProperties()
61{
62
63 return Sequence< Property >( & m_aColorProp, 1 );
64}
65
66Property SAL_CALL lcl_ColorPropertySetInfo::getPropertyByName( const OUString& aName )
67{
68 if( aName == m_aColorPropName )
69 return m_aColorProp;
70 throw UnknownPropertyException( m_aColorPropName, getXWeak());
71}
72
73sal_Bool SAL_CALL lcl_ColorPropertySetInfo::hasPropertyByName( const OUString& Name )
74{
75 return Name == m_aColorPropName;
76}
77
78} // anonymous namespace
79
80namespace oox::drawingml
81{
82
83ColorPropertySet::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
104void 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
116uno::Any SAL_CALL ColorPropertySet::getPropertyValue( const OUString& aPropertyName )
117{
118 if( aPropertyName == "FillStyle" && m_bIsFillColor )
119 {
120 return uno::Any(css::drawing::FillStyle_SOLID);
121 }
122 else if (aPropertyName == m_aColorPropName)
123 return uno::Any( m_nColor );
124
125 throw UnknownPropertyException(aPropertyName);
126}
127
128void SAL_CALL ColorPropertySet::addPropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* xListener */ )
129{
130 OSL_FAIL( "Not Implemented" );
131}
132
133void SAL_CALL ColorPropertySet::removePropertyChangeListener( const OUString& /* aPropertyName */, const Reference< XPropertyChangeListener >& /* aListener */ )
134{
135 OSL_FAIL( "Not Implemented" );
136}
137
138void SAL_CALL ColorPropertySet::addVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
139{
140 OSL_FAIL( "Not Implemented" );
141}
142
143void SAL_CALL ColorPropertySet::removeVetoableChangeListener( const OUString& /* PropertyName */, const Reference< XVetoableChangeListener >& /* aListener */ )
144{
145 OSL_FAIL( "Not Implemented" );
146}
147
148// ____ XPropertyState ____
149
150PropertyState 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
162void SAL_CALL ColorPropertySet::setPropertyToDefault( const OUString& PropertyName )
163{
164 if( PropertyName == m_aColorPropName )
166}
167
168uno::Any SAL_CALL ColorPropertySet::getPropertyDefault( const OUString& aPropertyName )
169{
170 if( aPropertyName == m_aColorPropName )
171 return uno::Any( 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::beans::XPropertySetInfo > m_xInfo
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
ColorPropertySet(::Color nColor, bool bFillColor=true)
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 css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString Name
unsigned char sal_Bool