xref: /trunk/main/sw/inc/SwStyleNameMapper.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SWSTYLENAMEMAPPER_HXX
24 #define _SWSTYLENAMEMAPPER_HXX
25 
26 #include <sal/types.h>
27 #include <tools/string.hxx>
28 #include <SwGetPoolIdFromName.hxx>
29 #include "swdllapi.h"
30 
31 #ifndef INCLUDED_HASH_MAP
32 #include <hash_map>
33 #define INCLUDED_HASH_MAP
34 #endif
35 #include <stringhash.hxx>
36 
37 /* This class holds all data about the names of styles used in the user
38  * interface (UI names...these are localised into different languages).
39  * These UI names are loaded from the resource files on demand.
40  *
41  * It also holds all information about the 'Programmatic' names of styles
42  * which remain static (and are hardcoded in the corresponding cxx file)
43  * for all languages.
44  *
45  * This class also provides static functions which can be used for the
46  * following conversions:
47  *
48  * 1. Programmatic Name -> UI Name
49  * 2. Programmatic Name -> Pool ID
50  * 3. UI Name -> Programmatic Name
51  * 4. UI Name -> Pool ID
52  * 5. Pool ID -> UI Name
53  * 6. Pool ID -> Programmatic Name
54  *
55  * The relationship of these tables to the style families is as follows:
56  *
57  * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
58  *    name arrays.
59  * 2. Character contains the ChrFmt and HTMLChrFmt name arrays.
60  * 3. Page contains the PageDesc name array.
61  * 4. Frame contains the FrmFmt name array.
62  * 5. Numbering Rule contains the NumRule name array.
63  */
64 
65 /*
66  * There is a further complication that came to light later. If someone enters
67  * a user-defined style name which is the same as a programmatic name, this
68  * name clash must be handled.
69  *
70  * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
71  * must be set to true in the SwStyleNameMapper call (it defaults to false).
72  * This will cause the following to happen:
73  *
74  * If the UI style name either equals a programmatic name or already ends
75  * with " (user)", then it must append " (user)" to the end.
76  *
77  * When a programmatic name is being converted to a UI name, if it ends in
78  * " (user)", we simply remove it.
79  */
80 
81 class SvStringsDtor;
82 class String;
83 struct SwTableEntry;
84 
85 
86 typedef ::std::hash_map < const String*, sal_uInt16, StringHash, StringEq > NameToIdHash;
87 
88 class SwStyleNameMapper
89 {
90 	friend void _InitCore();
91 	friend void _FinitCore();
92 
93 protected:
94 	// UI Name tables
95 	static SvStringsDtor	*pTextUINameArray,
96 							*pListsUINameArray,
97 							*pExtraUINameArray,
98 							*pRegisterUINameArray,
99 							*pDocUINameArray,
100 							*pHTMLUINameArray,
101 							*pFrmFmtUINameArray,
102 							*pChrFmtUINameArray,
103 							*pHTMLChrFmtUINameArray,
104 							*pPageDescUINameArray,
105 							*pNumRuleUINameArray,
106 	// Programmatic Name tables
107 							*pTextProgNameArray,
108 							*pListsProgNameArray,
109 							*pExtraProgNameArray,
110 							*pRegisterProgNameArray,
111 							*pDocProgNameArray,
112 							*pHTMLProgNameArray,
113 							*pFrmFmtProgNameArray,
114 							*pChrFmtProgNameArray,
115 							*pHTMLChrFmtProgNameArray,
116 							*pPageDescProgNameArray,
117 							*pNumRuleProgNameArray;
118 
119 	static NameToIdHash     *pParaUIMap,
120 							*pCharUIMap,
121 							*pPageUIMap,
122 							*pFrameUIMap,
123 							*pNumRuleUIMap,
124 
125 							*pParaProgMap,
126 							*pCharProgMap,
127 							*pPageProgMap,
128 							*pFrameProgMap,
129 							*pNumRuleProgMap;
130 
131     static SvStringsDtor* NewUINameArray( SvStringsDtor*&,
132 									  sal_uInt16 nStt,
133 									  sal_uInt16 nEnd );
134 
135     static SvStringsDtor* NewProgNameArray( SvStringsDtor*&,
136 										  const SwTableEntry *pTable,
137 										  sal_uInt8 nCount);
138 
139 	static void fillNameFromId ( sal_uInt16 nId, String &rName, sal_Bool bProgName );
140 	static const String& getNameFromId ( sal_uInt16 nId, const String &rName, sal_Bool bProgName );
141 	static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, sal_Bool bProgName );
142 	static sal_Bool SuffixIsUser ( const String & rString );
143 	static void CheckSuffixAndDelete ( String & rString );
144 
145 public:
146 	// This gets the UI Name from the programmatic name
147 	static const String& GetUIName ( const String& rName, SwGetPoolIdFromName );
148 	static 		   void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
149 
150 	// Get the programmatic Name from the UI name
151 	static const String& GetProgName ( const String& rName, SwGetPoolIdFromName );
152 	static 		   void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
153 
154 	// This gets the UI Name from the Pool ID
155 	SW_DLLPUBLIC static          void FillUIName ( sal_uInt16 nId, String& rFillName );
156 	SW_DLLPUBLIC static const String& GetUIName  ( sal_uInt16 nId, const String& rName );
157 
158 	// This gets the programmatic Name from the Pool ID
159 	static 		    void FillProgName( sal_uInt16 nId, String& rFillName );
160 	SW_DLLPUBLIC static const String& GetProgName ( sal_uInt16 nId, const String& rName );
161 
162 	// This gets the PoolId from the UI Name
163 	SW_DLLPUBLIC static sal_uInt16 GetPoolIdFromUIName( const String& rName, SwGetPoolIdFromName );
164 
165 	// Get the Pool ID from the programmatic name
166 	static sal_uInt16 GetPoolIdFromProgName( const String& rName, SwGetPoolIdFromName );
167 
168     // used to convert the 4 special ExtraProg/UINames for
169     // RES_POOLCOLL_LABEL_DRAWING,  RES_POOLCOLL_LABEL_ABB,
170     // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
171     // forth and back.
172     // Non-matching names remain unchanged.
173     SW_DLLPUBLIC static const String GetSpecialExtraProgName( const String& rExtraUIName );
174     static const String GetSpecialExtraUIName( const String& rExtraProgName );
175 
176 	static const SvStringsDtor& GetTextUINameArray();
177 	static const SvStringsDtor& GetListsUINameArray();
178 	static const SvStringsDtor& GetExtraUINameArray();
179 	static const SvStringsDtor& GetRegisterUINameArray();
180 	static const SvStringsDtor& GetDocUINameArray();
181 	static const SvStringsDtor& GetHTMLUINameArray();
182 	static const SvStringsDtor& GetFrmFmtUINameArray();
183 	static const SvStringsDtor& GetChrFmtUINameArray();
184 	static const SvStringsDtor& GetHTMLChrFmtUINameArray();
185 	static const SvStringsDtor& GetPageDescUINameArray();
186 	static const SvStringsDtor& GetNumRuleUINameArray();
187 
188 	static const SvStringsDtor& GetTextProgNameArray();
189 	static const SvStringsDtor& GetListsProgNameArray();
190 	static const SvStringsDtor& GetExtraProgNameArray();
191 	static const SvStringsDtor& GetRegisterProgNameArray();
192 	static const SvStringsDtor& GetDocProgNameArray();
193 	static const SvStringsDtor& GetHTMLProgNameArray();
194 	static const SvStringsDtor& GetFrmFmtProgNameArray();
195 	static const SvStringsDtor& GetChrFmtProgNameArray();
196 	static const SvStringsDtor& GetHTMLChrFmtProgNameArray();
197 	static const SvStringsDtor& GetPageDescProgNameArray();
198 	static const SvStringsDtor& GetNumRuleProgNameArray();
199 };
200 #endif // _NAME_MAPPER_HXX
201