merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / pdfimport / tree / style.hxx
blob07b1aff27e11cb0ba85caea960210b6dbbeee260
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: style.hxx,v $
11 * $Revision: 1.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef INCLUDED_PDFI_STYLE_HXX
33 #define INCLUDED_PDFI_STYLE_HXX
35 #include "pdfihelper.hxx"
36 #include <hash_map>
37 #include <vector>
38 #include <rtl/ustring.hxx>
39 #include <rtl/string.hxx>
40 #include "treevisiting.hxx"
42 namespace pdfi
44 struct Element;
45 struct EmitContext;
46 struct ElementTreeVisitable;
48 class StyleContainer
50 public:
51 struct Style
53 rtl::OString Name;
54 PropertyMap Properties;
55 rtl::OUString Contents;
56 Element* ContainedElement;
57 std::vector< Style* > SubStyles;
59 Style() : ContainedElement( NULL ) {}
60 Style( const rtl::OString& rName, const PropertyMap& rProps ) :
61 Name( rName ),
62 Properties( rProps ),
63 ContainedElement( NULL )
67 private:
68 struct HashedStyle
70 rtl::OString Name;
71 PropertyMap Properties;
72 rtl::OUString Contents;
73 Element* ContainedElement;
74 std::vector<sal_Int32> SubStyles;
76 bool IsSubStyle;
77 sal_Int32 RefCount;
79 HashedStyle() : ContainedElement( NULL ), IsSubStyle( true ), RefCount( 0 ) {}
81 HashedStyle( const HashedStyle& rRight ) :
82 Name( rRight.Name ),
83 Properties( rRight.Properties ),
84 Contents( rRight.Contents ),
85 ContainedElement( rRight.ContainedElement ),
86 SubStyles( rRight.SubStyles ),
87 IsSubStyle( rRight.IsSubStyle ),
88 RefCount( 0 )
91 size_t hashCode() const
93 size_t nRet = size_t(Name.hashCode());
94 for( PropertyMap::const_iterator it = Properties.begin();
95 it != Properties.end(); ++it )
97 nRet ^= size_t(it->first.hashCode());
98 nRet ^= size_t(it->second.hashCode());
100 nRet = size_t(Contents.hashCode());
101 nRet ^= size_t(ContainedElement);
102 for( unsigned int n = 0; n < SubStyles.size(); ++n )
103 nRet ^= size_t(SubStyles[n]);
104 return nRet;
107 bool operator==(const HashedStyle& rRight) const
109 if( Name != rRight.Name ||
110 Properties != rRight.Properties ||
111 Contents != rRight.Contents ||
112 ContainedElement != rRight.ContainedElement ||
113 SubStyles.size() != rRight.SubStyles.size()
115 return false;
116 for( unsigned int n = 0; n < SubStyles.size(); ++n )
118 if( SubStyles[n] != rRight.SubStyles[n] )
119 return false;
121 return true;
125 struct StyleHash;
126 friend struct StyleHash;
127 struct StyleHash
129 size_t operator()( const StyleContainer::HashedStyle& rStyle ) const
131 return rStyle.hashCode();
135 struct StyleIdNameSort;
136 friend struct StyleIdNameSort;
137 struct StyleIdNameSort
139 const std::hash_map< sal_Int32, HashedStyle >* m_pMap;
141 StyleIdNameSort( const std::hash_map< sal_Int32, HashedStyle >* pMap ) :
142 m_pMap(pMap)
144 bool operator()( sal_Int32 nLeft, sal_Int32 nRight )
146 const std::hash_map< sal_Int32, HashedStyle >::const_iterator left_it =
147 m_pMap->find( nLeft );
148 const std::hash_map< sal_Int32, HashedStyle >::const_iterator right_it =
149 m_pMap->find( nRight );
150 if( left_it == m_pMap->end() )
151 return false;
152 else if( right_it == m_pMap->end() )
153 return true;
154 else
155 return left_it->second.Name < right_it->second.Name;
159 sal_Int32 m_nNextId;
160 std::hash_map< sal_Int32, HashedStyle > m_aIdToStyle;
161 std::hash_map< HashedStyle, sal_Int32, StyleHash > m_aStyleToId;
163 void impl_emitStyle( sal_Int32 nStyleId,
164 EmitContext& rContext,
165 ElementTreeVisitor& rContainedElemVisitor );
167 public:
168 StyleContainer();
170 void emit( EmitContext& rContext,
171 ElementTreeVisitor& rContainedElemVisitor );
173 sal_Int32 impl_getStyleId( const Style& rStyle, bool bSubStyle );
174 sal_Int32 getStyleId( const Style& rStyle )
175 { return impl_getStyleId( rStyle, false ); }
176 sal_Int32 getStandardStyleId( const rtl::OString& rFamily );
178 // returns NULL for an invalid style id
179 const PropertyMap* getProperties( sal_Int32 nStyleId ) const;
180 sal_Int32 setProperties( sal_Int32 nStyleId, const PropertyMap &rNewProps );
181 rtl::OUString getStyleName( sal_Int32 nStyle ) const;
185 #endif