Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / SwStyleNameMapper.hxx
blob9b120d8314b3e0454ea153a93081ad0637a316f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_SWSTYLENAMEMAPPER_HXX
20 #define INCLUDED_SW_INC_SWSTYLENAMEMAPPER_HXX
22 #include <sal/types.h>
23 #include <rtl/ustring.hxx>
24 #include <SwGetPoolIdFromName.hxx>
25 #include "swdllapi.h"
27 #include <unordered_map>
28 #include <vector>
30 /** This class holds all data about the names of styles used in the user
31 * interface (UI names...these are localised into different languages).
32 * These UI names are loaded from the resource files on demand.
34 * It also holds all information about the 'Programmatic' names of styles
35 * which remain static (and are hardcoded in the corresponding cxx file)
36 * for all languages.
38 * This class also provides static functions which can be used for the
39 * following conversions:
41 * 1. Programmatic Name -> UI Name
42 * 2. Programmatic Name -> Pool ID
43 * 3. UI Name -> Programmatic Name
44 * 4. UI Name -> Pool ID
45 * 5. Pool ID -> UI Name
46 * 6. Pool ID -> Programmatic Name
48 * The relationship of these tables to the style families is as follows:
50 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
51 * name arrays.
52 * 2. Character contains the ChrFormat and HTMLChrFormat name arrays.
53 * 3. Page contains the PageDesc name array.
54 * 4. Frame contains the FrameFormat name array.
55 * 5. Numbering Rule contains the NumRule name array.
58 /**
59 * There is a further complication that came to light later. If someone enters
60 * a user-defined style name which is the same as a programmatic name, this
61 * name clash must be handled.
63 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
64 * must be set to true in the SwStyleNameMapper call (it defaults to false).
65 * This will cause the following to happen:
67 * If the UI style name either equals a programmatic name or already ends
68 * with " (user)", then it must append " (user)" to the end.
70 * When a programmatic name is being converted to a UI name, if it ends in
71 * " (user)", we simply remove it.
74 struct SwTableEntry;
76 typedef std::unordered_map<OUString, sal_uInt16, OUStringHash> NameToIdHash;
78 class SwStyleNameMapper
80 friend void InitCore();
81 friend void FinitCore();
83 protected:
84 // UI Name tables
85 static std::vector<OUString> *s_pTextUINameArray,
86 *s_pListsUINameArray,
87 *s_pExtraUINameArray,
88 *s_pRegisterUINameArray,
89 *s_pDocUINameArray,
90 *s_pHTMLUINameArray,
91 *s_pFrameFormatUINameArray,
92 *s_pChrFormatUINameArray,
93 *s_pHTMLChrFormatUINameArray,
94 *s_pPageDescUINameArray,
95 *s_pNumRuleUINameArray,
96 *s_pTableStyleUINameArray,
97 *s_pCellStyleUINameArray,
98 // Programmatic Name tables
99 *s_pTextProgNameArray,
100 *s_pListsProgNameArray,
101 *s_pExtraProgNameArray,
102 *s_pRegisterProgNameArray,
103 *s_pDocProgNameArray,
104 *s_pHTMLProgNameArray,
105 *s_pFrameFormatProgNameArray,
106 *s_pChrFormatProgNameArray,
107 *s_pHTMLChrFormatProgNameArray,
108 *s_pPageDescProgNameArray,
109 *s_pNumRuleProgNameArray,
110 *s_pTableStyleProgNameArray,
111 *s_pCellStyleProgNameArray;
113 static NameToIdHash *s_pParaUIMap,
114 *s_pCharUIMap,
115 *s_pPageUIMap,
116 *s_pFrameUIMap,
117 *s_pNumRuleUIMap,
118 *s_pTableStyleUIMap,
119 *s_pCellStyleUIMap,
121 *s_pParaProgMap,
122 *s_pCharProgMap,
123 *s_pPageProgMap,
124 *s_pFrameProgMap,
125 *s_pNumRuleProgMap,
126 *s_pTableStyleProgMap,
127 *s_pCellStyleProgMap;
129 static void fillNameFromId(sal_uInt16 nId, OUString &rName, bool bProgName);
130 static const OUString& getNameFromId(sal_uInt16 nId, const OUString &rName,
131 bool bProgName);
132 static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, bool bProgName );
133 #ifdef _NEED_TO_DEBUG_MAPPING
134 static void testNameTable( SwGetPoolIdFromName const nFamily, sal_uInt16 const nStartIndex, sal_uInt16 const nEndIndex );
135 #endif
137 public:
138 // This gets the UI Name from the programmatic name
139 static const OUString& GetUIName(const OUString& rName, SwGetPoolIdFromName);
140 static void FillUIName(const OUString& rName, OUString& rFillName,
141 SwGetPoolIdFromName, bool bDisambiguate);
143 // Get the programmatic Name from the UI name
144 static const OUString& GetProgName(const OUString& rName,
145 SwGetPoolIdFromName);
146 static void FillProgName(const OUString& rName, OUString& rFillName,
147 SwGetPoolIdFromName, bool bDisambiguate);
149 // This gets the UI Name from the Pool ID
150 SW_DLLPUBLIC static void FillUIName(sal_uInt16 nId, OUString& rFillName);
151 SW_DLLPUBLIC static const OUString& GetUIName(sal_uInt16 nId,
152 const OUString& rName);
154 // This gets the programmatic Name from the Pool ID
155 static void FillProgName(sal_uInt16 nId, OUString& rFillName);
156 SW_DLLPUBLIC static const OUString& GetProgName(sal_uInt16 nId,
157 const OUString& rName);
159 // This gets the PoolId from the UI Name
160 SW_DLLPUBLIC static sal_uInt16 GetPoolIdFromUIName(const OUString& rName,
161 SwGetPoolIdFromName);
163 // Get the Pool ID from the programmatic name
164 static sal_uInt16 GetPoolIdFromProgName(const OUString& rName,
165 SwGetPoolIdFromName);
167 // used to convert the 4 special ExtraProg/UINames for
168 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
169 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
170 // forth and back.
171 // Non-matching names remain unchanged.
172 SW_DLLPUBLIC static const OUString GetSpecialExtraProgName(
173 const OUString& rExtraUIName);
174 static const OUString GetSpecialExtraUIName(const OUString& rExtraProgName);
176 static const std::vector<OUString>& GetTextUINameArray();
177 static const std::vector<OUString>& GetListsUINameArray();
178 static const std::vector<OUString>& GetExtraUINameArray();
179 static const std::vector<OUString>& GetRegisterUINameArray();
180 static const std::vector<OUString>& GetDocUINameArray();
181 static const std::vector<OUString>& GetHTMLUINameArray();
182 static const std::vector<OUString>& GetFrameFormatUINameArray();
183 static const std::vector<OUString>& GetChrFormatUINameArray();
184 static const std::vector<OUString>& GetHTMLChrFormatUINameArray();
185 static const std::vector<OUString>& GetPageDescUINameArray();
186 static const std::vector<OUString>& GetNumRuleUINameArray();
187 static const std::vector<OUString>& GetTableStyleUINameArray();
188 static const std::vector<OUString>& GetCellStyleUINameArray();
190 static const std::vector<OUString>& GetTextProgNameArray();
191 static const std::vector<OUString>& GetListsProgNameArray();
192 static const std::vector<OUString>& GetExtraProgNameArray();
193 static const std::vector<OUString>& GetRegisterProgNameArray();
194 static const std::vector<OUString>& GetDocProgNameArray();
195 static const std::vector<OUString>& GetHTMLProgNameArray();
196 static const std::vector<OUString>& GetFrameFormatProgNameArray();
197 static const std::vector<OUString>& GetChrFormatProgNameArray();
198 static const std::vector<OUString>& GetHTMLChrFormatProgNameArray();
199 static const std::vector<OUString>& GetPageDescProgNameArray();
200 static const std::vector<OUString>& GetNumRuleProgNameArray();
201 static const std::vector<OUString>& GetTableStyleProgNameArray();
202 static const std::vector<OUString>& GetCellStyleProgNameArray();
204 #endif // _NAME_MAPPER_HXX
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */