1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: impastp3.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include "impastpl.hxx"
34 #include <xmloff/xmlprmap.hxx>
39 //#############################################################################
41 // Class SvXMLAutoStylePoolParent_Impl
44 ///////////////////////////////////////////////////////////////////////////////
46 // dtor class SvXMLAutoStylePoolParent_Impl
49 SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl()
51 while( maPropertiesList
.Count() )
52 delete maPropertiesList
.Remove( maPropertiesList
.Count() -1 );
55 ///////////////////////////////////////////////////////////////////////////////
57 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
61 sal_Bool
SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl
* pFamilyData
, const vector
< XMLPropertyState
>& rProperties
, OUString
& rName
, bool bDontSeek
)
63 sal_Bool bAdded
= sal_False
;
64 SvXMLAutoStylePoolPropertiesP_Impl
*pProperties
= 0;
66 sal_Int32 nProperties
= rProperties
.size();
67 sal_uInt32 nCount
= maPropertiesList
.Count();
69 for( i
= 0; i
< nCount
; i
++ )
71 SvXMLAutoStylePoolPropertiesP_Impl
*pIS
= maPropertiesList
.GetObject( i
);
72 if( nProperties
> (sal_Int32
)pIS
->GetProperties().size() )
76 else if( nProperties
< (sal_Int32
)pIS
->GetProperties().size() )
80 else if( !bDontSeek
&& pFamilyData
->mxMapper
->Equals( pIS
->GetProperties(), rProperties
) )
89 pProperties
= new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData
, rProperties
);
90 maPropertiesList
.Insert( pProperties
, i
);
94 rName
= pProperties
->GetName();
99 ///////////////////////////////////////////////////////////////////////////////
101 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
102 // If the name exists already, nothing is done. If a style with a different name and
103 // the same properties exists, a new one is added (like with bDontSeek).
106 sal_Bool
SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl
* pFamilyData
, const vector
< XMLPropertyState
>& rProperties
, const OUString
& rName
)
108 sal_Bool bAdded
= sal_False
;
110 sal_Int32 nProperties
= rProperties
.size();
111 sal_uInt32 nCount
= maPropertiesList
.Count();
113 for( i
= 0; i
< nCount
; i
++ )
115 SvXMLAutoStylePoolPropertiesP_Impl
*pIS
= maPropertiesList
.GetObject( i
);
116 if( nProperties
> (sal_Int32
)pIS
->GetProperties().size() )
120 else if( nProperties
< (sal_Int32
)pIS
->GetProperties().size() )
126 if( !pFamilyData
->mpNameList
->Seek_Entry( &rName
, 0 ) )
128 SvXMLAutoStylePoolPropertiesP_Impl
* pProperties
=
129 new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData
, rProperties
);
130 // ignore the generated name
131 pProperties
->SetName( rName
);
132 maPropertiesList
.Insert( pProperties
, i
);
139 ///////////////////////////////////////////////////////////////////////////////
141 // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
144 OUString
SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl
* pFamilyData
, const vector
< XMLPropertyState
>& rProperties
) const
147 vector
< XMLPropertyState
>::size_type nItems
= rProperties
.size();
148 sal_uInt32 nCount
= maPropertiesList
.Count();
149 for( sal_uInt32 i
=0; i
< nCount
; i
++ )
151 SvXMLAutoStylePoolPropertiesP_Impl
*pIS
= maPropertiesList
.GetObject( i
);
152 if( nItems
> pIS
->GetProperties().size() )
156 else if( nItems
< pIS
->GetProperties().size() )
160 else if( pFamilyData
->mxMapper
->Equals( pIS
->GetProperties(), rProperties
) )
162 sName
= pIS
->GetName();
170 ///////////////////////////////////////////////////////////////////////////////
172 // Sort-function for sorted list of SvXMLAutoStylePoolParent_Impl-elements
175 int SvXMLAutoStylePoolParentPCmp_Impl( const SvXMLAutoStylePoolParentP_Impl
& r1
,
176 const SvXMLAutoStylePoolParentP_Impl
& r2
)
178 return (int)r1
.GetParent().compareTo( r2
.GetParent() );
181 ///////////////////////////////////////////////////////////////////////////////
183 // Implementation of sorted list of SvXMLAutoStylePoolParent_Impl-elements
186 IMPL_CONTAINER_SORT( SvXMLAutoStylePoolParentsP_Impl
,
187 SvXMLAutoStylePoolParentP_Impl
,
188 SvXMLAutoStylePoolParentPCmp_Impl
)