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