Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "impastpl.hxx"
21 : #include <xmloff/xmlprmap.hxx>
22 :
23 : using namespace std;
24 :
25 : using ::rtl::OUString;
26 :
27 : //#############################################################################
28 : //
29 : // Class SvXMLAutoStylePoolParent_Impl
30 : //
31 :
32 : ///////////////////////////////////////////////////////////////////////////////
33 : //
34 : // dtor class SvXMLAutoStylePoolParent_Impl
35 : //
36 :
37 86 : SvXMLAutoStylePoolParentP_Impl::~SvXMLAutoStylePoolParentP_Impl()
38 : {
39 103 : for( size_t i = maPropertiesList.size(); i > 0; )
40 17 : delete maPropertiesList[ --i ];
41 43 : maPropertiesList.clear();
42 43 : }
43 :
44 : ///////////////////////////////////////////////////////////////////////////////
45 : //
46 : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
47 : // if not added, yet.
48 : //
49 :
50 17 : sal_Bool SvXMLAutoStylePoolParentP_Impl::Add( XMLFamilyData_Impl& rFamilyData, const vector< XMLPropertyState >& rProperties, OUString& rName, bool bDontSeek )
51 : {
52 17 : sal_Bool bAdded = sal_False;
53 17 : SvXMLAutoStylePoolPropertiesP_Impl *pProperties = 0;
54 17 : size_t i = 0;
55 17 : sal_Int32 nProperties = rProperties.size();
56 17 : size_t nCount = maPropertiesList.size();
57 :
58 22 : for( i = 0; i < nCount; i++ )
59 : {
60 5 : SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ];
61 5 : if( nProperties > (sal_Int32)pIS->GetProperties().size() )
62 : {
63 2 : continue;
64 : }
65 3 : else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
66 : {
67 0 : break;
68 : }
69 3 : else if( !bDontSeek && rFamilyData.mxMapper->Equals( pIS->GetProperties(), rProperties ) )
70 : {
71 0 : pProperties = pIS;
72 0 : break;
73 : }
74 : }
75 :
76 17 : if( !pProperties )
77 : {
78 17 : pProperties = new SvXMLAutoStylePoolPropertiesP_Impl( rFamilyData, rProperties );
79 17 : SvXMLAutoStylePoolPropertiesPList_Impl::iterator it = maPropertiesList.begin();
80 17 : ::std::advance( it, i );
81 17 : maPropertiesList.insert( it, pProperties );
82 17 : bAdded = sal_True;
83 : }
84 :
85 17 : rName = pProperties->GetName();
86 :
87 17 : return bAdded;
88 : }
89 :
90 : ///////////////////////////////////////////////////////////////////////////////
91 : //
92 : // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) with a given name.
93 : // If the name exists already, nothing is done. If a style with a different name and
94 : // the same properties exists, a new one is added (like with bDontSeek).
95 : //
96 :
97 0 : sal_Bool SvXMLAutoStylePoolParentP_Impl::AddNamed( XMLFamilyData_Impl& rFamilyData, const vector< XMLPropertyState >& rProperties, const OUString& rName )
98 : {
99 0 : sal_Bool bAdded = sal_False;
100 0 : size_t i = 0;
101 0 : sal_Int32 nProperties = rProperties.size();
102 0 : size_t nCount = maPropertiesList.size();
103 :
104 0 : for( i = 0; i < nCount; i++ )
105 : {
106 0 : SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ];
107 0 : if( nProperties > (sal_Int32)pIS->GetProperties().size() )
108 : {
109 0 : continue;
110 : }
111 0 : else if( nProperties < (sal_Int32)pIS->GetProperties().size() )
112 : {
113 0 : break;
114 : }
115 : }
116 :
117 0 : if(rFamilyData.mpNameList->find(rName) == rFamilyData.mpNameList->end())
118 : {
119 : SvXMLAutoStylePoolPropertiesP_Impl* pProperties =
120 0 : new SvXMLAutoStylePoolPropertiesP_Impl( rFamilyData, rProperties );
121 : // ignore the generated name
122 0 : pProperties->SetName( rName );
123 0 : SvXMLAutoStylePoolPropertiesPList_Impl::iterator it = maPropertiesList.begin();
124 0 : ::std::advance( it, i );
125 0 : maPropertiesList.insert( it, pProperties );
126 0 : bAdded = sal_True;
127 : }
128 :
129 0 : return bAdded;
130 : }
131 :
132 : ///////////////////////////////////////////////////////////////////////////////
133 : //
134 : // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
135 : //
136 :
137 10 : OUString SvXMLAutoStylePoolParentP_Impl::Find( const XMLFamilyData_Impl& rFamilyData, const vector< XMLPropertyState >& rProperties ) const
138 : {
139 10 : OUString sName;
140 10 : vector< XMLPropertyState>::size_type nItems = rProperties.size();
141 10 : size_t nCount = maPropertiesList.size();
142 15 : for( size_t i = 0; i < nCount; i++ )
143 : {
144 11 : SvXMLAutoStylePoolPropertiesP_Impl *pIS = maPropertiesList[ i ];
145 11 : if( nItems > pIS->GetProperties().size() )
146 : {
147 2 : continue;
148 : }
149 9 : else if( nItems < pIS->GetProperties().size() )
150 : {
151 0 : break;
152 : }
153 9 : else if( rFamilyData.mxMapper->Equals( pIS->GetProperties(), rProperties ) )
154 : {
155 6 : sName = pIS->GetName();
156 6 : break;
157 : }
158 : }
159 :
160 10 : return sName;
161 : }
162 :
163 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|