1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "LayoutContainer.hxx"
27 #include "macros.hxx"
28 #include "ContainerHelper.hxx"
29
30 #include <algorithm>
31
32 using namespace ::com::sun::star;
33
34 namespace
35 {
36
37 static const ::rtl::OUString lcl_aServiceName(
38 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.layout.LayoutContainer" ));
39 } // anonymous namespace
40
41 namespace chart
42 {
43
LayoutContainer()44 LayoutContainer::LayoutContainer()
45 {}
46
~LayoutContainer()47 LayoutContainer::~LayoutContainer()
48 {}
49
50 // ____ XLayoutContainer ____
addConstrainedElementByIdentifier(const::rtl::OUString & aIdentifier,const layout::Constraint & Constraint)51 void SAL_CALL LayoutContainer::addConstrainedElementByIdentifier(
52 const ::rtl::OUString& aIdentifier,
53 const layout::Constraint& Constraint )
54 throw (layout::IllegalConstraintException,
55 lang::IllegalArgumentException,
56 uno::RuntimeException)
57 {
58 addElementByIdentifier( aIdentifier );
59 m_aConstraints[ aIdentifier ] = Constraint;
60 }
61
addElementByIdentifier(const::rtl::OUString & aIdentifier)62 void SAL_CALL LayoutContainer::addElementByIdentifier( const ::rtl::OUString& aIdentifier )
63 throw (lang::IllegalArgumentException,
64 uno::RuntimeException)
65 {
66 if( ::std::find( m_aLayoutElements.begin(),
67 m_aLayoutElements.end(),
68 aIdentifier ) != m_aLayoutElements.end())
69 throw lang::IllegalArgumentException();
70
71 m_aLayoutElements.push_back( aIdentifier );
72 }
73
removeElementByIdentifier(const::rtl::OUString & aIdentifier)74 void SAL_CALL LayoutContainer::removeElementByIdentifier( const ::rtl::OUString& aIdentifier )
75 throw (container::NoSuchElementException,
76 uno::RuntimeException)
77 {
78 tLayoutElements::iterator aIt(
79 ::std::find( m_aLayoutElements.begin(),
80 m_aLayoutElements.end(),
81 aIdentifier ));
82
83 if( aIt == m_aLayoutElements.end())
84 throw container::NoSuchElementException();
85
86 m_aLayoutElements.erase( aIt );
87 m_aConstraints.erase( aIdentifier );
88 }
89
setConstraintByIdentifier(const::rtl::OUString & aIdentifier,const layout::Constraint & Constraint)90 void SAL_CALL LayoutContainer::setConstraintByIdentifier(
91 const ::rtl::OUString& aIdentifier,
92 const layout::Constraint& Constraint )
93 throw (container::NoSuchElementException,
94 uno::RuntimeException)
95 {
96 if( ::std::find( m_aLayoutElements.begin(),
97 m_aLayoutElements.end(),
98 aIdentifier ) == m_aLayoutElements.end())
99 throw container::NoSuchElementException();
100
101 m_aConstraints[ aIdentifier ] = Constraint;
102 }
103
getConstraintByIdentifier(const::rtl::OUString & aIdentifier)104 layout::Constraint SAL_CALL LayoutContainer::getConstraintByIdentifier( const ::rtl::OUString& aIdentifier )
105 throw (container::NoSuchElementException,
106 uno::RuntimeException)
107 {
108 tConstraintsMap::const_iterator aIt( m_aConstraints.find( aIdentifier ));
109 if( aIt == m_aConstraints.end())
110 throw container::NoSuchElementException();
111
112 return (*aIt).second;
113 }
114
getElementIdentifiers()115 uno::Sequence< ::rtl::OUString > SAL_CALL LayoutContainer::getElementIdentifiers()
116 throw (uno::RuntimeException)
117 {
118 return ContainerHelper::ContainerToSequence( m_aLayoutElements );
119 }
120
getSupportedServiceNames_Static()121 uno::Sequence< ::rtl::OUString > LayoutContainer::getSupportedServiceNames_Static()
122 {
123 uno::Sequence< ::rtl::OUString > aServices( 1 );
124
125 aServices[ 0 ] = C2U( "com.sun.star.layout.LayoutContainer" );
126 return aServices;
127 }
128
129 // --------------------------------------------------------------------------------
130
131 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
132 APPHELPER_XSERVICEINFO_IMPL( LayoutContainer, lcl_aServiceName );
133
134 } // namespace chart
135