sync master with lastest vba changes
[ooovba.git] / reportdesign / source / core / api / ReportControlModel.cxx
blob09cf3034bb21f83678c21c6389f6399f96f1fb88
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ReportControlModel.cxx,v $
10 * $Revision: 1.3 $
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 "ReportControlModel.hxx"
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/beans/XPropertyState.hpp>
33 namespace reportdesign
35 using namespace com::sun::star;
36 using namespace comphelper;
38 bool operator==( const ::com::sun::star::awt::FontDescriptor& _lhs, const ::com::sun::star::awt::FontDescriptor& _rhs )
40 return ( _lhs.Name == _rhs.Name )
41 && ( _lhs.Height == _rhs.Height )
42 && ( _lhs.Width == _rhs.Width )
43 && ( _lhs.StyleName == _rhs.StyleName )
44 && ( _lhs.Family == _rhs.Family )
45 && ( _lhs.CharSet == _rhs.CharSet )
46 && ( _lhs.Pitch == _rhs.Pitch )
47 && ( _lhs.CharacterWidth == _rhs.CharacterWidth )
48 && ( _lhs.Weight == _rhs.Weight )
49 && ( _lhs.Slant == _rhs.Slant )
50 && ( _lhs.Underline == _rhs.Underline )
51 && ( _lhs.Strikeout == _rhs.Strikeout )
52 && ( _lhs.Orientation == _rhs.Orientation )
53 && ( _lhs.Kerning == _rhs.Kerning )
54 && ( _lhs.WordLineMode == _rhs.WordLineMode )
55 && ( _lhs.Type == _rhs.Type );
58 // -----------------------------------------------------------------------------
59 // XContainer
60 void OReportControlModel::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
62 aContainerListeners.addInterface(xListener);
64 // -----------------------------------------------------------------------------
65 void OReportControlModel::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
67 aContainerListeners.removeInterface(xListener);
69 // -----------------------------------------------------------------------------
70 ::sal_Bool OReportControlModel::hasElements( ) throw (uno::RuntimeException)
72 ::osl::MutexGuard aGuard(m_rMutex);
73 return !m_aFormatConditions.empty();
75 // -----------------------------------------------------------------------------
76 // XIndexContainer
77 void OReportControlModel::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
79 uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
80 if ( !xElement.is() )
81 throw lang::IllegalArgumentException();
83 uno::Reference< container::XContainer > xBroadcaster;
85 ::osl::MutexGuard aGuard(m_rMutex);
86 xBroadcaster = m_pOwner;
87 if ( Index > static_cast<sal_Int32>(m_aFormatConditions.size()) )
88 throw lang::IndexOutOfBoundsException();
90 //m_aFormatConditions.resize(m_aFormatConditions.size() + 1);
91 m_aFormatConditions.insert(m_aFormatConditions.begin() + Index,xElement);
94 // notify our container listeners
95 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
96 aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
98 // -----------------------------------------------------------------------------
99 void OReportControlModel::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
101 uno::Any Element;
102 uno::Reference< container::XContainer > xBroadcaster;
104 ::osl::MutexGuard aGuard(m_rMutex);
105 xBroadcaster = m_pOwner;
106 checkIndex(Index);
107 Element <<= m_aFormatConditions[Index];
108 m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
110 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
111 aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
113 // -----------------------------------------------------------------------------
114 // XIndexReplace
115 void OReportControlModel::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
117 uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
118 if ( !xElement.is() )
119 throw lang::IllegalArgumentException();
120 uno::Reference< container::XContainer > xBroadcaster;
122 ::osl::MutexGuard aGuard(m_rMutex);
123 xBroadcaster = m_pOwner;
124 checkIndex(Index);
125 m_aFormatConditions[Index] = xElement;
127 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
128 aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
130 // -----------------------------------------------------------------------------
131 // XIndexAccess
132 ::sal_Int32 OReportControlModel::getCount( ) throw (uno::RuntimeException)
134 ::osl::MutexGuard aGuard(m_rMutex);
135 return m_aFormatConditions.size();
137 // -----------------------------------------------------------------------------
138 uno::Any OReportControlModel::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
140 uno::Any aElement;
142 ::osl::MutexGuard aGuard(m_rMutex);
143 checkIndex(Index);
144 aElement <<= m_aFormatConditions[Index];
146 return aElement;
148 // -----------------------------------------------------------------------------
149 void OReportControlModel::checkIndex(sal_Int32 _nIndex)
151 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex )
152 throw lang::IndexOutOfBoundsException();
154 // -----------------------------------------------------------------------------
155 void OReportControlModel::dispose()
157 m_aFormatConditions.clear();
158 lang::EventObject aDisposeEvent( m_pOwner );
159 aContainerListeners.disposeAndClear( aDisposeEvent );
160 m_aFormatConditions.clear();
162 // -----------------------------------------------------------------------------
163 bool OReportControlModel::isInterfaceForbidden(const uno::Type& _rType)
165 return (_rType == ::getCppuType((const uno::Reference< beans::XPropertyState>* )0) || _rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet>* )0));
167 // -----------------------------------------------------------------------------
168 } // reportdesign