xref: /core/sw/source/core/doc/SwStyleNameMapper.cxx (revision f79569adeacc971ae1272871da3e4e5ee002c559)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <SwStyleNameMapper.hxx>
21 #include <poolfmt.hxx>
22 #include <strings.hrc>
23 #include <swtypes.hxx>
24 #include <unotools/syslocale.hxx>
25 #include <i18nlangtag/languagetag.hxx>
26 #include <o3tl/string_view.hxx>
27 #include <map>
28 #include <names.hxx>
29 
30 #ifdef _NEED_TO_DEBUG_MAPPING
31 #include <stdlib.h>
32 #endif
33 
34 namespace
35 {
36 
37 const OUString &
lcl_GetSpecialExtraName(const OUString & rExtraName,const bool bIsUIName)38 lcl_GetSpecialExtraName(const OUString& rExtraName, const bool bIsUIName )
39 {
40     const std::vector<OUString>& rExtraArr = bIsUIName
41         ? SwStyleNameMapper::GetExtraUINameArray()
42         : SwStyleNameMapper::GetExtraProgNameArray();
43     static const sal_uInt16 nIds[] =
44     {
45         RES_POOLCOLL_LABEL_DRAWING - RES_POOLCOLL_EXTRA_BEGIN,
46         RES_POOLCOLL_LABEL_ABB - RES_POOLCOLL_EXTRA_BEGIN,
47         RES_POOLCOLL_LABEL_TABLE - RES_POOLCOLL_EXTRA_BEGIN,
48         RES_POOLCOLL_LABEL_FRAME- RES_POOLCOLL_EXTRA_BEGIN,
49         RES_POOLCOLL_LABEL_FIGURE-RES_POOLCOLL_EXTRA_BEGIN,
50         0
51     };
52     const sal_uInt16 * pIds;
53     for ( pIds = nIds; *pIds; ++pIds)
54     {
55         if (rExtraName == rExtraArr[ *pIds ])
56         {
57             return bIsUIName
58                 ? SwStyleNameMapper::GetExtraProgNameArray()[*pIds]
59                 : SwStyleNameMapper::GetExtraUINameArray()[*pIds];
60         }
61     }
62     return rExtraName;
63 }
64 
lcl_SuffixIsUser(std::u16string_view rString)65 bool lcl_SuffixIsUser(std::u16string_view rString)
66 {
67     // Interesting, why the rest must be longer than 1 character? It is so
68     // since commit 4fbc9dd48b7cebb304010e7337b1bbc3936c7923 (2001-08-16)
69     return rString.size() > 8 && o3tl::ends_with(rString, u" (user)");
70 }
71 
72 template<class T>
lcl_CheckSuffixAndDelete(T & rString)73 void lcl_CheckSuffixAndDelete(T & rString)
74 {
75     if (lcl_SuffixIsUser(rString.toString()))
76     {
77         rString = T(rString.toString().copy(0, rString.toString().getLength() - 7));
78     }
79 }
80 
lcl_CheckSuffixAndDelete(ProgName & rString)81 void lcl_CheckSuffixAndDelete(ProgName & rString)
82 {
83     if (lcl_SuffixIsUser(rString.toString()))
84     {
85         rString = ProgName(rString.toString().copy(0, rString.toString().getLength() - 7));
86     }
87 }
88 
HashFromRange(sal_uInt16 nAcc)89 NameToIdHash HashFromRange(sal_uInt16 nAcc) { return NameToIdHash(nAcc); }
90 template <typename... Rest>
HashFromRange(sal_uInt16 nAcc,sal_uInt16 nBegin,sal_uInt16 nEnd,const std::vector<OUString> & (* pFunc)(),Rest...rest)91 NameToIdHash HashFromRange(sal_uInt16 nAcc, sal_uInt16 nBegin, sal_uInt16 nEnd,
92                            const std::vector<OUString>& (*pFunc)(), Rest... rest)
93 {
94     NameToIdHash hash(HashFromRange(nAcc + nEnd - nBegin, rest...));
95     sal_uInt16 nIndex, nId;
96     const std::vector<OUString>& rStrings = pFunc();
97     for (nIndex = 0, nId = nBegin; nId < nEnd; nId++, nIndex++)
98         hash[rStrings[nIndex]] = nId;
99     return hash;
100 }
101 
102 template <auto initFunc> struct TablePair
103 {
getMap__anon8c41fb6d0111::TablePair104     static const NameToIdHash& getMap(bool bProgName)
105     {
106         if (bProgName)
107         {
108             static const NameToIdHash s_aProgMap(initFunc(true));
109             return s_aProgMap;
110         }
111 
112         SvtSysLocale aSysLocale;
113         const LanguageTag& rCurrentLanguage = aSysLocale.GetUILanguageTag();
114         static std::map<LanguageTag, NameToIdHash> s_aUIMap;
115 
116         auto it = s_aUIMap.find(rCurrentLanguage);
117         if (it == s_aUIMap.end())
118             it = s_aUIMap.emplace(rCurrentLanguage, initFunc(false)).first;
119 
120         return it->second;
121     }
122 };
123 
GetParaMap(bool bProgName)124 NameToIdHash GetParaMap (bool bProgName)
125 {
126     return HashFromRange(0,
127         RES_POOLCOLL_TEXT_BEGIN, RES_POOLCOLL_TEXT_END, bProgName ? &SwStyleNameMapper::GetTextProgNameArray : &SwStyleNameMapper::GetTextUINameArray,
128         RES_POOLCOLL_LISTS_BEGIN, RES_POOLCOLL_LISTS_END, bProgName ? &SwStyleNameMapper::GetListsProgNameArray : &SwStyleNameMapper::GetListsUINameArray,
129         RES_POOLCOLL_EXTRA_BEGIN, RES_POOLCOLL_EXTRA_END, bProgName ? &SwStyleNameMapper::GetExtraProgNameArray : &SwStyleNameMapper::GetExtraUINameArray,
130         RES_POOLCOLL_REGISTER_BEGIN, RES_POOLCOLL_REGISTER_END, bProgName ? &SwStyleNameMapper::GetRegisterProgNameArray : &SwStyleNameMapper::GetRegisterUINameArray,
131         RES_POOLCOLL_DOC_BEGIN, RES_POOLCOLL_DOC_END, bProgName ? &SwStyleNameMapper::GetDocProgNameArray : &SwStyleNameMapper::GetDocUINameArray,
132         RES_POOLCOLL_HTML_BEGIN, RES_POOLCOLL_HTML_END, bProgName ? &SwStyleNameMapper::GetHTMLProgNameArray : &SwStyleNameMapper::GetHTMLUINameArray
133     );
134 };
135 
GetCharMap(bool bProgName)136 NameToIdHash GetCharMap(bool bProgName)
137 {
138     return HashFromRange(0,
139         RES_POOLCHR_NORMAL_BEGIN, RES_POOLCHR_NORMAL_END, bProgName ? &SwStyleNameMapper::GetChrFormatProgNameArray : &SwStyleNameMapper::GetChrFormatUINameArray,
140         RES_POOLCHR_HTML_BEGIN, RES_POOLCHR_HTML_END, bProgName ? &SwStyleNameMapper::GetHTMLChrFormatProgNameArray : &SwStyleNameMapper::GetHTMLChrFormatUINameArray
141     );
142 };
143 
GetFrameMap(bool bProgName)144 NameToIdHash GetFrameMap(bool bProgName)
145 {
146     return HashFromRange(0,
147         RES_POOLFRM_BEGIN, RES_POOLFRM_END, bProgName ? &SwStyleNameMapper::GetFrameFormatProgNameArray : &SwStyleNameMapper::GetFrameFormatUINameArray
148     );
149 };
150 
GetPageMap(bool bProgName)151 NameToIdHash GetPageMap(bool bProgName)
152 {
153     return HashFromRange(0,
154         RES_POOLPAGE_BEGIN, RES_POOLPAGE_END, bProgName ? &SwStyleNameMapper::GetPageDescProgNameArray : &SwStyleNameMapper::GetPageDescUINameArray
155     );
156 };
157 
GetNumRuleMap(bool bProgName)158 NameToIdHash GetNumRuleMap(bool bProgName)
159 {
160     return HashFromRange(0,
161         RES_POOLNUMRULE_BEGIN, RES_POOLNUMRULE_END, bProgName ? &SwStyleNameMapper::GetNumRuleProgNameArray : &SwStyleNameMapper::GetNumRuleUINameArray
162     );
163 };
164 
GetTableStyleMap(bool bProgName)165 NameToIdHash GetTableStyleMap(bool bProgName)
166 {
167     return HashFromRange(0,
168         RES_POOLTABLESTYLE_BEGIN, RES_POOLTABLESTYLE_END, bProgName ? &SwStyleNameMapper::GetTableStyleProgNameArray : &SwStyleNameMapper::GetTableStyleUINameArray
169     );
170 };
171 
GetCellStyleMap(bool bProgName)172 NameToIdHash GetCellStyleMap(bool bProgName)
173 {
174     return HashFromRange(0,
175         RES_POOLCELLSTYLE_BEGIN, RES_POOLCELLSTYLE_END, bProgName ? &SwStyleNameMapper::GetCellStyleProgNameArray : &SwStyleNameMapper::GetCellStyleUINameArray
176     );
177 };
178 
179 } // namespace
180 
181 #ifdef _NEED_TO_DEBUG_MAPPING
testNameTable(SwGetPoolIdFromName const nFamily,sal_uInt16 const nStartIndex,sal_uInt16 const nEndIndex)182 void SwStyleNameMapper::testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex )
183 {
184     sal_uInt16 nIndex;
185     sal_uInt16 nId;
186 
187     for ( nIndex = 0, nId = nStartIndex ; nId < nEndIndex ; nId++,nIndex++ )
188     {
189         OUString aString, bString;
190         FillUIName ( nId, aString );
191         bString = GetProgName ( nFamily, aString );
192         sal_uInt16 nNewId = GetPoolIdFromProgName ( bString, nFamily );
193         FillProgName ( nNewId, aString );
194         bString = GetUIName ( aString, nFamily );
195         nNewId = GetPoolIdFromUIName ( aString, nFamily );
196         if ( nNewId != nId )
197             abort();
198     }
199 }
200 #endif
201 
getHashTable(SwGetPoolIdFromName eFlags,bool bProgName)202 const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlags, bool bProgName )
203 {
204 #ifdef _NEED_TO_DEBUG_MAPPING
205     static bool bTested = false;
206     if ( !bTested )
207     {
208         bTested = true;
209 
210         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_TEXT_BEGIN, RES_POOLCOLL_TEXT_END );
211         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_LISTS_BEGIN, RES_POOLCOLL_LISTS_END );
212         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_EXTRA_BEGIN, RES_POOLCOLL_EXTRA_END );
213         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_REGISTER_BEGIN, RES_POOLCOLL_REGISTER_END );
214         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_DOC_BEGIN, RES_POOLCOLL_DOC_END );
215         testNameTable( SwGetPoolIdFromName::TxtColl, RES_POOLCOLL_HTML_BEGIN, RES_POOLCOLL_HTML_END );
216         testNameTable( SwGetPoolIdFromName::ChrFmt, RES_POOLCHR_NORMAL_BEGIN, RES_POOLCHR_NORMAL_END );
217         testNameTable( SwGetPoolIdFromName::ChrFmt, RES_POOLCHR_HTML_BEGIN, RES_POOLCHR_HTML_END );
218         testNameTable( SwGetPoolIdFromName::FrmFmt, RES_POOLFRM_BEGIN, RES_POOLFRM_END );
219         testNameTable( SwGetPoolIdFromName::PageDesc, RES_POOLPAGE_BEGIN, RES_POOLPAGE_END );
220         testNameTable( SwGetPoolIdFromName::NumRule, RES_POOLNUMRULE_BEGIN, RES_POOLNUMRULE_END );
221     }
222 #endif
223 
224     switch ( eFlags )
225     {
226         case SwGetPoolIdFromName::TxtColl:
227             return TablePair<GetParaMap>::getMap(bProgName);
228         case SwGetPoolIdFromName::ChrFmt:
229             return TablePair<GetCharMap>::getMap(bProgName);
230         case SwGetPoolIdFromName::FrmFmt:
231             return TablePair<GetFrameMap>::getMap(bProgName);
232         case SwGetPoolIdFromName::PageDesc:
233             return TablePair<GetPageMap>::getMap(bProgName);
234         case SwGetPoolIdFromName::NumRule:
235             return TablePair<GetNumRuleMap>::getMap(bProgName);
236         case SwGetPoolIdFromName::TableStyle:
237             return TablePair<GetTableStyleMap>::getMap(bProgName);
238         case SwGetPoolIdFromName::CellStyle:
239             return TablePair<GetCellStyleMap>::getMap(bProgName);
240     }
241 
242     assert(false); // must not reach here
243     abort();
244 }
245 
246 // This gets the UI name from the programmatic name
GetUIName(const ProgName & rName,SwGetPoolIdFromName const eFlags)247 UIName SwStyleNameMapper::GetUIName(const ProgName& rName,
248                                              SwGetPoolIdFromName const eFlags)
249 {
250     sal_uInt16 nId = GetPoolIdFromProgName ( rName, eFlags );
251     return nId != USHRT_MAX ? GetUIName( nId, rName ) : UIName(rName.toString());
252 }
253 
254 // Get the programmatic name from the UI name
GetProgName(const UIName & rName,SwGetPoolIdFromName const eFlags)255 ProgName SwStyleNameMapper::GetProgName(
256         const UIName& rName, SwGetPoolIdFromName const eFlags)
257 {
258     sal_uInt16 nId = GetPoolIdFromUIName ( rName, eFlags );
259     return nId != USHRT_MAX ? GetProgName( nId, rName ) : ProgName(rName.toString());
260 }
261 
262 // Get the programmatic name from the UI name in rName and put it into rFillName
FillProgName(const UIName & rName,ProgName & rFillName,SwGetPoolIdFromName const eFlags)263 void SwStyleNameMapper::FillProgName(
264         const UIName& rName, ProgName& rFillName,
265         SwGetPoolIdFromName const eFlags)
266 {
267     sal_uInt16 nId = GetPoolIdFromUIName ( rName, eFlags );
268     if ( nId == USHRT_MAX )
269     {
270         // rName isn't in our UI name table...check if it's in the programmatic one
271         nId = GetPoolIdFromProgName ( ProgName(rName.toString()), eFlags );
272 
273         rFillName = ProgName(rName.toString());
274         if (nId == USHRT_MAX )
275         {
276             if (eFlags != SwGetPoolIdFromName::TableStyle)
277             {
278                 // check if it has a " (user)" suffix, if so remove it
279                 lcl_CheckSuffixAndDelete(rFillName);
280             }
281             else // FIXME don't do this
282             {
283                 // It isn't ...make sure the suffix isn't already " (user)"...if it is,
284                 // we need to add another one
285                 if (lcl_SuffixIsUser(rFillName.toString()))
286                     rFillName = ProgName(rFillName.toString() + " (user)");
287             }
288         }
289         else
290         {
291             // It's in the programmatic name table...append suffix
292             rFillName = ProgName(rFillName.toString() + " (user)");
293         }
294     }
295     else
296     {
297         // If we aren't trying to disambiguate, then just do a normal fill
298         fillProgNameFromId(nId, rFillName);
299     }
300 
301     if (eFlags == SwGetPoolIdFromName::ChrFmt && rName.toString() == SwResId(STR_POOLCHR_STANDARD))
302         rFillName = ProgName("Standard");
303 }
304 
305 // Get the UI name from the programmatic name in rName and put it into rFillName
FillUIName(const ProgName & rName,UIName & rFillName,SwGetPoolIdFromName const eFlags)306 void SwStyleNameMapper::FillUIName(
307         const ProgName& rName, UIName& rFillName,
308         SwGetPoolIdFromName const eFlags)
309 {
310     ProgName aName = rName;
311     if (eFlags == SwGetPoolIdFromName::ChrFmt && rName == "Standard")
312         aName = ProgName(SwResId(STR_POOLCHR_STANDARD));
313 
314     sal_uInt16 nId = GetPoolIdFromProgName ( aName, eFlags );
315     if ( nId == USHRT_MAX )
316     {
317         rFillName = UIName(aName.toString());
318         // TabStyle: unfortunately ODF documents with UIName table styles exist
319         if (eFlags == SwGetPoolIdFromName::TableStyle || // see testTdf129568ui
320             GetPoolIdFromUIName(UIName(aName.toString()), eFlags) == USHRT_MAX)
321         {
322             // aName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
323             lcl_CheckSuffixAndDelete(rFillName);
324         }
325         else
326         {
327             rFillName = UIName(rFillName.toString() + " (user)");
328         }
329     }
330     else
331     {
332         // If we aren't trying to disambiguate, then just do a normal fill
333         fillUINameFromId(nId, rFillName);
334     }
335 }
336 
getNameFromId(sal_uInt16 const nId,const OUString & rFillName,bool const bProgName)337 const OUString& SwStyleNameMapper::getNameFromId(
338         sal_uInt16 const nId, const OUString& rFillName, bool const bProgName)
339 {
340     sal_uInt16 nStt = 0;
341     const std::vector<OUString>* pStrArr = nullptr;
342 
343     switch( (USER_FMT | COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID) & nId )
344     {
345     case COLL_TEXT_BITS:
346         if( RES_POOLCOLL_TEXT_BEGIN <= nId && nId < RES_POOLCOLL_TEXT_END )
347         {
348             pStrArr = bProgName ? &GetTextProgNameArray() : &GetTextUINameArray();
349             nStt = RES_POOLCOLL_TEXT_BEGIN;
350         }
351         break;
352     case COLL_LISTS_BITS:
353         if( RES_POOLCOLL_LISTS_BEGIN <= nId && nId < RES_POOLCOLL_LISTS_END )
354         {
355             pStrArr = bProgName ? &GetListsProgNameArray() : &GetListsUINameArray();
356             nStt = RES_POOLCOLL_LISTS_BEGIN;
357         }
358         break;
359     case COLL_EXTRA_BITS:
360         if( RES_POOLCOLL_EXTRA_BEGIN <= nId && nId < RES_POOLCOLL_EXTRA_END )
361         {
362             pStrArr = bProgName ? &GetExtraProgNameArray() : &GetExtraUINameArray();
363             nStt = RES_POOLCOLL_EXTRA_BEGIN;
364         }
365         break;
366     case COLL_REGISTER_BITS:
367         if( RES_POOLCOLL_REGISTER_BEGIN <= nId && nId < RES_POOLCOLL_REGISTER_END )
368         {
369             pStrArr = bProgName ? &GetRegisterProgNameArray() : &GetRegisterUINameArray();
370             nStt = RES_POOLCOLL_REGISTER_BEGIN;
371         }
372         break;
373     case COLL_DOC_BITS:
374         if( RES_POOLCOLL_DOC_BEGIN <= nId && nId < RES_POOLCOLL_DOC_END )
375         {
376             pStrArr = bProgName ? &GetDocProgNameArray() : &GetDocUINameArray();
377             nStt = RES_POOLCOLL_DOC_BEGIN;
378         }
379         break;
380     case COLL_HTML_BITS:
381         if( RES_POOLCOLL_HTML_BEGIN <= nId && nId < RES_POOLCOLL_HTML_END )
382         {
383             pStrArr = bProgName ? &GetHTMLProgNameArray() : &GetHTMLUINameArray();
384             nStt = RES_POOLCOLL_HTML_BEGIN;
385         }
386         break;
387     case POOLGRP_CHARFMT:
388         if( RES_POOLCHR_NORMAL_BEGIN <= nId && nId < RES_POOLCHR_NORMAL_END )
389         {
390             pStrArr = bProgName ? &GetChrFormatProgNameArray() : &GetChrFormatUINameArray();
391             nStt = RES_POOLCHR_NORMAL_BEGIN;
392         }
393         else if( RES_POOLCHR_HTML_BEGIN <= nId && nId < RES_POOLCHR_HTML_END )
394         {
395             pStrArr = bProgName ? &GetHTMLChrFormatProgNameArray() : &GetHTMLChrFormatUINameArray();
396             nStt = RES_POOLCHR_HTML_BEGIN;
397         }
398         break;
399     case POOLGRP_FRAMEFMT:
400         if( RES_POOLFRM_BEGIN <= nId && nId < RES_POOLFRM_END )
401         {
402             pStrArr = bProgName ? &GetFrameFormatProgNameArray() : &GetFrameFormatUINameArray();
403             nStt = RES_POOLFRM_BEGIN;
404         }
405         break;
406     case POOLGRP_PAGEDESC:
407         if( RES_POOLPAGE_BEGIN <= nId && nId < RES_POOLPAGE_END )
408         {
409             pStrArr = bProgName ? &GetPageDescProgNameArray() : &GetPageDescUINameArray();
410             nStt = RES_POOLPAGE_BEGIN;
411         }
412         break;
413     case POOLGRP_NUMRULE:
414         if( RES_POOLNUMRULE_BEGIN <= nId && nId < RES_POOLNUMRULE_END )
415         {
416             pStrArr = bProgName ? &GetNumRuleProgNameArray() : &GetNumRuleUINameArray();
417             nStt = RES_POOLNUMRULE_BEGIN;
418         }
419         break;
420     case POOLGRP_TABSTYLE:
421         if( RES_POOLTABLESTYLE_BEGIN <= nId && nId < RES_POOLTABLESTYLE_END )
422         {
423             pStrArr = bProgName ? &GetTableStyleProgNameArray() : &GetTableStyleUINameArray();
424             nStt = RES_POOLTABLESTYLE_BEGIN;
425         }
426         break;
427     }
428     return pStrArr ? pStrArr->operator[](nId - nStt) : rFillName;
429 }
430 
fillUINameFromId(sal_uInt16 const nId,UIName & rFillName)431 void SwStyleNameMapper::fillUINameFromId(
432         sal_uInt16 const nId, UIName& rFillName)
433 {
434     rFillName = UIName(getNameFromId(nId, rFillName.toString(), /*bProgName*/false));
435 }
436 
fillProgNameFromId(sal_uInt16 const nId,ProgName & rFillName)437 void SwStyleNameMapper::fillProgNameFromId(
438         sal_uInt16 const nId, ProgName& rFillName)
439 {
440     rFillName = ProgName(getNameFromId(nId, rFillName.toString(), /*bProgName*/true));
441 }
442 
443 // Get the UI name from the pool ID
FillUIName(sal_uInt16 const nId,UIName & rFillName)444 void SwStyleNameMapper::FillUIName(sal_uInt16 const nId, UIName& rFillName)
445 {
446     fillUINameFromId(nId, rFillName);
447 }
448 
449 // Get the UI name from the pool ID
GetUIName(sal_uInt16 const nId,const ProgName & rName)450 UIName SwStyleNameMapper::GetUIName(
451         sal_uInt16 const nId, const ProgName& rName)
452 {
453     return UIName(getNameFromId(nId, rName.toString(), false));
454 }
455 
456 // Get the programmatic name from the pool ID
FillProgName(sal_uInt16 nId,ProgName & rFillName)457 void SwStyleNameMapper::FillProgName(sal_uInt16 nId, ProgName& rFillName)
458 {
459     fillProgNameFromId(nId, rFillName);
460 }
461 
462 // Get the programmatic name from the pool ID
463 ProgName
GetProgName(sal_uInt16 const nId,const UIName & rName)464 SwStyleNameMapper::GetProgName(sal_uInt16 const nId, const UIName& rName)
465 {
466     return ProgName(getNameFromId(nId, rName.toString(), true));
467 }
468 
469 // This gets the PoolId from the UI Name
GetPoolIdFromUIName(const UIName & rName,SwGetPoolIdFromName const eFlags)470 sal_uInt16 SwStyleNameMapper::GetPoolIdFromUIName(
471         const UIName& rName, SwGetPoolIdFromName const eFlags)
472 {
473     const NameToIdHash & rHashMap = getHashTable ( eFlags, false );
474     NameToIdHash::const_iterator aIter = rHashMap.find(rName.toString());
475     return aIter != rHashMap.end() ? (*aIter).second : USHRT_MAX;
476 }
477 
478 // Get the Pool ID from the programmatic name
GetPoolIdFromProgName(const ProgName & rName,SwGetPoolIdFromName const eFlags)479 sal_uInt16 SwStyleNameMapper::GetPoolIdFromProgName(
480             const ProgName& rName, SwGetPoolIdFromName const eFlags)
481 {
482     const NameToIdHash & rHashMap = getHashTable ( eFlags, true );
483     NameToIdHash::const_iterator aIter = rHashMap.find(rName.toString());
484     return aIter != rHashMap.end() ? (*aIter).second : USHRT_MAX;
485 }
486 
487 // Hard coded Programmatic Name tables
488 
489 /// returns an empty array because Cell Names aren't translated
GetCellStyleUINameArray()490 const std::vector<OUString>& SwStyleNameMapper::GetCellStyleUINameArray()
491 {
492     static const std::vector<OUString> s_aCellStyleUINameArray;
493     return s_aCellStyleUINameArray;
494 }
495 
GetTextProgNameArray()496 const std::vector<OUString>& SwStyleNameMapper::GetTextProgNameArray()
497 {
498     static const std::vector<OUString> s_aTextProgNameArray = {
499         u"Standard"_ustr, // RES_POOLCOLL_STANDARD
500         u"Text body"_ustr,
501         u"First line indent"_ustr,
502         u"Hanging indent"_ustr,
503         u"Text body indent"_ustr,
504         u"Salutation"_ustr,
505         u"Signature"_ustr,
506         u"List Indent"_ustr, // RES_POOLCOLL_CONFRONTATION
507         u"Marginalia"_ustr,
508         // RES_POOLCOLL_TEXT_END
509     };
510     return s_aTextProgNameArray;
511 }
512 
GetListsProgNameArray()513 const std::vector<OUString>& SwStyleNameMapper::GetListsProgNameArray()
514 {
515     static const std::vector<OUString> s_aListsProgNameArray = {
516         u"List"_ustr, // STR_POCO_PRGM_NUMBER_BULLET_BASE
517         u"Numbering 1 Start"_ustr, // STR_POCO_PRGM_NUM_LEVEL1S
518         u"Numbering 1"_ustr,
519         u"Numbering 1 End"_ustr,
520         u"Numbering 1 Cont."_ustr,
521         u"Numbering 2 Start"_ustr,
522         u"Numbering 2"_ustr,
523         u"Numbering 2 End"_ustr,
524         u"Numbering 2 Cont."_ustr,
525         u"Numbering 3 Start"_ustr,
526         u"Numbering 3"_ustr,
527         u"Numbering 3 End"_ustr,
528         u"Numbering 3 Cont."_ustr,
529         u"Numbering 4 Start"_ustr,
530         u"Numbering 4"_ustr,
531         u"Numbering 4 End"_ustr,
532         u"Numbering 4 Cont."_ustr,
533         u"Numbering 5 Start"_ustr,
534         u"Numbering 5"_ustr,
535         u"Numbering 5 End"_ustr,
536         u"Numbering 5 Cont."_ustr,
537         u"List 1 Start"_ustr,
538         u"List 1"_ustr,
539         u"List 1 End"_ustr,
540         u"List 1 Cont."_ustr,
541         u"List 2 Start"_ustr,
542         u"List 2"_ustr,
543         u"List 2 End"_ustr,
544         u"List 2 Cont."_ustr,
545         u"List 3 Start"_ustr,
546         u"List 3"_ustr,
547         u"List 3 End"_ustr,
548         u"List 3 Cont."_ustr,
549         u"List 4 Start"_ustr,
550         u"List 4"_ustr,
551         u"List 4 End"_ustr,
552         u"List 4 Cont."_ustr,
553         u"List 5 Start"_ustr,
554         u"List 5"_ustr,
555         u"List 5 End"_ustr,
556         u"List 5 Cont."_ustr, // STR_POCO_PRGM_BULLET_NONUM5
557     };
558     return s_aListsProgNameArray;
559 }
560 
GetExtraProgNameArray()561 const std::vector<OUString>& SwStyleNameMapper::GetExtraProgNameArray()
562 {
563     static const std::vector<OUString> s_aExtraProgNameArray = {
564         u"Header and Footer"_ustr, // RES_POOLCOLL_EXTRA_BEGIN
565         u"Header"_ustr,
566         u"Header left"_ustr,
567         u"Header right"_ustr,
568         u"Footer"_ustr,
569         u"Footer left"_ustr,
570         u"Footer right"_ustr,
571         u"Table Contents"_ustr,
572         u"Table Heading"_ustr,
573         u"Caption"_ustr,
574         u"Illustration"_ustr,
575         u"Table"_ustr,
576         u"Text"_ustr,
577         u"Figure"_ustr, // RES_POOLCOLL_LABEL_FIGURE
578         u"Frame contents"_ustr,
579         u"Footnote"_ustr,
580         u"Addressee"_ustr,
581         u"Sender"_ustr,
582         u"Endnote"_ustr,
583         u"Drawing"_ustr,
584         u"Comment"_ustr, // RES_POOLCOLL_COMMENT
585     };
586     return s_aExtraProgNameArray;
587 }
588 
GetRegisterProgNameArray()589 const std::vector<OUString>& SwStyleNameMapper::GetRegisterProgNameArray()
590 {
591     static const std::vector<OUString> s_aRegisterProgNameArray = {
592         u"Index"_ustr, // STR_POCO_PRGM_REGISTER_BASE
593         u"Index Heading"_ustr, // STR_POCO_PRGM_TOX_IDXH
594         u"Index 1"_ustr,
595         u"Index 2"_ustr,
596         u"Index 3"_ustr,
597         u"Index Separator"_ustr,
598         u"Contents Heading"_ustr,
599         u"Contents 1"_ustr,
600         u"Contents 2"_ustr,
601         u"Contents 3"_ustr,
602         u"Contents 4"_ustr,
603         u"Contents 5"_ustr,
604         u"User Index Heading"_ustr,
605         u"User Index 1"_ustr,
606         u"User Index 2"_ustr,
607         u"User Index 3"_ustr,
608         u"User Index 4"_ustr,
609         u"User Index 5"_ustr,
610         u"Contents 6"_ustr,
611         u"Contents 7"_ustr,
612         u"Contents 8"_ustr,
613         u"Contents 9"_ustr,
614         u"Contents 10"_ustr,
615         u"Figure Index Heading"_ustr,
616         u"Figure Index 1"_ustr,
617         u"Object index heading"_ustr,
618         u"Object index 1"_ustr,
619         u"Table index heading"_ustr,
620         u"Table index 1"_ustr,
621         u"Bibliography Heading"_ustr,
622         u"Bibliography 1"_ustr,
623         u"User Index 6"_ustr,
624         u"User Index 7"_ustr,
625         u"User Index 8"_ustr,
626         u"User Index 9"_ustr,
627         u"User Index 10"_ustr, // STR_POCO_PRGM_TOX_USER10
628     };
629     return s_aRegisterProgNameArray;
630 }
631 
GetDocProgNameArray()632 const std::vector<OUString>& SwStyleNameMapper::GetDocProgNameArray()
633 {
634     static const std::vector<OUString> s_aDocProgNameArray = {
635         u"Title"_ustr, // STR_POCO_PRGM_DOC_TITLE
636         u"Subtitle"_ustr,
637         u"Appendix"_ustr,
638         u"Heading"_ustr,
639         u"Heading 1"_ustr,
640         u"Heading 2"_ustr,
641         u"Heading 3"_ustr,
642         u"Heading 4"_ustr,
643         u"Heading 5"_ustr,
644         u"Heading 6"_ustr,
645         u"Heading 7"_ustr,
646         u"Heading 8"_ustr,
647         u"Heading 9"_ustr,
648         u"Heading 10"_ustr,
649         // RES_POOLCOLL_DOC_END
650     };
651     return s_aDocProgNameArray;
652 }
653 
GetHTMLProgNameArray()654 const std::vector<OUString>& SwStyleNameMapper::GetHTMLProgNameArray()
655 {
656     static const std::vector<OUString> s_aHTMLProgNameArray = {
657         u"Quotations"_ustr,
658         u"Preformatted Text"_ustr,
659         u"Horizontal Line"_ustr,
660         u"List Contents"_ustr,
661         u"List Heading"_ustr, // STR_POCO_PRGM_HTML_DT
662     };
663     return s_aHTMLProgNameArray;
664 }
665 
GetFrameFormatProgNameArray()666 const std::vector<OUString>& SwStyleNameMapper::GetFrameFormatProgNameArray()
667 {
668     static const std::vector<OUString> s_aFrameFormatProgNameArray = {
669         u"Frame"_ustr, // RES_POOLFRM_FRAME
670         u"Graphics"_ustr,
671         u"OLE"_ustr,
672         u"Formula"_ustr,
673         u"Marginalia"_ustr,
674         u"Watermark"_ustr,
675         u"Labels"_ustr, // RES_POOLFRM_LABEL
676         u"Inline Heading"_ustr,
677     };
678     return s_aFrameFormatProgNameArray;
679 }
680 
GetChrFormatProgNameArray()681 const std::vector<OUString>& SwStyleNameMapper::GetChrFormatProgNameArray()
682 {
683     static const std::vector<OUString> s_aChrFormatProgNameArray = {
684         u"Footnote Symbol"_ustr, // RES_POOLCHR_FOOTNOTE
685         u"Page Number"_ustr,
686         u"Caption characters"_ustr,
687         u"Drop Caps"_ustr,
688         u"Numbering Symbols"_ustr,
689         u"Bullet Symbols"_ustr,
690         u"Internet link"_ustr,
691         u"Visited Internet Link"_ustr,
692         u"Placeholder"_ustr,
693         u"Index Link"_ustr,
694         u"Endnote Symbol"_ustr,
695         u"Line numbering"_ustr,
696         u"Main index entry"_ustr,
697         u"Footnote anchor"_ustr,
698         u"Endnote anchor"_ustr,
699         u"Rubies"_ustr, // RES_POOLCHR_RUBYTEXT
700         u"Vertical Numbering Symbols"_ustr, // RES_POOLCHR_VERT_NUMBER
701     };
702     return s_aChrFormatProgNameArray;
703 }
704 
GetHTMLChrFormatProgNameArray()705 const std::vector<OUString>& SwStyleNameMapper::GetHTMLChrFormatProgNameArray()
706 {
707     static const std::vector<OUString> s_aHTMLChrFormatProgNameArray = {
708         u"Emphasis"_ustr, // RES_POOLCHR_HTML_EMPHASIS
709         u"Citation"_ustr,
710         u"Strong Emphasis"_ustr,
711         u"Source Text"_ustr,
712         u"Example"_ustr,
713         u"User Entry"_ustr,
714         u"Variable"_ustr,
715         u"Definition"_ustr,
716         u"Teletype"_ustr, // RES_POOLCHR_HTML_TELETYPE
717     };
718     return s_aHTMLChrFormatProgNameArray;
719 }
720 
GetPageDescProgNameArray()721 const std::vector<OUString>& SwStyleNameMapper::GetPageDescProgNameArray()
722 {
723     static const std::vector<OUString> s_aPageDescProgNameArray = {
724         u"Standard"_ustr, // STR_POOLPAGE_PRGM_STANDARD
725         u"First Page"_ustr,
726         u"Left Page"_ustr,
727         u"Right Page"_ustr,
728         u"Envelope"_ustr,
729         u"Index"_ustr,
730         u"HTML"_ustr,
731         u"Footnote"_ustr,
732         u"Endnote"_ustr, // STR_POOLPAGE_PRGM_ENDNOTE
733         u"Landscape"_ustr,
734     };
735     return s_aPageDescProgNameArray;
736 }
737 
GetNumRuleProgNameArray()738 const std::vector<OUString>& SwStyleNameMapper::GetNumRuleProgNameArray()
739 {
740     static const std::vector<OUString> s_aNumRuleProgNameArray = {
741         u"No List"_ustr,
742         u"Numbering 123"_ustr, // STR_POOLNUMRULE_PRGM_NUM1
743         u"Numbering ABC"_ustr,
744         u"Numbering abc"_ustr,
745         u"Numbering IVX"_ustr,
746         u"Numbering ivx"_ustr,
747         u"List 1"_ustr,
748         u"List 2"_ustr,
749         u"List 3"_ustr,
750         u"List 4"_ustr,
751         u"List 5"_ustr, // STR_POOLNUMRULE_PRGM_BUL5
752     };
753     return s_aNumRuleProgNameArray;
754 }
755 
GetTableStyleProgNameArray()756 const std::vector<OUString>& SwStyleNameMapper::GetTableStyleProgNameArray()
757 {
758     // XXX MUST match the entries of STR_TABSTYLE_ARY in
759     // sw/source/core/doc/DocumentStylePoolManager.cxx and MUST match the order of
760     // RES_POOL_TABLESTYLE_TYPE in sw/inc/poolfmt.hxx
761     static const std::vector<OUString> s_aTableStyleProgNameArray = {
762         u"Default Style"_ustr,       // RES_POOLTABLESTYLE_DEFAULT
763         u"3D"_ustr,                  // RES_POOLTABLESTYLE_3D
764         u"Black 1"_ustr,             // RES_POOLTABLESTYLE_BLACK1
765         u"Black 2"_ustr,             // RES_POOLTABLESTYLE_BLACK2
766         u"Blue"_ustr,                // RES_POOLTABLESTYLE_BLUE
767         u"Brown"_ustr,               // RES_POOLTABLESTYLE_BROWN
768         u"Currency"_ustr,            // RES_POOLTABLESTYLE_CURRENCY
769         u"Currency 3D"_ustr,         // RES_POOLTABLESTYLE_CURRENCY_3D
770         u"Currency Gray"_ustr,       // RES_POOLTABLESTYLE_CURRENCY_GRAY
771         u"Currency Lavender"_ustr,   // RES_POOLTABLESTYLE_CURRENCY_LAVENDER
772         u"Currency Turquoise"_ustr,  // RES_POOLTABLESTYLE_CURRENCY_TURQUOISE
773         u"Gray"_ustr,                // RES_POOLTABLESTYLE_GRAY
774         u"Green"_ustr,               // RES_POOLTABLESTYLE_GREEN
775         u"Lavender"_ustr,            // RES_POOLTABLESTYLE_LAVENDER
776         u"Red"_ustr,                 // RES_POOLTABLESTYLE_RED
777         u"Turquoise"_ustr,           // RES_POOLTABLESTYLE_TURQUOISE
778         u"Yellow"_ustr,              // RES_POOLTABLESTYLE_YELLOW
779         u"Academic"_ustr,            // RES_POOLTABLESTYLE_LO6_ACADEMIC
780         u"Box List Blue"_ustr,       // RES_POOLTABLESTYLE_LO6_BOX_LIST_BLUE
781         u"Box List Green"_ustr,      // RES_POOLTABLESTYLE_LO6_BOX_LIST_GREEN
782         u"Box List Red"_ustr,        // RES_POOLTABLESTYLE_LO6_BOX_LIST_RED
783         u"Box List Yellow"_ustr,     // RES_POOLTABLESTYLE_LO6_BOX_LIST_YELLOW
784         u"Elegant"_ustr,             // RES_POOLTABLESTYLE_LO6_ELEGANT
785         u"Financial"_ustr,           // RES_POOLTABLESTYLE_LO6_FINANCIAL
786         u"Simple Grid Columns"_ustr, // RES_POOLTABLESTYLE_LO6_SIMPLE_GRID_COLUMNS
787         u"Simple Grid Rows"_ustr,    // RES_POOLTABLESTYLE_LO6_SIMPLE_GRID_ROWS
788         u"Simple List Shaded"_ustr,  // RES_POOLTABLESTYLE_LO6_SIMPLE_LIST_SHADED
789     };
790     return s_aTableStyleProgNameArray;
791 }
792 
793 /// returns an empty array because Cell Names aren't translated
GetCellStyleProgNameArray()794 const std::vector<OUString>& SwStyleNameMapper::GetCellStyleProgNameArray()
795 {
796     static const std::vector<OUString> s_aCellStyleProgNameArray;
797     return s_aCellStyleProgNameArray;
798 }
799 
800 ProgName
GetSpecialExtraProgName(const UIName & rExtraUIName)801 SwStyleNameMapper::GetSpecialExtraProgName(const UIName& rExtraUIName)
802 {
803     return ProgName(lcl_GetSpecialExtraName( rExtraUIName.toString(), true ));
804 }
805 
806 UIName
GetSpecialExtraUIName(const ProgName & rExtraProgName)807 SwStyleNameMapper::GetSpecialExtraUIName(const ProgName& rExtraProgName)
808 {
809     return UIName(lcl_GetSpecialExtraName( rExtraProgName.toString(), false ));
810 }
811 
812 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
813