1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
28 void OReportControlModel::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
)
30 aContainerListeners
.addInterface(xListener
);
33 void OReportControlModel::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
)
35 aContainerListeners
.removeInterface(xListener
);
38 bool OReportControlModel::hasElements( )
40 ::osl::MutexGuard
aGuard(m_rMutex
);
41 return !m_aFormatConditions
.empty();
45 void OReportControlModel::insertByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
47 uno::Reference
<report::XFormatCondition
> xElement(Element
,uno::UNO_QUERY
);
49 throw lang::IllegalArgumentException();
51 uno::Reference
< container::XContainer
> xBroadcaster
;
53 ::osl::MutexGuard
aGuard(m_rMutex
);
54 xBroadcaster
= m_pOwner
;
55 if ( Index
> static_cast<sal_Int32
>(m_aFormatConditions
.size()) )
56 throw lang::IndexOutOfBoundsException();
58 m_aFormatConditions
.insert(m_aFormatConditions
.begin() + Index
,xElement
);
61 // notify our container listeners
62 container::ContainerEvent
aEvent(xBroadcaster
, uno::makeAny(Index
), Element
, uno::Any());
63 aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
,aEvent
);
66 void OReportControlModel::removeByIndex( ::sal_Int32 Index
)
69 uno::Reference
< container::XContainer
> xBroadcaster
;
71 ::osl::MutexGuard
aGuard(m_rMutex
);
72 xBroadcaster
= m_pOwner
;
74 Element
<<= m_aFormatConditions
[Index
];
75 m_aFormatConditions
.erase(m_aFormatConditions
.begin() + Index
);
77 container::ContainerEvent
aEvent(xBroadcaster
, uno::makeAny(Index
), Element
, uno::Any());
78 aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
,aEvent
);
82 void OReportControlModel::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
84 uno::Reference
<report::XFormatCondition
> xElement(Element
,uno::UNO_QUERY
);
86 throw lang::IllegalArgumentException();
87 uno::Reference
< container::XContainer
> xBroadcaster
;
89 ::osl::MutexGuard
aGuard(m_rMutex
);
90 xBroadcaster
= m_pOwner
;
92 m_aFormatConditions
[Index
] = xElement
;
94 container::ContainerEvent
aEvent(xBroadcaster
, uno::makeAny(Index
), Element
, uno::Any());
95 aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
99 ::sal_Int32
OReportControlModel::getCount( )
101 ::osl::MutexGuard
aGuard(m_rMutex
);
102 return m_aFormatConditions
.size();
105 uno::Any
OReportControlModel::getByIndex( ::sal_Int32 Index
)
109 ::osl::MutexGuard
aGuard(m_rMutex
);
111 aElement
<<= m_aFormatConditions
[Index
];
116 void OReportControlModel::checkIndex(sal_Int32 _nIndex
)
118 if ( _nIndex
< 0 || static_cast<sal_Int32
>(m_aFormatConditions
.size()) <= _nIndex
)
119 throw lang::IndexOutOfBoundsException();
122 bool OReportControlModel::isInterfaceForbidden(const uno::Type
& _rType
)
124 return (_rType
== cppu::UnoType
<beans::XPropertyState
>::get()|| _rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get());
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */