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 .
21 #include <sal/types.h>
22 #include <rtl/ustring.hxx>
23 #include "SwGetPoolIdFromName.hxx"
26 #include <unordered_map>
29 /** This class holds all data about the names of styles used in the user
30 * interface (UI names...these are localised into different languages).
31 * These UI names are loaded from the resource files on demand.
33 * It also holds all information about the 'Programmatic' names of styles
34 * which remain static (and are hardcoded in the corresponding cxx file)
37 * This class also provides static functions which can be used for the
38 * following conversions:
40 * 1. Programmatic Name -> UI Name
41 * 2. Programmatic Name -> Pool ID
42 * 3. UI Name -> Programmatic Name
43 * 4. UI Name -> Pool ID
44 * 5. Pool ID -> UI Name
45 * 6. Pool ID -> Programmatic Name
47 * The relationship of these tables to the style families is as follows:
49 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
51 * 2. Character contains the ChrFormat and HTMLChrFormat name arrays.
52 * 3. Page contains the PageDesc name array.
53 * 4. Frame contains the FrameFormat name array.
54 * 5. Numbering Rule contains the NumRule name array.
58 * There is a further complication that came to light later. If someone enters
59 * a user-defined style name which is the same as a programmatic name, this
60 * name clash must be handled.
62 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
63 * must be set to true in the SwStyleNameMapper call (it defaults to false).
64 * This will cause the following to happen:
66 * If the UI style name either equals a programmatic name or already ends
67 * with " (user)", then it must append " (user)" to the end.
69 * When a programmatic name is being converted to a UI name, if it ends in
70 * " (user)", we simply remove it.
73 typedef std::unordered_map
<OUString
, sal_uInt16
> NameToIdHash
;
75 class SwStyleNameMapper final
77 friend void InitCore();
78 friend void FinitCore();
80 static void fillNameFromId(sal_uInt16 nId
, OUString
&rName
, bool bProgName
);
81 static const OUString
& getNameFromId(sal_uInt16 nId
, const OUString
&rName
,
83 static const NameToIdHash
& getHashTable ( SwGetPoolIdFromName
, bool bProgName
);
84 #ifdef _NEED_TO_DEBUG_MAPPING
85 static void testNameTable( SwGetPoolIdFromName
const nFamily
, sal_uInt16
const nStartIndex
, sal_uInt16
const nEndIndex
);
89 // This gets the UI Name from the programmatic name
90 SAL_WARN_UNUSED_RESULT
91 static const OUString
& GetUIName(const OUString
& rName
, SwGetPoolIdFromName
);
92 static void FillUIName(const OUString
& rName
, OUString
& rFillName
,
95 // Get the programmatic Name from the UI name
96 SAL_WARN_UNUSED_RESULT
97 static const OUString
& GetProgName(const OUString
& rName
,
99 static void FillProgName(const OUString
& rName
, OUString
& rFillName
,
100 SwGetPoolIdFromName
);
102 // This gets the UI Name from the Pool ID
103 SW_DLLPUBLIC
static void FillUIName(sal_uInt16 nId
, OUString
& rFillName
);
104 SAL_WARN_UNUSED_RESULT
105 SW_DLLPUBLIC
static const OUString
& GetUIName(sal_uInt16 nId
,
106 const OUString
& rName
);
108 // This gets the programmatic Name from the Pool ID
109 static void FillProgName(sal_uInt16 nId
, OUString
& rFillName
);
110 SAL_WARN_UNUSED_RESULT
111 SW_DLLPUBLIC
static const OUString
& GetProgName(sal_uInt16 nId
,
112 const OUString
& rName
);
114 // This gets the PoolId from the UI Name
115 SAL_WARN_UNUSED_RESULT
116 SW_DLLPUBLIC
static sal_uInt16
GetPoolIdFromUIName(const OUString
& rName
,
117 SwGetPoolIdFromName
);
119 // Get the Pool ID from the programmatic name
120 SAL_WARN_UNUSED_RESULT
121 static sal_uInt16
GetPoolIdFromProgName(const OUString
& rName
,
122 SwGetPoolIdFromName
);
124 // used to convert the 4 special ExtraProg/UINames for
125 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
126 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
128 // Non-matching names remain unchanged.
129 SAL_WARN_UNUSED_RESULT
130 SW_DLLPUBLIC
static const OUString
& GetSpecialExtraProgName(
131 const OUString
& rExtraUIName
);
132 SAL_WARN_UNUSED_RESULT
133 static const OUString
& GetSpecialExtraUIName(const OUString
& rExtraProgName
);
135 static const std::vector
<OUString
>& GetTextUINameArray();
136 static const std::vector
<OUString
>& GetListsUINameArray();
137 static const std::vector
<OUString
>& GetExtraUINameArray();
138 static const std::vector
<OUString
>& GetRegisterUINameArray();
139 static const std::vector
<OUString
>& GetDocUINameArray();
140 static const std::vector
<OUString
>& GetHTMLUINameArray();
141 static const std::vector
<OUString
>& GetFrameFormatUINameArray();
142 static const std::vector
<OUString
>& GetChrFormatUINameArray();
143 static const std::vector
<OUString
>& GetHTMLChrFormatUINameArray();
144 static const std::vector
<OUString
>& GetPageDescUINameArray();
145 static const std::vector
<OUString
>& GetNumRuleUINameArray();
146 static const std::vector
<OUString
>& GetTableStyleUINameArray();
147 static const std::vector
<OUString
>& GetCellStyleUINameArray();
149 static const std::vector
<OUString
>& GetTextProgNameArray();
150 static const std::vector
<OUString
>& GetListsProgNameArray();
151 static const std::vector
<OUString
>& GetExtraProgNameArray();
152 static const std::vector
<OUString
>& GetRegisterProgNameArray();
153 static const std::vector
<OUString
>& GetDocProgNameArray();
154 static const std::vector
<OUString
>& GetHTMLProgNameArray();
155 static const std::vector
<OUString
>& GetFrameFormatProgNameArray();
156 static const std::vector
<OUString
>& GetChrFormatProgNameArray();
157 static const std::vector
<OUString
>& GetHTMLChrFormatProgNameArray();
158 static const std::vector
<OUString
>& GetPageDescProgNameArray();
159 static const std::vector
<OUString
>& GetNumRuleProgNameArray();
160 static const std::vector
<OUString
>& GetTableStyleProgNameArray();
161 static const std::vector
<OUString
>& GetCellStyleProgNameArray();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */