1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridcolumnproptranslator.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "gridcolumnproptranslator.hxx"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/beans/XPropertySetInfo.hpp>
37 #include <com/sun/star/awt/TextAlign.hpp>
38 #include <com/sun/star/style/ParagraphAdjust.hpp>
39 /** === end UNO includes === **/
40 #include <osl/diagnose.h>
41 #include <cppuhelper/implbase1.hxx>
45 //........................................................................
48 //........................................................................
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::awt
;
52 using namespace ::com::sun::star::lang
;
53 using namespace ::com::sun::star::beans
;
54 using namespace ::com::sun::star::style
;
58 //----------------------------------------------------------------
59 ::rtl::OUString
getParaAlignProperty()
61 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParaAdjust" ) );
64 //----------------------------------------------------------------
65 ::rtl::OUString
getAlignProperty()
67 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Align" ) );
70 //----------------------------------------------------------------
71 sal_Int32
findStringElement( const Sequence
< ::rtl::OUString
>& _rNames
, const ::rtl::OUString
& _rName
)
73 const ::rtl::OUString
* pStart
= _rNames
.getConstArray();
74 const ::rtl::OUString
* pEnd
= _rNames
.getConstArray() + _rNames
.getLength();
75 const ::rtl::OUString
* pPos
= ::std::find( pStart
, pEnd
, _rName
);
81 //----------------------------------------------------------------
82 struct AlignmentTranslationEntry
84 ParagraphAdjust nParagraphValue
;
85 sal_Int16 nControlValue
;
87 AlignmentTranslations
[] =
89 // note that order matters:
90 // valueAlignToParaAdjust and valueParaAdjustToAlign search this map from the _beginning_
91 // and use the first matching entry
92 { ParagraphAdjust_LEFT
, TextAlign::LEFT
},
93 { ParagraphAdjust_CENTER
, TextAlign::CENTER
},
94 { ParagraphAdjust_RIGHT
, TextAlign::RIGHT
},
95 { ParagraphAdjust_BLOCK
, TextAlign::RIGHT
},
96 { ParagraphAdjust_STRETCH
, TextAlign::LEFT
},
97 { ParagraphAdjust_MAKE_FIXED_SIZE
, TextAlign::LEFT
},
98 { ParagraphAdjust_MAKE_FIXED_SIZE
, -1 }
101 //----------------------------------------------------------------
102 void valueAlignToParaAdjust(Any
& rValue
)
104 sal_Int16 nValue
= 0;
106 const AlignmentTranslationEntry
* pTranslation
= AlignmentTranslations
;
107 while (-1 != pTranslation
->nControlValue
)
109 if ( nValue
== pTranslation
->nControlValue
)
111 rValue
<<= pTranslation
->nParagraphValue
;
116 OSL_ENSURE( sal_False
, "valueAlignToParaAdjust: unreachable!" );
119 //----------------------------------------------------------------
120 void valueParaAdjustToAlign(Any
& rValue
)
122 sal_Int32 nValue
= 0;
124 const AlignmentTranslationEntry
* pTranslation
= AlignmentTranslations
;
125 while ( ParagraphAdjust_MAKE_FIXED_SIZE
!= pTranslation
->nParagraphValue
)
127 if ( nValue
== pTranslation
->nParagraphValue
)
129 rValue
<<= pTranslation
->nControlValue
;
134 OSL_ENSURE( sal_False
, "valueParaAdjustToAlign: unreachable!" );
137 //====================================================================
138 //= OMergedPropertySetInfo
139 //====================================================================
140 typedef ::cppu::WeakAggImplHelper1
< XPropertySetInfo
141 > OMergedPropertySetInfo_Base
;
142 class OMergedPropertySetInfo
: public OMergedPropertySetInfo_Base
145 Reference
< XPropertySetInfo
> m_xMasterInfo
;
148 OMergedPropertySetInfo( const Reference
< XPropertySetInfo
>& _rxMasterInfo
);
151 virtual ~OMergedPropertySetInfo();
154 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
> SAL_CALL
getProperties( ) throw (::com::sun::star::uno::RuntimeException
);
155 virtual ::com::sun::star::beans::Property SAL_CALL
getPropertyByName( const ::rtl::OUString
& aName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
156 virtual ::sal_Bool SAL_CALL
hasPropertyByName( const ::rtl::OUString
& Name
) throw (::com::sun::star::uno::RuntimeException
);
159 //----------------------------------------------------------------
160 OMergedPropertySetInfo::OMergedPropertySetInfo( const Reference
< XPropertySetInfo
>& _rxMasterInfo
)
161 :m_xMasterInfo( _rxMasterInfo
)
163 OSL_ENSURE( m_xMasterInfo
.is(), "OMergedPropertySetInfo::OMergedPropertySetInfo: hmm?" );
166 //----------------------------------------------------------------
167 OMergedPropertySetInfo::~OMergedPropertySetInfo()
171 //----------------------------------------------------------------
172 Sequence
< Property
> SAL_CALL
OMergedPropertySetInfo::getProperties( ) throw (RuntimeException
)
174 // add a "ParaAdjust" property to the master properties
175 Sequence
< Property
> aProperties
;
176 if ( m_xMasterInfo
.is() )
177 aProperties
= m_xMasterInfo
->getProperties();
179 sal_Int32 nOldLength
= aProperties
.getLength();
180 aProperties
.realloc( nOldLength
+ 1 );
181 aProperties
[ nOldLength
] = getPropertyByName( getParaAlignProperty() );
186 //----------------------------------------------------------------
187 Property SAL_CALL
OMergedPropertySetInfo::getPropertyByName( const ::rtl::OUString
& aName
) throw (UnknownPropertyException
, RuntimeException
)
189 if ( aName
== getParaAlignProperty() )
190 return Property( getParaAlignProperty(), -1,
191 ::getCppuType( static_cast< const ParagraphAdjust
* >( NULL
) ), 0 );
193 if ( !m_xMasterInfo
.is() )
196 return m_xMasterInfo
->getPropertyByName( aName
);
199 //----------------------------------------------------------------
200 ::sal_Bool SAL_CALL
OMergedPropertySetInfo::hasPropertyByName( const ::rtl::OUString
& Name
) throw (RuntimeException
)
202 if ( Name
== getParaAlignProperty() )
205 if ( !m_xMasterInfo
.is() )
208 return m_xMasterInfo
->hasPropertyByName( Name
);
213 //====================================================================
214 //= OGridColumnPropertyTranslator
215 //====================================================================
216 //--------------------------------------------------------------------
217 OGridColumnPropertyTranslator::OGridColumnPropertyTranslator( const Reference
< XMultiPropertySet
>& _rxGridColumn
)
218 :m_xGridColumn( _rxGridColumn
)
220 OSL_ENSURE( m_xGridColumn
.is(), "OGridColumnPropertyTranslator: invalid grid column!" );
223 //--------------------------------------------------------------------
224 OGridColumnPropertyTranslator::~OGridColumnPropertyTranslator()
228 //--------------------------------------------------------------------
229 Reference
< XPropertySetInfo
> SAL_CALL
OGridColumnPropertyTranslator::getPropertySetInfo( ) throw (RuntimeException
)
231 Reference
< XPropertySetInfo
> xColumnPropInfo
;
232 if ( m_xGridColumn
.is() )
233 xColumnPropInfo
= m_xGridColumn
->getPropertySetInfo();
234 return new OMergedPropertySetInfo( xColumnPropInfo
);
237 //--------------------------------------------------------------------
238 void SAL_CALL
OGridColumnPropertyTranslator::setPropertyValue( const ::rtl::OUString
& aPropertyName
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
240 Sequence
< ::rtl::OUString
> aNames( &aPropertyName
, 1 );
241 Sequence
< Any
> aValues( &aValue
, 1 );
242 setPropertyValues( aNames
, aValues
);
245 //--------------------------------------------------------------------
246 Any SAL_CALL
OGridColumnPropertyTranslator::getPropertyValue( const ::rtl::OUString
& PropertyName
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
248 Sequence
< ::rtl::OUString
> aNames( &PropertyName
, 1 );
249 Sequence
< Any
> aValues
= getPropertyValues( aNames
);
250 OSL_ENSURE( aValues
.getLength() == 1, "OGridColumnPropertyTranslator::getPropertyValue: nonsense!" );
251 if ( aValues
.getLength() == 1 )
256 //--------------------------------------------------------------------
257 void SAL_CALL
OGridColumnPropertyTranslator::addPropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
259 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::addPropertyChangeListener: not implemented - this should not be needed!" );
262 //--------------------------------------------------------------------
263 void SAL_CALL
OGridColumnPropertyTranslator::removePropertyChangeListener( const ::rtl::OUString
&, const Reference
< XPropertyChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
265 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::removePropertyChangeListener: not implemented - this should not be needed!" );
268 //--------------------------------------------------------------------
269 void SAL_CALL
OGridColumnPropertyTranslator::addVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
271 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::addVetoableChangeListener: not implemented - this should not be needed!" );
274 //--------------------------------------------------------------------
275 void SAL_CALL
OGridColumnPropertyTranslator::removeVetoableChangeListener( const ::rtl::OUString
&, const Reference
< XVetoableChangeListener
>& ) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
277 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::removeVetoableChangeListener: not implemented - this should not be needed!" );
280 //--------------------------------------------------------------------
281 void SAL_CALL
OGridColumnPropertyTranslator::setPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
, const Sequence
< Any
>& aValues
) throw (PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
283 if ( !m_xGridColumn
.is() )
286 // if there's ever the need for more than one property being translated, then we should
287 // certainly have a more clever implementation than this ...
289 Sequence
< ::rtl::OUString
> aTranslatedNames( aPropertyNames
);
290 Sequence
< Any
> aTranslatedValues( aValues
);
292 sal_Int32 nParaAlignPos
= findStringElement( aTranslatedNames
, getParaAlignProperty() );
293 if ( nParaAlignPos
!= -1 )
295 aTranslatedNames
[ nParaAlignPos
] = getAlignProperty();
296 valueParaAdjustToAlign( aTranslatedValues
[ nParaAlignPos
] );
299 m_xGridColumn
->setPropertyValues( aTranslatedNames
, aTranslatedValues
);
302 //--------------------------------------------------------------------
303 Sequence
< Any
> SAL_CALL
OGridColumnPropertyTranslator::getPropertyValues( const Sequence
< ::rtl::OUString
>& aPropertyNames
) throw (RuntimeException
)
305 Sequence
< Any
> aValues( aPropertyNames
.getLength() );
306 if ( !m_xGridColumn
.is() )
309 Sequence
< ::rtl::OUString
> aTranslatedNames( aPropertyNames
);
310 sal_Int32 nAlignPos
= findStringElement( aTranslatedNames
, getParaAlignProperty() );
311 if ( nAlignPos
!= -1 )
312 aTranslatedNames
[ nAlignPos
] = getAlignProperty();
314 aValues
= m_xGridColumn
->getPropertyValues( aPropertyNames
);
315 if ( nAlignPos
!= -1 )
316 valueAlignToParaAdjust( aValues
[ nAlignPos
] );
321 //--------------------------------------------------------------------
322 void SAL_CALL
OGridColumnPropertyTranslator::addPropertiesChangeListener( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
324 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::addPropertiesChangeListener: not implemented - this should not be needed!" );
327 //--------------------------------------------------------------------
328 void SAL_CALL
OGridColumnPropertyTranslator::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
330 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::removePropertiesChangeListener: not implemented - this should not be needed!" );
333 //--------------------------------------------------------------------
334 void SAL_CALL
OGridColumnPropertyTranslator::firePropertiesChangeEvent( const Sequence
< ::rtl::OUString
>&, const Reference
< XPropertiesChangeListener
>& ) throw (RuntimeException
)
336 OSL_ENSURE( sal_False
, "OGridColumnPropertyTranslator::firePropertiesChangeEvent: not implemented - this should not be needed!" );
339 //........................................................................
340 } // namespace xmloff
341 //........................................................................