Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sw / SwStyleNameMapper.hxx
bloba4163625e998ff33c1a7a807f09731a384e5a203
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: SwStyleNameMapper.hxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
30 #ifndef _SWSTYLENAMEMAPPER_HXX
31 #define _SWSTYLENAMEMAPPER_HXX
33 #ifndef _SAL_TYPES_H_
34 #include <sal/types.h>
35 #endif
36 #ifndef _GETPOOLIDFROMNAMEENUM_HXX
37 #include <SwGetPoolIdFromName.hxx>
38 #endif
39 #ifndef _STRING_HXX
40 #include <tools/string.hxx>
41 #endif
42 #include <hash_map>
44 class String;
46 namespace binfilter {
47 class SvStringsDtor;
50 /* This class holds all data about the names of styles used in the user
51 * interface (UI names...these are localised into different languages).
52 * These UI names are loaded from the resource files on demand.
54 * It also holds all information about the 'Programmatic' names of styles
55 * which remain static (and are hardcoded in the corresponding cxx file)
56 * for all languages.
58 * This class also provides static functions which can be used for the
59 * following conversions:
61 * 1. Programmatic Name -> UI Name
62 * 2. Programmatic Name -> Pool ID
63 * 3. UI Name -> Programmatic Name
64 * 4. UI Name -> Pool ID
65 * 5. Pool ID -> UI Name
66 * 6. Pool ID -> Programmatic Name
68 * The relationship of these tables to the style families is as follows:
70 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
71 * name arrays.
72 * 2. Character contains the ChrFmt and HTMLChrFmt name arrays.
73 * 3. Page contains the PageDesc name array.
74 * 4. Frame contains the FrmFmt name array.
75 * 5. Numbering Rule contains the NumRule name array.
79 * There is a further complication that came to light later. If someone enters
80 * a user-defined style name which is the same as a programmatic name, this
81 * name clash must be handled.
83 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
84 * must be set to true in the SwStyleNameMapper call (it defaults to false).
85 * This will cause the following to happen:
87 * If the UI style name either equals a programmatic name or already ends
88 * with " (user)", then it must append " (user)" to the end.
90 * When a programmatic name is being converted to a UI name, if it ends in
91 * " (user)", we simply remove it.
94 struct SwTableEntry;
95 struct StringEq
97 sal_Bool operator() ( const String *r1,
98 const String *r2) const
100 return r1->Equals(*r2);
104 struct StringHash
106 size_t operator() ( const String *rString) const
108 sal_Int32 h, nLen;
109 h = nLen = rString->Len();
110 const sal_Unicode *pStr = rString->GetBuffer();
112 if ( nLen < 16 )
113 while ( nLen-- > 0 )
114 h = (h*37) + *(pStr++);
115 else
117 sal_Int32 nSkip;
118 const sal_Unicode* pEndStr = pStr+nLen-5;
120 /* only sample some characters */
121 /* the first 3, some characters between, and the last 5 */
122 h = (h*39) + *(pStr++);
123 h = (h*39) + *(pStr++);
124 h = (h*39) + *(pStr++);
126 nSkip = nLen / nLen < 32 ? 4 : 8;
127 nLen -= 8;
128 while ( nLen > 0 )
130 h = (h*39) + ( *pStr );
131 pStr += nSkip;
132 nLen -= nSkip;
135 h = (h*39) + *(pEndStr++);
136 h = (h*39) + *(pEndStr++);
137 h = (h*39) + *(pEndStr++);
138 h = (h*39) + *(pEndStr++);
139 h = (h*39) + *(pEndStr++);
141 return h;
146 typedef ::std::hash_map < const String*, sal_uInt16, StringHash, StringEq > NameToIdHash;
148 class SwStyleNameMapper
150 friend void _InitCore();
151 friend void _FinitCore();
153 protected:
154 // UI Name tables
155 static SvStringsDtor *pTextUINameArray,
156 *pListsUINameArray,
157 *pExtraUINameArray,
158 *pRegisterUINameArray,
159 *pDocUINameArray,
160 *pHTMLUINameArray,
161 *pFrmFmtUINameArray,
162 *pChrFmtUINameArray,
163 *pHTMLChrFmtUINameArray,
164 *pPageDescUINameArray,
165 *pNumRuleUINameArray,
166 // Programmatic Name tables
167 *pTextProgNameArray,
168 *pListsProgNameArray,
169 *pExtraProgNameArray,
170 *pRegisterProgNameArray,
171 *pDocProgNameArray,
172 *pHTMLProgNameArray,
173 *pFrmFmtProgNameArray,
174 *pChrFmtProgNameArray,
175 *pHTMLChrFmtProgNameArray,
176 *pPageDescProgNameArray,
177 *pNumRuleProgNameArray;
179 static NameToIdHash *pParaUIMap,
180 *pCharUIMap,
181 *pPageUIMap,
182 *pFrameUIMap,
183 *pNumRuleUIMap,
185 *pParaProgMap,
186 *pCharProgMap,
187 *pPageProgMap,
188 *pFrameProgMap,
189 *pNumRuleProgMap;
191 static SvStringsDtor* NewUINameArray( SvStringsDtor*&,
192 sal_uInt16 nStt,
193 sal_uInt16 nEnd );
195 static SvStringsDtor* NewProgNameArray( SvStringsDtor*&,
196 const SwTableEntry *pTable,
197 sal_uInt8 nCount);
199 static void fillNameFromId ( sal_uInt16 nId, String &rName, sal_Bool bProgName );
200 static const String& getNameFromId ( sal_uInt16 nId, const String &rName, sal_Bool bProgName );
201 static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, sal_Bool bProgName );
202 static sal_Bool SuffixIsUser ( const String & rString );
203 static void CheckSuffixAndDelete ( String & rString );
205 public:
206 // This gets the UI Name from the programmatic name
207 static const String& GetUIName ( const String& rName, SwGetPoolIdFromName );
208 static void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
209 // Get the programmatic Name from the UI name
210 static const String& GetProgName ( const String& rName, SwGetPoolIdFromName );
211 static void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
213 // This gets the UI Name from the Pool ID
214 static void FillUIName ( sal_uInt16 nId, String& rFillName );
215 static const String& GetUIName ( sal_uInt16 nId, const String& rName );
217 // This gets the programmatic Name from the Pool ID
218 static void FillProgName( sal_uInt16 nId, String& rFillName );
219 static const String& GetProgName ( sal_uInt16 nId, const String& rName );
221 // This gets the PoolId from the UI Name
222 static sal_uInt16 GetPoolIdFromUIName( const String& rName, SwGetPoolIdFromName );
223 // Get the Pool ID from the programmatic name
224 static sal_uInt16 GetPoolIdFromProgName( const String& rName, SwGetPoolIdFromName );
226 // used to convert the 4 special ExtraProg/UINames for
227 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
228 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
229 // forth and back.
230 // Non-matching names remain unchanged.
231 static const String GetSpecialExtraProgName( const String& rExtraUIName );
232 static const String GetSpecialExtraUIName( const String& rExtraProgName );
234 static const SvStringsDtor& GetTextUINameArray();
235 static const SvStringsDtor& GetListsUINameArray();
236 static const SvStringsDtor& GetExtraUINameArray();
237 static const SvStringsDtor& GetRegisterUINameArray();
238 static const SvStringsDtor& GetDocUINameArray();
239 static const SvStringsDtor& GetHTMLUINameArray();
240 static const SvStringsDtor& GetFrmFmtUINameArray();
241 static const SvStringsDtor& GetChrFmtUINameArray();
242 static const SvStringsDtor& GetHTMLChrFmtUINameArray();
243 static const SvStringsDtor& GetPageDescUINameArray();
244 static const SvStringsDtor& GetNumRuleUINameArray();
246 static const SvStringsDtor& GetTextProgNameArray();
247 static const SvStringsDtor& GetListsProgNameArray();
248 static const SvStringsDtor& GetExtraProgNameArray();
249 static const SvStringsDtor& GetRegisterProgNameArray();
250 static const SvStringsDtor& GetDocProgNameArray();
251 static const SvStringsDtor& GetHTMLProgNameArray();
252 static const SvStringsDtor& GetFrmFmtProgNameArray();
253 static const SvStringsDtor& GetChrFmtProgNameArray();
254 static const SvStringsDtor& GetHTMLChrFmtProgNameArray();
255 static const SvStringsDtor& GetPageDescProgNameArray();
256 static const SvStringsDtor& GetNumRuleProgNameArray();
258 } //namespace binfilter
259 #endif // _NAME_MAPPER_HXX