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: PropertyForward.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 ************************************************************************/
30 #include "PropertyForward.hxx"
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <comphelper/property.hxx>
34 #include <com/sun/star/sdbcx/XAppend.hpp>
35 #include <tools/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include "corestrings.hrc"
39 //........................................................................
42 //........................................................................
43 using namespace ::com::sun::star::uno
;
44 using namespace ::com::sun::star::beans
;
45 using namespace reportdesign
;
47 DBG_NAME( rpt_OPropertyMediator
)
48 OPropertyMediator::OPropertyMediator(const Reference
< XPropertySet
>& _xSource
49 ,const Reference
< XPropertySet
>& _xDest
50 ,const TPropertyNamePair
& _aNameMap
52 : OPropertyForward_Base(m_aMutex
)
53 ,m_aNameMap(_aNameMap
)
56 ,m_bInChange(sal_False
)
58 DBG_CTOR( rpt_OPropertyMediator
,NULL
);
59 osl_incrementInterlockedCount(&m_refCount
);
60 OSL_ENSURE(m_xDest
.is(),"Dest is NULL!");
61 OSL_ENSURE(m_xSource
.is(),"Source is NULL!");
62 if ( m_xDest
.is() && m_xSource
.is() )
66 m_xDestInfo
= m_xDest
->getPropertySetInfo();
67 m_xSourceInfo
= m_xSource
->getPropertySetInfo();
70 ::comphelper::copyProperties(m_xDest
,m_xSource
);
71 TPropertyNamePair::iterator aIter
= m_aNameMap
.begin();
72 TPropertyNamePair::iterator aEnd
= m_aNameMap
.end();
73 for (; aIter
!= aEnd
; ++aIter
)
75 Property aProp
= m_xSourceInfo
->getPropertyByName(aIter
->first
);
76 if (0 == (aProp
.Attributes
& PropertyAttribute::READONLY
))
78 Any aValue
= _xDest
->getPropertyValue(aIter
->second
.first
);
79 if ( 0 != (aProp
.Attributes
& PropertyAttribute::MAYBEVOID
) || aValue
.hasValue() )
80 _xSource
->setPropertyValue(aIter
->first
,aIter
->second
.second
->operator()(aIter
->second
.first
,aValue
));
86 ::comphelper::copyProperties(m_xSource
,m_xDest
);
87 TPropertyNamePair::iterator aIter
= m_aNameMap
.begin();
88 TPropertyNamePair::iterator aEnd
= m_aNameMap
.end();
89 for (; aIter
!= aEnd
; ++aIter
)
90 _xDest
->setPropertyValue(aIter
->second
.first
,aIter
->second
.second
->operator()(aIter
->second
.first
,_xSource
->getPropertyValue(aIter
->first
)));
96 DBG_UNHANDLED_EXCEPTION();
99 } // if ( m_xDest.is() && m_xSource.is() )
100 osl_decrementInterlockedCount(&m_refCount
);
102 // -----------------------------------------------------------------------------
103 OPropertyMediator::~OPropertyMediator()
105 DBG_DTOR( rpt_OPropertyMediator
,NULL
);
107 // -----------------------------------------------------------------------------
108 void SAL_CALL
OPropertyMediator::propertyChange( const PropertyChangeEvent
& evt
) throw(RuntimeException
)
110 ::osl::MutexGuard
aGuard(m_aMutex
);
113 m_bInChange
= sal_True
;
116 sal_Bool bDest
= (evt
.Source
== m_xDest
);
117 Reference
<XPropertySet
> xProp
= bDest
? m_xSource
: m_xDest
;
118 Reference
<XPropertySetInfo
> xPropInfo
= bDest
? m_xSourceInfo
: m_xDestInfo
;
121 if ( xPropInfo
.is() )
123 if ( xPropInfo
->hasPropertyByName(evt
.PropertyName
) )
124 xProp
->setPropertyValue(evt
.PropertyName
,evt
.NewValue
);
127 TPropertyNamePair::iterator aFind
= m_aNameMap
.find(evt
.PropertyName
);
128 ::rtl::OUString sPropName
;
129 if ( aFind
!= m_aNameMap
.end() )
130 sPropName
= aFind
->second
.first
;
133 aFind
= ::std::find_if(
137 ::std::bind2nd(::std::equal_to
< ::rtl::OUString
>(), evt
.PropertyName
),
138 ::std::compose1(::std::select1st
<TPropertyConverter
>(),::std::select2nd
<TPropertyNamePair::value_type
>())
141 if ( aFind
!= m_aNameMap
.end() )
142 sPropName
= aFind
->first
;
144 if ( sPropName
.getLength() && xPropInfo
->hasPropertyByName(sPropName
) )
145 xProp
->setPropertyValue(sPropName
,aFind
->second
.second
->operator()(sPropName
,evt
.NewValue
));
146 else if ( evt
.PropertyName
== PROPERTY_CHARFONTNAME
147 || evt
.PropertyName
== PROPERTY_CHARFONTSTYLENAME
148 || evt
.PropertyName
== PROPERTY_CHARSTRIKEOUT
149 || evt
.PropertyName
== PROPERTY_CHARWORDMODE
150 || evt
.PropertyName
== PROPERTY_CHARROTATION
151 || evt
.PropertyName
== PROPERTY_CHARSCALEWIDTH
152 || evt
.PropertyName
== PROPERTY_CHARFONTFAMILY
153 || evt
.PropertyName
== PROPERTY_CHARFONTCHARSET
154 || evt
.PropertyName
== PROPERTY_CHARFONTPITCH
155 || evt
.PropertyName
== PROPERTY_CHARHEIGHT
156 || evt
.PropertyName
== PROPERTY_CHARUNDERLINE
157 || evt
.PropertyName
== PROPERTY_CHARWEIGHT
158 || evt
.PropertyName
== PROPERTY_CHARPOSTURE
)
160 xProp
->setPropertyValue(PROPERTY_FONTDESCRIPTOR
,m_xSource
->getPropertyValue(PROPERTY_FONTDESCRIPTOR
));
168 OSL_ENSURE(0,"Exception catched!");
170 m_bInChange
= sal_False
;
173 // -----------------------------------------------------------------------------
174 void SAL_CALL
OPropertyMediator::disposing( const ::com::sun::star::lang::EventObject
& /*_rSource*/ ) throw (RuntimeException
)
176 ::osl::MutexGuard
aGuard(m_aMutex
);
179 // -----------------------------------------------------------------------------
180 void SAL_CALL
OPropertyMediator::disposing()
184 m_xSourceInfo
.clear();
188 // -----------------------------------------------------------------------------
189 void OPropertyMediator::stopListening()
191 if ( m_xSource
.is() )
192 m_xSource
->removePropertyChangeListener(::rtl::OUString(), this);
194 m_xDest
->removePropertyChangeListener(::rtl::OUString(), this);
196 // -----------------------------------------------------------------------------
197 void OPropertyMediator::startListening()
199 if ( m_xSource
.is() )
200 m_xSource
->addPropertyChangeListener(::rtl::OUString(), this);
202 m_xDest
->addPropertyChangeListener(::rtl::OUString(), this);
204 // -----------------------------------------------------------------------------
205 //........................................................................
206 } // namespace dbaccess
207 //........................................................................