LibreOffice Module reportdesign (master) 1
ReportControlModel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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>
24namespace reportdesign
25{
26using namespace com::sun::star;
27using namespace comphelper;
28
29// XContainer
31 const uno::Reference<container::XContainerListener>& xListener)
32{
34}
35
37 const uno::Reference<container::XContainerListener>& xListener)
38{
40}
41
43{
44 ::osl::MutexGuard aGuard(m_rMutex);
45 return !m_aFormatConditions.empty();
46}
47
48// XIndexContainer
49void OReportControlModel::insertByIndex(::sal_Int32 Index, const uno::Any& Element)
50{
51 uno::Reference<report::XFormatCondition> xElement(Element, uno::UNO_QUERY);
52 if (!xElement.is())
53 throw lang::IllegalArgumentException();
54
55 uno::Reference<container::XContainer> xBroadcaster;
56 {
57 ::osl::MutexGuard aGuard(m_rMutex);
58 xBroadcaster = m_pOwner;
59 if (Index > static_cast<sal_Int32>(m_aFormatConditions.size()))
60 throw lang::IndexOutOfBoundsException();
61
62 m_aFormatConditions.insert(m_aFormatConditions.begin() + Index, xElement);
63 }
64
65 // notify our container listeners
66 container::ContainerEvent aEvent(xBroadcaster, uno::Any(Index), Element, uno::Any());
67 aContainerListeners.notifyEach(&container::XContainerListener::elementInserted, aEvent);
68}
69
71{
72 uno::Any Element;
73 uno::Reference<container::XContainer> xBroadcaster;
74 {
75 ::osl::MutexGuard aGuard(m_rMutex);
76 xBroadcaster = m_pOwner;
78 Element <<= m_aFormatConditions[Index];
80 }
81 container::ContainerEvent aEvent(xBroadcaster, uno::Any(Index), Element, uno::Any());
82 aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved, aEvent);
83}
84
85// XIndexReplace
86void OReportControlModel::replaceByIndex(::sal_Int32 Index, const uno::Any& Element)
87{
88 uno::Reference<report::XFormatCondition> xElement(Element, uno::UNO_QUERY);
89 if (!xElement.is())
90 throw lang::IllegalArgumentException();
91 uno::Reference<container::XContainer> xBroadcaster;
92 {
93 ::osl::MutexGuard aGuard(m_rMutex);
94 xBroadcaster = m_pOwner;
96 m_aFormatConditions[Index] = xElement;
97 }
98 container::ContainerEvent aEvent(xBroadcaster, uno::Any(Index), Element, uno::Any());
99 aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced, aEvent);
100}
101
102// XIndexAccess
104{
105 ::osl::MutexGuard aGuard(m_rMutex);
106 return m_aFormatConditions.size();
107}
108
110{
111 uno::Any aElement;
112 {
113 ::osl::MutexGuard aGuard(m_rMutex);
115 aElement <<= m_aFormatConditions[Index];
116 }
117 return aElement;
118}
119
120void OReportControlModel::checkIndex(sal_Int32 _nIndex)
121{
122 if (_nIndex < 0 || m_aFormatConditions.size() <= o3tl::make_unsigned(_nIndex))
123 throw lang::IndexOutOfBoundsException();
124}
125
127{
130}
131
132} // reportdesign
133
134/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
AnyEventRef aEvent
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
void insertByIndex(::sal_Int32 Index, const css::uno::Any &Element)
void removeByIndex(::sal_Int32 Index)
css::uno::Any getByIndex(::sal_Int32 Index)
::comphelper::OInterfaceContainerHelper3< css::container::XContainerListener > aContainerListeners
static bool isInterfaceForbidden(const css::uno::Type &_rType)
void removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener)
void addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener)
::std::vector< css::uno::Reference< css::report::XFormatCondition > > m_aFormatConditions
void replaceByIndex(::sal_Int32 Index, const css::uno::Any &Element)
css::container::XContainer * m_pOwner
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)