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 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 #include <o3tl/safeint.hxx>
24 namespace reportdesign
26 using namespace com::sun::star
;
27 using namespace comphelper
;
30 void OReportControlModel::addContainerListener(
31 const uno::Reference
<container::XContainerListener
>& xListener
)
33 aContainerListeners
.addInterface(xListener
);
36 void OReportControlModel::removeContainerListener(
37 const uno::Reference
<container::XContainerListener
>& xListener
)
39 aContainerListeners
.removeInterface(xListener
);
42 bool OReportControlModel::hasElements()
44 ::osl::MutexGuard
aGuard(m_rMutex
);
45 return !m_aFormatConditions
.empty();
49 void OReportControlModel::insertByIndex(::sal_Int32 Index
, const uno::Any
& Element
)
51 uno::Reference
<report::XFormatCondition
> xElement(Element
, uno::UNO_QUERY
);
53 throw lang::IllegalArgumentException();
55 uno::Reference
<container::XContainer
> xBroadcaster
;
57 ::osl::MutexGuard
aGuard(m_rMutex
);
58 xBroadcaster
= m_pOwner
;
59 if (Index
> static_cast<sal_Int32
>(m_aFormatConditions
.size()))
60 throw lang::IndexOutOfBoundsException();
62 m_aFormatConditions
.insert(m_aFormatConditions
.begin() + Index
, xElement
);
65 // notify our container listeners
66 container::ContainerEvent
aEvent(xBroadcaster
, uno::Any(Index
), Element
, uno::Any());
67 aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
, aEvent
);
70 void OReportControlModel::removeByIndex(::sal_Int32 Index
)
73 uno::Reference
<container::XContainer
> xBroadcaster
;
75 ::osl::MutexGuard
aGuard(m_rMutex
);
76 xBroadcaster
= m_pOwner
;
78 Element
<<= m_aFormatConditions
[Index
];
79 m_aFormatConditions
.erase(m_aFormatConditions
.begin() + Index
);
81 container::ContainerEvent
aEvent(xBroadcaster
, uno::Any(Index
), Element
, uno::Any());
82 aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
, aEvent
);
86 void OReportControlModel::replaceByIndex(::sal_Int32 Index
, const uno::Any
& Element
)
88 uno::Reference
<report::XFormatCondition
> xElement(Element
, uno::UNO_QUERY
);
90 throw lang::IllegalArgumentException();
91 uno::Reference
<container::XContainer
> xBroadcaster
;
93 ::osl::MutexGuard
aGuard(m_rMutex
);
94 xBroadcaster
= m_pOwner
;
96 m_aFormatConditions
[Index
] = std::move(xElement
);
98 container::ContainerEvent
aEvent(xBroadcaster
, uno::Any(Index
), Element
, uno::Any());
99 aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
, aEvent
);
103 ::sal_Int32
OReportControlModel::getCount()
105 ::osl::MutexGuard
aGuard(m_rMutex
);
106 return m_aFormatConditions
.size();
109 uno::Any
OReportControlModel::getByIndex(::sal_Int32 Index
)
113 ::osl::MutexGuard
aGuard(m_rMutex
);
115 aElement
<<= m_aFormatConditions
[Index
];
120 void OReportControlModel::checkIndex(sal_Int32 _nIndex
)
122 if (_nIndex
< 0 || m_aFormatConditions
.size() <= o3tl::make_unsigned(_nIndex
))
123 throw lang::IndexOutOfBoundsException();
126 bool OReportControlModel::isInterfaceForbidden(const uno::Type
& _rType
)
128 return (_rType
== cppu::UnoType
<beans::XPropertyState
>::get()
129 || _rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get());
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */