bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / SwStyleNameMapper.hxx
blob9ad540f48071ecfaa8cc0bd422c197b4050f6fd1
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 _SWSTYLENAMEMAPPER_HXX
20 #define _SWSTYLENAMEMAPPER_HXX
22 #include <sal/types.h>
23 #include <tools/string.hxx>
24 #include <SwGetPoolIdFromName.hxx>
25 #include "swdllapi.h"
27 #include <boost/unordered_map.hpp>
28 #include <stringhash.hxx>
30 #include <boost/ptr_container/ptr_vector.hpp>
32 /** This class holds all data about the names of styles used in the user
33 * interface (UI names...these are localised into different languages).
34 * These UI names are loaded from the resource files on demand.
36 * It also holds all information about the 'Programmatic' names of styles
37 * which remain static (and are hardcoded in the corresponding cxx file)
38 * for all languages.
40 * This class also provides static functions which can be used for the
41 * following conversions:
43 * 1. Programmatic Name -> UI Name
44 * 2. Programmatic Name -> Pool ID
45 * 3. UI Name -> Programmatic Name
46 * 4. UI Name -> Pool ID
47 * 5. Pool ID -> UI Name
48 * 6. Pool ID -> Programmatic Name
50 * The relationship of these tables to the style families is as follows:
52 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
53 * name arrays.
54 * 2. Character contains the ChrFmt and HTMLChrFmt name arrays.
55 * 3. Page contains the PageDesc name array.
56 * 4. Frame contains the FrmFmt name array.
57 * 5. Numbering Rule contains the NumRule name array.
60 /**
61 * There is a further complication that came to light later. If someone enters
62 * a user-defined style name which is the same as a programmatic name, this
63 * name clash must be handled.
65 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
66 * must be set to true in the SwStyleNameMapper call (it defaults to false).
67 * This will cause the following to happen:
69 * If the UI style name either equals a programmatic name or already ends
70 * with " (user)", then it must append " (user)" to the end.
72 * When a programmatic name is being converted to a UI name, if it ends in
73 * " (user)", we simply remove it.
76 class String;
77 struct SwTableEntry;
79 typedef ::boost::unordered_map < const String*, sal_uInt16, StringHash, StringEq > NameToIdHash;
81 class SwStyleNameMapper
83 friend void _InitCore();
84 friend void _FinitCore();
86 protected:
87 // UI Name tables
88 static boost::ptr_vector<String> *pTextUINameArray,
89 *pListsUINameArray,
90 *pExtraUINameArray,
91 *pRegisterUINameArray,
92 *pDocUINameArray,
93 *pHTMLUINameArray,
94 *pFrmFmtUINameArray,
95 *pChrFmtUINameArray,
96 *pHTMLChrFmtUINameArray,
97 *pPageDescUINameArray,
98 *pNumRuleUINameArray,
99 // Programmatic Name tables
100 *pTextProgNameArray,
101 *pListsProgNameArray,
102 *pExtraProgNameArray,
103 *pRegisterProgNameArray,
104 *pDocProgNameArray,
105 *pHTMLProgNameArray,
106 *pFrmFmtProgNameArray,
107 *pChrFmtProgNameArray,
108 *pHTMLChrFmtProgNameArray,
109 *pPageDescProgNameArray,
110 *pNumRuleProgNameArray;
112 static NameToIdHash *pParaUIMap,
113 *pCharUIMap,
114 *pPageUIMap,
115 *pFrameUIMap,
116 *pNumRuleUIMap,
118 *pParaProgMap,
119 *pCharProgMap,
120 *pPageProgMap,
121 *pFrameProgMap,
122 *pNumRuleProgMap;
124 static boost::ptr_vector<String>* NewUINameArray( boost::ptr_vector<String>*&,
125 sal_uInt16 nStt,
126 sal_uInt16 nEnd );
128 static boost::ptr_vector<String>* NewProgNameArray( boost::ptr_vector<String>*&,
129 const SwTableEntry *pTable,
130 sal_uInt8 nCount);
132 static void fillNameFromId ( sal_uInt16 nId, String &rName, bool bProgName );
133 static const String& getNameFromId ( sal_uInt16 nId, const String &rName, bool bProgName );
134 static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, bool bProgName );
135 static bool SuffixIsUser ( const String & rString );
136 static void CheckSuffixAndDelete ( String & rString );
138 public:
139 // This gets the UI Name from the programmatic name
140 static const String& GetUIName ( const String& rName, SwGetPoolIdFromName );
141 static void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, bool bDisambiguate = false );
143 // Get the programmatic Name from the UI name
144 static const String& GetProgName ( const String& rName, SwGetPoolIdFromName );
145 static void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, bool bDisambiguate = false );
147 // This gets the UI Name from the Pool ID
148 SW_DLLPUBLIC static void FillUIName ( sal_uInt16 nId, String& rFillName );
149 SW_DLLPUBLIC static const String& GetUIName ( sal_uInt16 nId, const String& rName );
151 // This gets the programmatic Name from the Pool ID
152 static void FillProgName( sal_uInt16 nId, String& rFillName );
153 SW_DLLPUBLIC static const String& GetProgName ( sal_uInt16 nId, const String& rName );
155 // This gets the PoolId from the UI Name
156 SW_DLLPUBLIC static sal_uInt16 GetPoolIdFromUIName( const String& rName, SwGetPoolIdFromName );
158 // Get the Pool ID from the programmatic name
159 static sal_uInt16 GetPoolIdFromProgName( const String& rName, SwGetPoolIdFromName );
161 // used to convert the 4 special ExtraProg/UINames for
162 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
163 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
164 // forth and back.
165 // Non-matching names remain unchanged.
166 SW_DLLPUBLIC static const String GetSpecialExtraProgName( const String& rExtraUIName );
167 static const String GetSpecialExtraUIName( const String& rExtraProgName );
169 static const boost::ptr_vector<String>& GetTextUINameArray();
170 static const boost::ptr_vector<String>& GetListsUINameArray();
171 static const boost::ptr_vector<String>& GetExtraUINameArray();
172 static const boost::ptr_vector<String>& GetRegisterUINameArray();
173 static const boost::ptr_vector<String>& GetDocUINameArray();
174 static const boost::ptr_vector<String>& GetHTMLUINameArray();
175 static const boost::ptr_vector<String>& GetFrmFmtUINameArray();
176 static const boost::ptr_vector<String>& GetChrFmtUINameArray();
177 static const boost::ptr_vector<String>& GetHTMLChrFmtUINameArray();
178 static const boost::ptr_vector<String>& GetPageDescUINameArray();
179 static const boost::ptr_vector<String>& GetNumRuleUINameArray();
181 static const boost::ptr_vector<String>& GetTextProgNameArray();
182 static const boost::ptr_vector<String>& GetListsProgNameArray();
183 static const boost::ptr_vector<String>& GetExtraProgNameArray();
184 static const boost::ptr_vector<String>& GetRegisterProgNameArray();
185 static const boost::ptr_vector<String>& GetDocProgNameArray();
186 static const boost::ptr_vector<String>& GetHTMLProgNameArray();
187 static const boost::ptr_vector<String>& GetFrmFmtProgNameArray();
188 static const boost::ptr_vector<String>& GetChrFmtProgNameArray();
189 static const boost::ptr_vector<String>& GetHTMLChrFmtProgNameArray();
190 static const boost::ptr_vector<String>& GetPageDescProgNameArray();
191 static const boost::ptr_vector<String>& GetNumRuleProgNameArray();
193 #endif // _NAME_MAPPER_HXX
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */