1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #include "precompiled_reportdesign.hxx"
24 #include "ReportControlModel.hxx"
25 #include <com/sun/star/beans/XMultiPropertySet.hpp>
26 #include <com/sun/star/beans/XPropertyState.hpp>
27 namespace reportdesign
28 {
29 using namespace com::sun::star;
30 using namespace comphelper;
31 
operator ==(const::com::sun::star::awt::FontDescriptor & _lhs,const::com::sun::star::awt::FontDescriptor & _rhs)32 bool operator==( const ::com::sun::star::awt::FontDescriptor& _lhs, const ::com::sun::star::awt::FontDescriptor& _rhs )
33 {
34     return  ( _lhs.Name           == _rhs.Name )
35         &&  ( _lhs.Height         == _rhs.Height )
36         &&  ( _lhs.Width          == _rhs.Width )
37         &&  ( _lhs.StyleName      == _rhs.StyleName )
38         &&  ( _lhs.Family         == _rhs.Family )
39         &&  ( _lhs.CharSet        == _rhs.CharSet )
40         &&  ( _lhs.Pitch          == _rhs.Pitch )
41         &&  ( _lhs.CharacterWidth == _rhs.CharacterWidth )
42         &&  ( _lhs.Weight         == _rhs.Weight )
43         &&  ( _lhs.Slant          == _rhs.Slant )
44         &&  ( _lhs.Underline      == _rhs.Underline )
45         &&  ( _lhs.Strikeout      == _rhs.Strikeout )
46         &&  ( _lhs.Orientation    == _rhs.Orientation )
47         &&  ( _lhs.Kerning        == _rhs.Kerning )
48         &&  ( _lhs.WordLineMode   == _rhs.WordLineMode )
49         &&  ( _lhs.Type           == _rhs.Type );
50 }
51 
52 // -----------------------------------------------------------------------------
53 // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)54 void OReportControlModel::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
55 {
56 	aContainerListeners.addInterface(xListener);
57 }
58 // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)59 void OReportControlModel::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
60 {
61 	aContainerListeners.removeInterface(xListener);
62 }
63 // -----------------------------------------------------------------------------
hasElements()64 ::sal_Bool OReportControlModel::hasElements(  ) throw (uno::RuntimeException)
65 {
66 	::osl::MutexGuard aGuard(m_rMutex);
67 	return !m_aFormatConditions.empty();
68 }
69 // -----------------------------------------------------------------------------
70 // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & Element)71 void OReportControlModel::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
72 {
73 	uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
74 	if ( !xElement.is() )
75 		throw lang::IllegalArgumentException();
76 
77     uno::Reference< container::XContainer > xBroadcaster;
78 	{
79 		::osl::MutexGuard aGuard(m_rMutex);
80         xBroadcaster = m_pOwner;
81 		if ( Index > static_cast<sal_Int32>(m_aFormatConditions.size()) )
82 			throw lang::IndexOutOfBoundsException();
83 
84 		//m_aFormatConditions.resize(m_aFormatConditions.size() + 1);
85 		m_aFormatConditions.insert(m_aFormatConditions.begin() + Index,xElement);
86 	}
87 
88 	// notify our container listeners
89 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
90 	aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
91 }
92 // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)93 void OReportControlModel::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
94 {
95 	uno::Any Element;
96     uno::Reference< container::XContainer > xBroadcaster;
97 	{
98 		::osl::MutexGuard aGuard(m_rMutex);
99         xBroadcaster = m_pOwner;
100 		checkIndex(Index);
101 		Element <<= m_aFormatConditions[Index];
102 		m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
103 	}
104 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
105 	aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
106 }
107 // -----------------------------------------------------------------------------
108 // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)109 void OReportControlModel::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
110 {
111 	uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
112 	if ( !xElement.is() )
113 		throw lang::IllegalArgumentException();
114 	uno::Reference< container::XContainer > xBroadcaster;
115 	{
116 		::osl::MutexGuard aGuard(m_rMutex);
117         xBroadcaster = m_pOwner;
118 		checkIndex(Index);
119 		m_aFormatConditions[Index] = xElement;
120 	}
121 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
122 	aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
123 }
124 // -----------------------------------------------------------------------------
125 // XIndexAccess
getCount()126 ::sal_Int32 OReportControlModel::getCount(  ) throw (uno::RuntimeException)
127 {
128 	::osl::MutexGuard aGuard(m_rMutex);
129 	return m_aFormatConditions.size();
130 }
131 // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)132 uno::Any OReportControlModel::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
133 {
134 	uno::Any aElement;
135 	{
136 		::osl::MutexGuard aGuard(m_rMutex);
137 		checkIndex(Index);
138 		aElement <<= m_aFormatConditions[Index];
139 	}
140 	return aElement;
141 }
142 // -----------------------------------------------------------------------------
checkIndex(sal_Int32 _nIndex)143 void OReportControlModel::checkIndex(sal_Int32 _nIndex)
144 {
145 	if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex )
146 		throw lang::IndexOutOfBoundsException();
147 }
148 // -----------------------------------------------------------------------------
isInterfaceForbidden(const uno::Type & _rType)149 bool OReportControlModel::isInterfaceForbidden(const uno::Type& _rType)
150 {
151     return (_rType == ::getCppuType((const uno::Reference< beans::XPropertyState>* )0) || _rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet>* )0));
152 }
153 // -----------------------------------------------------------------------------
154 } // reportdesign
155 
156