1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
27 #include <unordered_map>
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)
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
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.
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.
76 typedef std::unordered_map
<OUString
, sal_uInt16
, OUStringHash
> NameToIdHash
;
78 class SwStyleNameMapper
80 friend void _InitCore();
81 friend void _FinitCore();
85 static ::std::vector
<OUString
> *pTextUINameArray
,
88 *pRegisterUINameArray
,
91 *pFrameFormatUINameArray
,
92 *pChrFormatUINameArray
,
93 *pHTMLChrFormatUINameArray
,
94 *pPageDescUINameArray
,
96 // Programmatic Name tables
100 *pRegisterProgNameArray
,
103 *pFrameFormatProgNameArray
,
104 *pChrFormatProgNameArray
,
105 *pHTMLChrFormatProgNameArray
,
106 *pPageDescProgNameArray
,
107 *pNumRuleProgNameArray
;
109 static NameToIdHash
*pParaUIMap
,
121 static void fillNameFromId(sal_uInt16 nId
, OUString
&rName
, bool bProgName
);
122 static const OUString
& getNameFromId(sal_uInt16 nId
, const OUString
&rName
,
124 static const NameToIdHash
& getHashTable ( SwGetPoolIdFromName
, bool bProgName
);
125 #ifdef _NEED_TO_DEBUG_MAPPING
126 static void testNameTable( SwGetPoolIdFromName
const nFamily
, sal_uInt16
const nStartIndex
, sal_uInt16
const nEndIndex
);
130 // This gets the UI Name from the programmatic name
131 static const OUString
& GetUIName(const OUString
& rName
, SwGetPoolIdFromName
);
132 static void FillUIName(const OUString
& rName
, OUString
& rFillName
,
133 SwGetPoolIdFromName
, bool bDisambiguate
= false);
135 // Get the programmatic Name from the UI name
136 static const OUString
& GetProgName(const OUString
& rName
,
137 SwGetPoolIdFromName
);
138 static void FillProgName(const OUString
& rName
, OUString
& rFillName
,
139 SwGetPoolIdFromName
, bool bDisambiguate
= false);
141 // This gets the UI Name from the Pool ID
142 SW_DLLPUBLIC
static void FillUIName(sal_uInt16 nId
, OUString
& rFillName
);
143 SW_DLLPUBLIC
static const OUString
& GetUIName(sal_uInt16 nId
,
144 const OUString
& rName
);
146 // This gets the programmatic Name from the Pool ID
147 static void FillProgName(sal_uInt16 nId
, OUString
& rFillName
);
148 SW_DLLPUBLIC
static const OUString
& GetProgName(sal_uInt16 nId
,
149 const OUString
& rName
);
151 // This gets the PoolId from the UI Name
152 SW_DLLPUBLIC
static sal_uInt16
GetPoolIdFromUIName(const OUString
& rName
,
153 SwGetPoolIdFromName
);
155 // Get the Pool ID from the programmatic name
156 static sal_uInt16
GetPoolIdFromProgName(const OUString
& rName
,
157 SwGetPoolIdFromName
);
159 // used to convert the 4 special ExtraProg/UINames for
160 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
161 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
163 // Non-matching names remain unchanged.
164 SW_DLLPUBLIC
static const OUString
GetSpecialExtraProgName(
165 const OUString
& rExtraUIName
);
166 static const OUString
GetSpecialExtraUIName(const OUString
& rExtraProgName
);
168 static const ::std::vector
<OUString
>& GetTextUINameArray();
169 static const ::std::vector
<OUString
>& GetListsUINameArray();
170 static const ::std::vector
<OUString
>& GetExtraUINameArray();
171 static const ::std::vector
<OUString
>& GetRegisterUINameArray();
172 static const ::std::vector
<OUString
>& GetDocUINameArray();
173 static const ::std::vector
<OUString
>& GetHTMLUINameArray();
174 static const ::std::vector
<OUString
>& GetFrameFormatUINameArray();
175 static const ::std::vector
<OUString
>& GetChrFormatUINameArray();
176 static const ::std::vector
<OUString
>& GetHTMLChrFormatUINameArray();
177 static const ::std::vector
<OUString
>& GetPageDescUINameArray();
178 static const ::std::vector
<OUString
>& GetNumRuleUINameArray();
180 static const ::std::vector
<OUString
>& GetTextProgNameArray();
181 static const ::std::vector
<OUString
>& GetListsProgNameArray();
182 static const ::std::vector
<OUString
>& GetExtraProgNameArray();
183 static const ::std::vector
<OUString
>& GetRegisterProgNameArray();
184 static const ::std::vector
<OUString
>& GetDocProgNameArray();
185 static const ::std::vector
<OUString
>& GetHTMLProgNameArray();
186 static const ::std::vector
<OUString
>& GetFrameFormatProgNameArray();
187 static const ::std::vector
<OUString
>& GetChrFormatProgNameArray();
188 static const ::std::vector
<OUString
>& GetHTMLChrFormatProgNameArray();
189 static const ::std::vector
<OUString
>& GetPageDescProgNameArray();
190 static const ::std::vector
<OUString
>& GetNumRuleProgNameArray();
192 #endif // _NAME_MAPPER_HXX
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */