1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10*63bba73cSAndrew Rist *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19*63bba73cSAndrew Rist *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include "impastpl.hxx"
27cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir using namespace std;
30cdf0e10cSrcweir using namespace rtl;
31cdf0e10cSrcweir
32cdf0e10cSrcweir //#############################################################################
33cdf0e10cSrcweir //
34cdf0e10cSrcweir // Class SvXMLAutoStylePoolParent_Impl
35cdf0e10cSrcweir //
36cdf0e10cSrcweir
37cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
38cdf0e10cSrcweir //
39cdf0e10cSrcweir // dtor class SvXMLAutoStylePoolParent_Impl
40cdf0e10cSrcweir //
41cdf0e10cSrcweir
~SvXMLAutoStylePoolParentP_Impl()42cdf0e10cSrcweir SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir while( maPropertiesList.Count() )
45cdf0e10cSrcweir delete maPropertiesList.Remove( maPropertiesList.Count() -1 );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
49cdf0e10cSrcweir //
50cdf0e10cSrcweir // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
51cdf0e10cSrcweir // if not added, yet.
52cdf0e10cSrcweir //
53cdf0e10cSrcweir
Add(XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties,OUString & rName,bool bDontSeek)54cdf0e10cSrcweir sal_Bool SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek )
55cdf0e10cSrcweir {
56cdf0e10cSrcweir sal_Bool bAdded = sal_False;
57cdf0e10cSrcweir SvXMLAutoStylePoolPropertiesP_Impl *pProperties = 0;
58cdf0e10cSrcweir sal_uInt32 i = 0;
59cdf0e10cSrcweir sal_Int32 nProperties = rProperties.size();
60cdf0e10cSrcweir sal_uInt32 nCount = maPropertiesList.Count();
61cdf0e10cSrcweir
62cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
65cdf0e10cSrcweir if( nProperties > (sal_Int32)pIS->GetProperties().size() )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir continue;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir break;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir else if( !bDontSeek && pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir pProperties = pIS;
76cdf0e10cSrcweir break;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir if( !pProperties )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
83cdf0e10cSrcweir maPropertiesList.Insert( pProperties, i );
84cdf0e10cSrcweir bAdded = sal_True;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
87cdf0e10cSrcweir rName = pProperties->GetName();
88cdf0e10cSrcweir
89cdf0e10cSrcweir return bAdded;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
93cdf0e10cSrcweir //
94cdf0e10cSrcweir // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
95cdf0e10cSrcweir // If the name exists already, nothing is done. If a style with a different name and
96cdf0e10cSrcweir // the same properties exists, a new one is added (like with bDontSeek).
97cdf0e10cSrcweir //
98cdf0e10cSrcweir
AddNamed(XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties,const OUString & rName)99cdf0e10cSrcweir sal_Bool SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir sal_Bool bAdded = sal_False;
102cdf0e10cSrcweir sal_uInt32 i = 0;
103cdf0e10cSrcweir sal_Int32 nProperties = rProperties.size();
104cdf0e10cSrcweir sal_uInt32 nCount = maPropertiesList.Count();
105cdf0e10cSrcweir
106cdf0e10cSrcweir for( i = 0; i < nCount; i++ )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
109cdf0e10cSrcweir if( nProperties > (sal_Int32)pIS->GetProperties().size() )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir continue;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir break;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir if( !pFamilyData->mpNameList->Seek_Entry( &rName, 0 ) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
122cdf0e10cSrcweir new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
123cdf0e10cSrcweir // ignore the generated name
124cdf0e10cSrcweir pProperties->SetName( rName );
125cdf0e10cSrcweir maPropertiesList.Insert( pProperties, i );
126cdf0e10cSrcweir bAdded = sal_True;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir return bAdded;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
133cdf0e10cSrcweir //
134cdf0e10cSrcweir // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
135cdf0e10cSrcweir //
136cdf0e10cSrcweir
Find(const XMLFamilyData_Impl * pFamilyData,const vector<XMLPropertyState> & rProperties) const137cdf0e10cSrcweir OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties ) const
138cdf0e10cSrcweir {
139cdf0e10cSrcweir OUString sName;
140cdf0e10cSrcweir vector< XMLPropertyState>::size_type nItems = rProperties.size();
141cdf0e10cSrcweir sal_uInt32 nCount = maPropertiesList.Count();
142cdf0e10cSrcweir for( sal_uInt32 i=0; i < nCount; i++ )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
145cdf0e10cSrcweir if( nItems > pIS->GetProperties().size() )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir continue;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir else if( nItems < pIS->GetProperties().size() )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir break;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir else if( pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir sName = pIS->GetName();
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir return sName;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir
163cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
164cdf0e10cSrcweir //
165cdf0e10cSrcweir // Sort-function for sorted list of SvXMLAutoStylePoolParent_Impl-elements
166cdf0e10cSrcweir //
167cdf0e10cSrcweir
SvXMLAutoStylePoolParentPCmp_Impl(const SvXMLAutoStylePoolParentP_Impl & r1,const SvXMLAutoStylePoolParentP_Impl & r2)168cdf0e10cSrcweir int SvXMLAutoStylePoolParentPCmp_Impl( const SvXMLAutoStylePoolParentP_Impl& r1,
169cdf0e10cSrcweir const SvXMLAutoStylePoolParentP_Impl& r2)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir return (int)r1.GetParent().compareTo( r2.GetParent() );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
175cdf0e10cSrcweir //
176cdf0e10cSrcweir // Implementation of sorted list of SvXMLAutoStylePoolParent_Impl-elements
177cdf0e10cSrcweir //
178cdf0e10cSrcweir
179cdf0e10cSrcweir IMPL_CONTAINER_SORT( SvXMLAutoStylePoolParentsP_Impl,
180cdf0e10cSrcweir SvXMLAutoStylePoolParentP_Impl,
181cdf0e10cSrcweir SvXMLAutoStylePoolParentPCmp_Impl )
182