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  */
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 namespace reportdesign
24 {
25 using namespace com::sun::star;
26 using namespace comphelper;
27 
28 // XContainer
30  const uno::Reference<container::XContainerListener>& xListener)
31 {
32  aContainerListeners.addInterface(xListener);
33 }
34 
36  const uno::Reference<container::XContainerListener>& xListener)
37 {
38  aContainerListeners.removeInterface(xListener);
39 }
40 
42 {
43  ::osl::MutexGuard aGuard(m_rMutex);
44  return !m_aFormatConditions.empty();
45 }
46 
47 // XIndexContainer
48 void OReportControlModel::insertByIndex(::sal_Int32 Index, const uno::Any& Element)
49 {
50  uno::Reference<report::XFormatCondition> xElement(Element, uno::UNO_QUERY);
51  if (!xElement.is())
52  throw lang::IllegalArgumentException();
53 
54  uno::Reference<container::XContainer> xBroadcaster;
55  {
56  ::osl::MutexGuard aGuard(m_rMutex);
57  xBroadcaster = m_pOwner;
58  if (Index > static_cast<sal_Int32>(m_aFormatConditions.size()))
59  throw lang::IndexOutOfBoundsException();
60 
61  m_aFormatConditions.insert(m_aFormatConditions.begin() + Index, xElement);
62  }
63 
64  // notify our container listeners
65  container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
66  aContainerListeners.notifyEach(&container::XContainerListener::elementInserted, aEvent);
67 }
68 
70 {
71  uno::Any Element;
72  uno::Reference<container::XContainer> xBroadcaster;
73  {
74  ::osl::MutexGuard aGuard(m_rMutex);
75  xBroadcaster = m_pOwner;
76  checkIndex(Index);
77  Element <<= m_aFormatConditions[Index];
78  m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
79  }
80  container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
81  aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved, aEvent);
82 }
83 
84 // XIndexReplace
85 void OReportControlModel::replaceByIndex(::sal_Int32 Index, const uno::Any& Element)
86 {
87  uno::Reference<report::XFormatCondition> xElement(Element, uno::UNO_QUERY);
88  if (!xElement.is())
89  throw lang::IllegalArgumentException();
90  uno::Reference<container::XContainer> xBroadcaster;
91  {
92  ::osl::MutexGuard aGuard(m_rMutex);
93  xBroadcaster = m_pOwner;
94  checkIndex(Index);
95  m_aFormatConditions[Index] = xElement;
96  }
97  container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
98  aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced, aEvent);
99 }
100 
101 // XIndexAccess
103 {
104  ::osl::MutexGuard aGuard(m_rMutex);
105  return m_aFormatConditions.size();
106 }
107 
109 {
110  uno::Any aElement;
111  {
112  ::osl::MutexGuard aGuard(m_rMutex);
113  checkIndex(Index);
114  aElement <<= m_aFormatConditions[Index];
115  }
116  return aElement;
117 }
118 
119 void OReportControlModel::checkIndex(sal_Int32 _nIndex)
120 {
121  if (_nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex)
122  throw lang::IndexOutOfBoundsException();
123 }
124 
126 {
129 }
130 
131 } // reportdesign
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener)
::osl::Mutex & m_rMutex
static bool isInterfaceForbidden(const css::uno::Type &_rType)
ContentProvider * m_pOwner
void addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener)
void insertByIndex(::sal_Int32 Index, const css::uno::Any &Element)
void replaceByIndex(::sal_Int32 Index, const css::uno::Any &Element)
void removeByIndex(::sal_Int32 Index)
struct _ADOIndex Index
AnyEventRef aEvent
css::uno::Any getByIndex(::sal_Int32 Index)