bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / core / api / ReportControlModel.cxx
blob9c90a808fa1a3c743f3d546352e8004d8b894463
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "ReportControlModel.hxx"
20 #include <com/sun/star/beans/XMultiPropertySet.hpp>
21 #include <com/sun/star/beans/XPropertyState.hpp>
22 namespace reportdesign
24 using namespace com::sun::star;
25 using namespace comphelper;
27 bool operator==( const ::com::sun::star::awt::FontDescriptor& _lhs, const ::com::sun::star::awt::FontDescriptor& _rhs )
29 return ( _lhs.Name == _rhs.Name )
30 && ( _lhs.Height == _rhs.Height )
31 && ( _lhs.Width == _rhs.Width )
32 && ( _lhs.StyleName == _rhs.StyleName )
33 && ( _lhs.Family == _rhs.Family )
34 && ( _lhs.CharSet == _rhs.CharSet )
35 && ( _lhs.Pitch == _rhs.Pitch )
36 && ( _lhs.CharacterWidth == _rhs.CharacterWidth )
37 && ( _lhs.Weight == _rhs.Weight )
38 && ( _lhs.Slant == _rhs.Slant )
39 && ( _lhs.Underline == _rhs.Underline )
40 && ( _lhs.Strikeout == _rhs.Strikeout )
41 && ( _lhs.Orientation == _rhs.Orientation )
42 && ( _lhs.Kerning == _rhs.Kerning )
43 && ( _lhs.WordLineMode == _rhs.WordLineMode )
44 && ( _lhs.Type == _rhs.Type );
48 // XContainer
49 void OReportControlModel::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
51 aContainerListeners.addInterface(xListener);
54 void OReportControlModel::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
56 aContainerListeners.removeInterface(xListener);
59 bool OReportControlModel::hasElements( ) throw (uno::RuntimeException)
61 ::osl::MutexGuard aGuard(m_rMutex);
62 return !m_aFormatConditions.empty();
65 // XIndexContainer
66 void OReportControlModel::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
68 uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
69 if ( !xElement.is() )
70 throw lang::IllegalArgumentException();
72 uno::Reference< container::XContainer > xBroadcaster;
74 ::osl::MutexGuard aGuard(m_rMutex);
75 xBroadcaster = m_pOwner;
76 if ( Index > static_cast<sal_Int32>(m_aFormatConditions.size()) )
77 throw lang::IndexOutOfBoundsException();
79 m_aFormatConditions.insert(m_aFormatConditions.begin() + Index,xElement);
82 // notify our container listeners
83 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
84 aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
87 void OReportControlModel::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
89 uno::Any Element;
90 uno::Reference< container::XContainer > xBroadcaster;
92 ::osl::MutexGuard aGuard(m_rMutex);
93 xBroadcaster = m_pOwner;
94 checkIndex(Index);
95 Element <<= m_aFormatConditions[Index];
96 m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
98 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
99 aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
102 // XIndexReplace
103 void OReportControlModel::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
105 uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
106 if ( !xElement.is() )
107 throw lang::IllegalArgumentException();
108 uno::Reference< container::XContainer > xBroadcaster;
110 ::osl::MutexGuard aGuard(m_rMutex);
111 xBroadcaster = m_pOwner;
112 checkIndex(Index);
113 m_aFormatConditions[Index] = xElement;
115 container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
116 aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
119 // XIndexAccess
120 ::sal_Int32 OReportControlModel::getCount( ) throw (uno::RuntimeException)
122 ::osl::MutexGuard aGuard(m_rMutex);
123 return m_aFormatConditions.size();
126 uno::Any OReportControlModel::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
128 uno::Any aElement;
130 ::osl::MutexGuard aGuard(m_rMutex);
131 checkIndex(Index);
132 aElement <<= m_aFormatConditions[Index];
134 return aElement;
137 void OReportControlModel::checkIndex(sal_Int32 _nIndex)
139 if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex )
140 throw lang::IndexOutOfBoundsException();
143 bool OReportControlModel::isInterfaceForbidden(const uno::Type& _rType)
145 return (_rType == cppu::UnoType<beans::XPropertyState>::get()|| _rType == cppu::UnoType<beans::XMultiPropertySet>::get());
148 } // reportdesign
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */