merged tag ooo/OOO330_m14
[LibreOffice.git] / sw / inc / SwStyleNameMapper.hxx
blob688b066bc75a5188324cc94b448dbb97e0e46e64
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
27 #ifndef _SWSTYLENAMEMAPPER_HXX
28 #define _SWSTYLENAMEMAPPER_HXX
30 #include <sal/types.h>
31 #include <tools/string.hxx>
32 #include <SwGetPoolIdFromName.hxx>
33 #include "swdllapi.h"
35 #ifndef INCLUDED_HASH_MAP
36 #include <hash_map>
37 #define INCLUDED_HASH_MAP
38 #endif
39 #include <stringhash.hxx>
41 /* This class holds all data about the names of styles used in the user
42 * interface (UI names...these are localised into different languages).
43 * These UI names are loaded from the resource files on demand.
45 * It also holds all information about the 'Programmatic' names of styles
46 * which remain static (and are hardcoded in the corresponding cxx file)
47 * for all languages.
49 * This class also provides static functions which can be used for the
50 * following conversions:
52 * 1. Programmatic Name -> UI Name
53 * 2. Programmatic Name -> Pool ID
54 * 3. UI Name -> Programmatic Name
55 * 4. UI Name -> Pool ID
56 * 5. Pool ID -> UI Name
57 * 6. Pool ID -> Programmatic Name
59 * The relationship of these tables to the style families is as follows:
61 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
62 * name arrays.
63 * 2. Character contains the ChrFmt and HTMLChrFmt name arrays.
64 * 3. Page contains the PageDesc name array.
65 * 4. Frame contains the FrmFmt name array.
66 * 5. Numbering Rule contains the NumRule name array.
70 * There is a further complication that came to light later. If someone enters
71 * a user-defined style name which is the same as a programmatic name, this
72 * name clash must be handled.
74 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
75 * must be set to true in the SwStyleNameMapper call (it defaults to false).
76 * This will cause the following to happen:
78 * If the UI style name either equals a programmatic name or already ends
79 * with " (user)", then it must append " (user)" to the end.
81 * When a programmatic name is being converted to a UI name, if it ends in
82 * " (user)", we simply remove it.
85 class SvStringsDtor;
86 class String;
87 struct SwTableEntry;
90 typedef ::std::hash_map < const String*, sal_uInt16, StringHash, StringEq > NameToIdHash;
92 class SwStyleNameMapper
94 friend void _InitCore();
95 friend void _FinitCore();
97 protected:
98 // UI Name tables
99 static SvStringsDtor *pTextUINameArray,
100 *pListsUINameArray,
101 *pExtraUINameArray,
102 *pRegisterUINameArray,
103 *pDocUINameArray,
104 *pHTMLUINameArray,
105 *pFrmFmtUINameArray,
106 *pChrFmtUINameArray,
107 *pHTMLChrFmtUINameArray,
108 *pPageDescUINameArray,
109 *pNumRuleUINameArray,
110 // Programmatic Name tables
111 *pTextProgNameArray,
112 *pListsProgNameArray,
113 *pExtraProgNameArray,
114 *pRegisterProgNameArray,
115 *pDocProgNameArray,
116 *pHTMLProgNameArray,
117 *pFrmFmtProgNameArray,
118 *pChrFmtProgNameArray,
119 *pHTMLChrFmtProgNameArray,
120 *pPageDescProgNameArray,
121 *pNumRuleProgNameArray;
123 static NameToIdHash *pParaUIMap,
124 *pCharUIMap,
125 *pPageUIMap,
126 *pFrameUIMap,
127 *pNumRuleUIMap,
129 *pParaProgMap,
130 *pCharProgMap,
131 *pPageProgMap,
132 *pFrameProgMap,
133 *pNumRuleProgMap;
135 static SvStringsDtor* NewUINameArray( SvStringsDtor*&,
136 sal_uInt16 nStt,
137 sal_uInt16 nEnd );
139 static SvStringsDtor* NewProgNameArray( SvStringsDtor*&,
140 const SwTableEntry *pTable,
141 sal_uInt8 nCount);
143 static void fillNameFromId ( sal_uInt16 nId, String &rName, sal_Bool bProgName );
144 static const String& getNameFromId ( sal_uInt16 nId, const String &rName, sal_Bool bProgName );
145 static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, sal_Bool bProgName );
146 static sal_Bool SuffixIsUser ( const String & rString );
147 static void CheckSuffixAndDelete ( String & rString );
149 public:
150 // This gets the UI Name from the programmatic name
151 static const String& GetUIName ( const String& rName, SwGetPoolIdFromName );
152 static void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
154 // Get the programmatic Name from the UI name
155 static const String& GetProgName ( const String& rName, SwGetPoolIdFromName );
156 static void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
158 // This gets the UI Name from the Pool ID
159 SW_DLLPUBLIC static void FillUIName ( sal_uInt16 nId, String& rFillName );
160 SW_DLLPUBLIC static const String& GetUIName ( sal_uInt16 nId, const String& rName );
162 // This gets the programmatic Name from the Pool ID
163 static void FillProgName( sal_uInt16 nId, String& rFillName );
164 SW_DLLPUBLIC static const String& GetProgName ( sal_uInt16 nId, const String& rName );
166 // This gets the PoolId from the UI Name
167 SW_DLLPUBLIC static sal_uInt16 GetPoolIdFromUIName( const String& rName, SwGetPoolIdFromName );
169 // Get the Pool ID from the programmatic name
170 static sal_uInt16 GetPoolIdFromProgName( const String& rName, SwGetPoolIdFromName );
172 // used to convert the 4 special ExtraProg/UINames for
173 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
174 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
175 // forth and back.
176 // Non-matching names remain unchanged.
177 SW_DLLPUBLIC static const String GetSpecialExtraProgName( const String& rExtraUIName );
178 static const String GetSpecialExtraUIName( const String& rExtraProgName );
180 static const SvStringsDtor& GetTextUINameArray();
181 static const SvStringsDtor& GetListsUINameArray();
182 static const SvStringsDtor& GetExtraUINameArray();
183 static const SvStringsDtor& GetRegisterUINameArray();
184 static const SvStringsDtor& GetDocUINameArray();
185 static const SvStringsDtor& GetHTMLUINameArray();
186 static const SvStringsDtor& GetFrmFmtUINameArray();
187 static const SvStringsDtor& GetChrFmtUINameArray();
188 static const SvStringsDtor& GetHTMLChrFmtUINameArray();
189 static const SvStringsDtor& GetPageDescUINameArray();
190 static const SvStringsDtor& GetNumRuleUINameArray();
192 static const SvStringsDtor& GetTextProgNameArray();
193 static const SvStringsDtor& GetListsProgNameArray();
194 static const SvStringsDtor& GetExtraProgNameArray();
195 static const SvStringsDtor& GetRegisterProgNameArray();
196 static const SvStringsDtor& GetDocProgNameArray();
197 static const SvStringsDtor& GetHTMLProgNameArray();
198 static const SvStringsDtor& GetFrmFmtProgNameArray();
199 static const SvStringsDtor& GetChrFmtProgNameArray();
200 static const SvStringsDtor& GetHTMLChrFmtProgNameArray();
201 static const SvStringsDtor& GetPageDescProgNameArray();
202 static const SvStringsDtor& GetNumRuleProgNameArray();
204 #endif // _NAME_MAPPER_HXX