xref: /aoo41x/main/xmloff/source/style/impastp3.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "impastpl.hxx"
31 #include <xmloff/xmlprmap.hxx>
32 
33 using namespace std;
34 using namespace rtl;
35 
36 //#############################################################################
37 //
38 // Class SvXMLAutoStylePoolParent_Impl
39 //
40 
41 ///////////////////////////////////////////////////////////////////////////////
42 //
43 // dtor class SvXMLAutoStylePoolParent_Impl
44 //
45 
46 SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl()
47 {
48 	while( maPropertiesList.Count() )
49 		delete maPropertiesList.Remove( maPropertiesList.Count() -1 );
50 }
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 //
54 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
55 // if not added, yet.
56 //
57 
58 sal_Bool SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek )
59 {
60 	sal_Bool bAdded = sal_False;
61     SvXMLAutoStylePoolPropertiesP_Impl *pProperties = 0;
62     sal_uInt32 i = 0;
63     sal_Int32 nProperties = rProperties.size();
64     sal_uInt32 nCount = maPropertiesList.Count();
65 
66     for( i = 0; i < nCount; i++ )
67     {
68         SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
69         if( nProperties > (sal_Int32)pIS->GetProperties().size() )
70         {
71             continue;
72         }
73         else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
74         {
75             break;
76         }
77         else if( !bDontSeek && pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
78         {
79             pProperties = pIS;
80             break;
81         }
82     }
83 
84     if( !pProperties )
85     {
86         pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
87         maPropertiesList.Insert( pProperties, i );
88         bAdded = sal_True;
89     }
90 
91     rName = pProperties->GetName();
92 
93     return bAdded;
94 }
95 
96 ///////////////////////////////////////////////////////////////////////////////
97 //
98 // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
99 // If the name exists already, nothing is done. If a style with a different name and
100 // the same properties exists, a new one is added (like with bDontSeek).
101 //
102 
103 sal_Bool SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName )
104 {
105     sal_Bool bAdded = sal_False;
106     sal_uInt32 i = 0;
107     sal_Int32 nProperties = rProperties.size();
108     sal_uInt32 nCount = maPropertiesList.Count();
109 
110     for( i = 0; i < nCount; i++ )
111     {
112         SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
113         if( nProperties > (sal_Int32)pIS->GetProperties().size() )
114         {
115             continue;
116         }
117         else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
118         {
119             break;
120         }
121     }
122 
123 	if( !pFamilyData->mpNameList->Seek_Entry( &rName, 0 ) )
124     {
125         SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
126                 new SvXMLAutoStylePoolPropertiesP_Impl( pFamilyData, rProperties );
127         // ignore the generated name
128         pProperties->SetName( rName );
129         maPropertiesList.Insert( pProperties, i );
130         bAdded = sal_True;
131     }
132 
133     return bAdded;
134 }
135 
136 ///////////////////////////////////////////////////////////////////////////////
137 //
138 // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
139 //
140 
141 OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl* pFamilyData, const vector< XMLPropertyState >& rProperties ) const
142 {
143 	OUString sName;
144 	vector< XMLPropertyState>::size_type nItems = rProperties.size();
145 	sal_uInt32 nCount = maPropertiesList.Count();
146 	for( sal_uInt32 i=0; i < nCount; i++ )
147 	{
148 		SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList.GetObject( i );
149 		if( nItems > pIS->GetProperties().size() )
150 		{
151 			continue;
152 		}
153 		else if( nItems < pIS->GetProperties().size() )
154 		{
155 			break;
156 		}
157 		else if( pFamilyData->mxMapper->Equals( pIS->GetProperties(), rProperties ) )
158 		{
159 			sName = pIS->GetName();
160 			break;
161 		}
162 	}
163 
164 	return sName;
165 }
166 
167 ///////////////////////////////////////////////////////////////////////////////
168 //
169 // Sort-function for sorted list of SvXMLAutoStylePoolParent_Impl-elements
170 //
171 
172 int SvXMLAutoStylePoolParentPCmp_Impl( const SvXMLAutoStylePoolParentP_Impl& r1,
173 									   const SvXMLAutoStylePoolParentP_Impl& r2)
174 {
175 	return (int)r1.GetParent().compareTo( r2.GetParent() );
176 }
177 
178 ///////////////////////////////////////////////////////////////////////////////
179 //
180 // Implementation of sorted list of SvXMLAutoStylePoolParent_Impl-elements
181 //
182 
183 IMPL_CONTAINER_SORT( SvXMLAutoStylePoolParentsP_Impl,
184 					 SvXMLAutoStylePoolParentP_Impl,
185 				     SvXMLAutoStylePoolParentPCmp_Impl )
186