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 "ReportControlModel.hxx"
24 #include <com/sun/star/beans/XMultiPropertySet.hpp>
25 #include <com/sun/star/beans/XPropertyState.hpp>
26 namespace reportdesign
27 {
28 using namespace com::sun::star;
29 using namespace comphelper;
30 
operator ==(const::com::sun::star::awt::FontDescriptor & _lhs,const::com::sun::star::awt::FontDescriptor & _rhs)31 bool operator==( const ::com::sun::star::awt::FontDescriptor& _lhs, const ::com::sun::star::awt::FontDescriptor& _rhs )
32 {
33     return  ( _lhs.Name           == _rhs.Name )
34         &&  ( _lhs.Height         == _rhs.Height )
35         &&  ( _lhs.Width          == _rhs.Width )
36         &&  ( _lhs.StyleName      == _rhs.StyleName )
37         &&  ( _lhs.Family         == _rhs.Family )
38         &&  ( _lhs.CharSet        == _rhs.CharSet )
39         &&  ( _lhs.Pitch          == _rhs.Pitch )
40         &&  ( _lhs.CharacterWidth == _rhs.CharacterWidth )
41         &&  ( _lhs.Weight         == _rhs.Weight )
42         &&  ( _lhs.Slant          == _rhs.Slant )
43         &&  ( _lhs.Underline      == _rhs.Underline )
44         &&  ( _lhs.Strikeout      == _rhs.Strikeout )
45         &&  ( _lhs.Orientation    == _rhs.Orientation )
46         &&  ( _lhs.Kerning        == _rhs.Kerning )
47         &&  ( _lhs.WordLineMode   == _rhs.WordLineMode )
48         &&  ( _lhs.Type           == _rhs.Type );
49 }
50 
51 // -----------------------------------------------------------------------------
52 // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)53 void OReportControlModel::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
54 {
55 	aContainerListeners.addInterface(xListener);
56 }
57 // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)58 void OReportControlModel::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
59 {
60 	aContainerListeners.removeInterface(xListener);
61 }
62 // -----------------------------------------------------------------------------
hasElements()63 ::sal_Bool OReportControlModel::hasElements(  ) throw (uno::RuntimeException)
64 {
65 	::osl::MutexGuard aGuard(m_rMutex);
66 	return !m_aFormatConditions.empty();
67 }
68 // -----------------------------------------------------------------------------
69 // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & Element)70 void OReportControlModel::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
71 {
72 	uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
73 	if ( !xElement.is() )
74 		throw lang::IllegalArgumentException();
75 
76     uno::Reference< container::XContainer > xBroadcaster;
77 	{
78 		::osl::MutexGuard aGuard(m_rMutex);
79         xBroadcaster = m_pOwner;
80 		if ( Index > static_cast<sal_Int32>(m_aFormatConditions.size()) )
81 			throw lang::IndexOutOfBoundsException();
82 
83 		//m_aFormatConditions.resize(m_aFormatConditions.size() + 1);
84 		m_aFormatConditions.insert(m_aFormatConditions.begin() + Index,xElement);
85 	}
86 
87 	// notify our container listeners
88 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
89 	aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
90 }
91 // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)92 void OReportControlModel::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
93 {
94 	uno::Any Element;
95     uno::Reference< container::XContainer > xBroadcaster;
96 	{
97 		::osl::MutexGuard aGuard(m_rMutex);
98         xBroadcaster = m_pOwner;
99 		checkIndex(Index);
100 		Element <<= m_aFormatConditions[Index];
101 		m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
102 	}
103 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
104 	aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
105 }
106 // -----------------------------------------------------------------------------
107 // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)108 void OReportControlModel::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
109 {
110 	uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
111 	if ( !xElement.is() )
112 		throw lang::IllegalArgumentException();
113 	uno::Reference< container::XContainer > xBroadcaster;
114 	{
115 		::osl::MutexGuard aGuard(m_rMutex);
116         xBroadcaster = m_pOwner;
117 		checkIndex(Index);
118 		m_aFormatConditions[Index] = xElement;
119 	}
120 	container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
121 	aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
122 }
123 // -----------------------------------------------------------------------------
124 // XIndexAccess
getCount()125 ::sal_Int32 OReportControlModel::getCount(  ) throw (uno::RuntimeException)
126 {
127 	::osl::MutexGuard aGuard(m_rMutex);
128 	return m_aFormatConditions.size();
129 }
130 // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)131 uno::Any OReportControlModel::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
132 {
133 	uno::Any aElement;
134 	{
135 		::osl::MutexGuard aGuard(m_rMutex);
136 		checkIndex(Index);
137 		aElement <<= m_aFormatConditions[Index];
138 	}
139 	return aElement;
140 }
141 // -----------------------------------------------------------------------------
checkIndex(sal_Int32 _nIndex)142 void OReportControlModel::checkIndex(sal_Int32 _nIndex)
143 {
144 	if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex )
145 		throw lang::IndexOutOfBoundsException();
146 }
147 // -----------------------------------------------------------------------------
isInterfaceForbidden(const uno::Type & _rType)148 bool OReportControlModel::isInterfaceForbidden(const uno::Type& _rType)
149 {
150     return (_rType == ::getCppuType((const uno::Reference< beans::XPropertyState>* )0) || _rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet>* )0));
151 }
152 // -----------------------------------------------------------------------------
153 } // reportdesign
154 
155