Line data Source code
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 : namespace reportdesign
23 : {
24 : using namespace com::sun::star;
25 : using namespace comphelper;
26 :
27 0 : bool operator==( const ::com::sun::star::awt::FontDescriptor& _lhs, const ::com::sun::star::awt::FontDescriptor& _rhs )
28 : {
29 0 : return ( _lhs.Name == _rhs.Name )
30 0 : && ( _lhs.Height == _rhs.Height )
31 0 : && ( _lhs.Width == _rhs.Width )
32 0 : && ( _lhs.StyleName == _rhs.StyleName )
33 0 : && ( _lhs.Family == _rhs.Family )
34 0 : && ( _lhs.CharSet == _rhs.CharSet )
35 0 : && ( _lhs.Pitch == _rhs.Pitch )
36 0 : && ( _lhs.CharacterWidth == _rhs.CharacterWidth )
37 0 : && ( _lhs.Weight == _rhs.Weight )
38 0 : && ( _lhs.Slant == _rhs.Slant )
39 0 : && ( _lhs.Underline == _rhs.Underline )
40 0 : && ( _lhs.Strikeout == _rhs.Strikeout )
41 0 : && ( _lhs.Orientation == _rhs.Orientation )
42 0 : && ( _lhs.Kerning == _rhs.Kerning )
43 0 : && ( _lhs.WordLineMode == _rhs.WordLineMode )
44 0 : && ( _lhs.Type == _rhs.Type );
45 : }
46 :
47 :
48 : // XContainer
49 0 : void OReportControlModel::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
50 : {
51 0 : aContainerListeners.addInterface(xListener);
52 0 : }
53 :
54 0 : void OReportControlModel::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
55 : {
56 0 : aContainerListeners.removeInterface(xListener);
57 0 : }
58 :
59 0 : bool OReportControlModel::hasElements( ) throw (uno::RuntimeException)
60 : {
61 0 : ::osl::MutexGuard aGuard(m_rMutex);
62 0 : return !m_aFormatConditions.empty();
63 : }
64 :
65 : // XIndexContainer
66 0 : void OReportControlModel::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
67 : {
68 0 : uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
69 0 : if ( !xElement.is() )
70 0 : throw lang::IllegalArgumentException();
71 :
72 0 : uno::Reference< container::XContainer > xBroadcaster;
73 : {
74 0 : ::osl::MutexGuard aGuard(m_rMutex);
75 0 : xBroadcaster = m_pOwner;
76 0 : if ( Index > static_cast<sal_Int32>(m_aFormatConditions.size()) )
77 0 : throw lang::IndexOutOfBoundsException();
78 :
79 0 : m_aFormatConditions.insert(m_aFormatConditions.begin() + Index,xElement);
80 : }
81 :
82 : // notify our container listeners
83 0 : container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
84 0 : aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
85 0 : }
86 :
87 0 : void OReportControlModel::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
88 : {
89 0 : uno::Any Element;
90 0 : uno::Reference< container::XContainer > xBroadcaster;
91 : {
92 0 : ::osl::MutexGuard aGuard(m_rMutex);
93 0 : xBroadcaster = m_pOwner;
94 0 : checkIndex(Index);
95 0 : Element <<= m_aFormatConditions[Index];
96 0 : m_aFormatConditions.erase(m_aFormatConditions.begin() + Index);
97 : }
98 0 : container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
99 0 : aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
100 0 : }
101 :
102 : // XIndexReplace
103 0 : void OReportControlModel::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
104 : {
105 0 : uno::Reference<report::XFormatCondition> xElement(Element,uno::UNO_QUERY);
106 0 : if ( !xElement.is() )
107 0 : throw lang::IllegalArgumentException();
108 0 : uno::Reference< container::XContainer > xBroadcaster;
109 : {
110 0 : ::osl::MutexGuard aGuard(m_rMutex);
111 0 : xBroadcaster = m_pOwner;
112 0 : checkIndex(Index);
113 0 : m_aFormatConditions[Index] = xElement;
114 : }
115 0 : container::ContainerEvent aEvent(xBroadcaster, uno::makeAny(Index), Element, uno::Any());
116 0 : aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
117 0 : }
118 :
119 : // XIndexAccess
120 0 : ::sal_Int32 OReportControlModel::getCount( ) throw (uno::RuntimeException)
121 : {
122 0 : ::osl::MutexGuard aGuard(m_rMutex);
123 0 : return m_aFormatConditions.size();
124 : }
125 :
126 0 : uno::Any OReportControlModel::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
127 : {
128 0 : uno::Any aElement;
129 : {
130 0 : ::osl::MutexGuard aGuard(m_rMutex);
131 0 : checkIndex(Index);
132 0 : aElement <<= m_aFormatConditions[Index];
133 : }
134 0 : return aElement;
135 : }
136 :
137 0 : void OReportControlModel::checkIndex(sal_Int32 _nIndex)
138 : {
139 0 : if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFormatConditions.size()) <= _nIndex )
140 0 : throw lang::IndexOutOfBoundsException();
141 0 : }
142 :
143 0 : bool OReportControlModel::isInterfaceForbidden(const uno::Type& _rType)
144 : {
145 0 : return (_rType == cppu::UnoType<beans::XPropertyState>::get()|| _rType == cppu::UnoType<beans::XMultiPropertySet>::get());
146 : }
147 :
148 : } // reportdesign
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|