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_xmloff.hxx"
26 #include "impastpl.hxx"
27 #include <xmloff/xmlprmap.hxx>
28
29 using namespace std;
30 using namespace rtl;
31
32 //#############################################################################
33 //
34 // Class SvXMLAutoStylePoolParent_Impl
35 //
36
37 ///////////////////////////////////////////////////////////////////////////////
38 //
39 // dtor class SvXMLAutoStylePoolParent_Impl
40 //
41
~SvXMLAutoStylePoolParentP_Impl()42 SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl()
43 {
44 while( maPropertiesList.Count() )
45 delete maPropertiesList.Remove( maPropertiesList.Count() -1 );
46 }
47
48 ///////////////////////////////////////////////////////////////////////////////
49 //
50 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
51 // if not added, yet.
52 //
53
Add(XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties,OUString & rName,bool bDontSeek)54 sal_Bool SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek )
55 {
56 sal_Bool bAdded = sal_False;
57 SvXMLAutoStylePoolPropertiesP_Impl *pProperties = 0;
58 sal_uInt32 i = 0;
59 sal_Int32 nProperties = rProperties.size();
60 sal_uInt32 nCount = maPropertiesList.Count();
61
62 for( i = 0; i < nCount; i++ )
63 {
64 SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
65 if( nProperties > (sal_Int32)pIS->GetProperties().size() )
66 {
67 continue;
68 }
69 else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
70 {
71 break;
72 }
73 else if( !bDontSeek && pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
74 {
75 pProperties = pIS;
76 break;
77 }
78 }
79
80 if( !pProperties )
81 {
82 pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
83 maPropertiesList.Insert( pProperties, i );
84 bAdded = sal_True;
85 }
86
87 rName = pProperties->GetName();
88
89 return bAdded;
90 }
91
92 ///////////////////////////////////////////////////////////////////////////////
93 //
94 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
95 // If the name exists already, nothing is done. If a style with a different name and
96 // the same properties exists, a new one is added (like with bDontSeek).
97 //
98
AddNamed(XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties,const OUString & rName)99 sal_Bool SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName )
100 {
101 sal_Bool bAdded = sal_False;
102 sal_uInt32 i = 0;
103 sal_Int32 nProperties = rProperties.size();
104 sal_uInt32 nCount = maPropertiesList.Count();
105
106 for( i = 0; i < nCount; i++ )
107 {
108 SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
109 if( nProperties > (sal_Int32)pIS->GetProperties().size() )
110 {
111 continue;
112 }
113 else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
114 {
115 break;
116 }
117 }
118
119 if( !pFamilyData->mpNameList->Seek_Entry( &rName, 0 ) )
120 {
121 SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
122 new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
123 // ignore the generated name
124 pProperties->SetName( rName );
125 maPropertiesList.Insert( pProperties, i );
126 bAdded = sal_True;
127 }
128
129 return bAdded;
130 }
131
132 ///////////////////////////////////////////////////////////////////////////////
133 //
134 // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
135 //
136
Find(const XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties) const137 OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties ) const
138 {
139 OUString sName;
140 vector< XMLPropertyState>::size_type nItems = rProperties.size();
141 sal_uInt32 nCount = maPropertiesList.Count();
142 for( sal_uInt32 i=0; i < nCount; i++ )
143 {
144 SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
145 if( nItems > pIS->GetProperties().size() )
146 {
147 continue;
148 }
149 else if( nItems < pIS->GetProperties().size() )
150 {
151 break;
152 }
153 else if( pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
154 {
155 sName = pIS->GetName();
156 break;
157 }
158 }
159
160 return sName;
161 }
162
163 ///////////////////////////////////////////////////////////////////////////////
164 //
165 // Sort-function for sorted list of SvXMLAutoStylePoolParent_Impl-elements
166 //
167
SvXMLAutoStylePoolParentPCmp_Impl(const SvXMLAutoStylePoolParentP_Impl & r1,const SvXMLAutoStylePoolParentP_Impl & r2)168 int SvXMLAutoStylePoolParentPCmp_Impl( const SvXMLAutoStylePoolParentP_Impl& r1,
169 const SvXMLAutoStylePoolParentP_Impl& r2)
170 {
171 return (int)r1.GetParent().compareTo( r2.GetParent() );
172 }
173
174 ///////////////////////////////////////////////////////////////////////////////
175 //
176 // Implementation of sorted list of SvXMLAutoStylePoolParent_Impl-elements
177 //
178
179 IMPL_CONTAINER_SORT( SvXMLAutoStylePoolParentsP_Impl,
180 SvXMLAutoStylePoolParentP_Impl,
181 SvXMLAutoStylePoolParentPCmp_Impl )
182