update dev300-m58
[ooovba.git] / xmloff / source / style / impastp3.cxx
blobe6c8b8fb821e294c08608437eadfc2670a4890c7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: impastp3.cxx,v $
10 * $Revision: 1.9 $
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>
36 using namespace std;
37 using namespace rtl;
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
58 // if not added, yet.
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;
65 sal_uInt32 i = 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() )
74 continue;
76 else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
78 break;
80 else if( !bDontSeek && pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
82 pProperties = pIS;
83 break;
87 if( !pProperties )
89 pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
90 maPropertiesList.Insert( pProperties, i );
91 bAdded = sal_True;
94 rName = pProperties->GetName();
96 return bAdded;
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;
109 sal_uInt32 i = 0;
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() )
118 continue;
120 else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
122 break;
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 );
133 bAdded = sal_True;
136 return bAdded;
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
146 OUString sName;
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() )
154 continue;
156 else if( nItems < pIS->GetProperties().size() )
158 break;
160 else if( pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
162 sName = pIS->GetName();
163 break;
167 return sName;
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 )