1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwStyleNameMapper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _SWSTYLENAMEMAPPER_HXX
31 #define _SWSTYLENAMEMAPPER_HXX
33 #include <sal/types.h>
34 #include <tools/string.hxx>
35 #include <SwGetPoolIdFromName.hxx>
38 #ifndef INCLUDED_HASH_MAP
40 #define INCLUDED_HASH_MAP
42 #include <stringhash.hxx>
44 /* This class holds all data about the names of styles used in the user
45 * interface (UI names...these are localised into different languages).
46 * These UI names are loaded from the resource files on demand.
48 * It also holds all information about the 'Programmatic' names of styles
49 * which remain static (and are hardcoded in the corresponding cxx file)
52 * This class also provides static functions which can be used for the
53 * following conversions:
55 * 1. Programmatic Name -> UI Name
56 * 2. Programmatic Name -> Pool ID
57 * 3. UI Name -> Programmatic Name
58 * 4. UI Name -> Pool ID
59 * 5. Pool ID -> UI Name
60 * 6. Pool ID -> Programmatic Name
62 * The relationship of these tables to the style families is as follows:
64 * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML
66 * 2. Character contains the ChrFmt and HTMLChrFmt name arrays.
67 * 3. Page contains the PageDesc name array.
68 * 4. Frame contains the FrmFmt name array.
69 * 5. Numbering Rule contains the NumRule name array.
73 * There is a further complication that came to light later. If someone enters
74 * a user-defined style name which is the same as a programmatic name, this
75 * name clash must be handled.
77 * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
78 * must be set to true in the SwStyleNameMapper call (it defaults to false).
79 * This will cause the following to happen:
81 * If the UI style name either equals a programmatic name or already ends
82 * with " (user)", then it must append " (user)" to the end.
84 * When a programmatic name is being converted to a UI name, if it ends in
85 * " (user)", we simply remove it.
93 typedef ::std::hash_map
< const String
*, sal_uInt16
, StringHash
, StringEq
> NameToIdHash
;
95 class SwStyleNameMapper
97 friend void _InitCore();
98 friend void _FinitCore();
102 static SvStringsDtor
*pTextUINameArray
,
105 *pRegisterUINameArray
,
110 *pHTMLChrFmtUINameArray
,
111 *pPageDescUINameArray
,
112 *pNumRuleUINameArray
,
113 // Programmatic Name tables
115 *pListsProgNameArray
,
116 *pExtraProgNameArray
,
117 *pRegisterProgNameArray
,
120 *pFrmFmtProgNameArray
,
121 *pChrFmtProgNameArray
,
122 *pHTMLChrFmtProgNameArray
,
123 *pPageDescProgNameArray
,
124 *pNumRuleProgNameArray
;
126 static NameToIdHash
*pParaUIMap
,
138 static SvStringsDtor
* NewUINameArray( SvStringsDtor
*&,
142 static SvStringsDtor
* NewProgNameArray( SvStringsDtor
*&,
143 const SwTableEntry
*pTable
,
146 static void fillNameFromId ( sal_uInt16 nId
, String
&rName
, sal_Bool bProgName
);
147 static const String
& getNameFromId ( sal_uInt16 nId
, const String
&rName
, sal_Bool bProgName
);
148 static const NameToIdHash
& getHashTable ( SwGetPoolIdFromName
, sal_Bool bProgName
);
149 static sal_Bool
SuffixIsUser ( const String
& rString
);
150 static void CheckSuffixAndDelete ( String
& rString
);
153 // This gets the UI Name from the programmatic name
154 static const String
& GetUIName ( const String
& rName
, SwGetPoolIdFromName
);
155 static void FillUIName ( const String
& rName
, String
& rFillName
, SwGetPoolIdFromName
, sal_Bool bDisambiguate
= sal_False
);
157 // Get the programmatic Name from the UI name
158 static const String
& GetProgName ( const String
& rName
, SwGetPoolIdFromName
);
159 static void FillProgName ( const String
& rName
, String
& rFillName
, SwGetPoolIdFromName
, sal_Bool bDisambiguate
= sal_False
);
161 // This gets the UI Name from the Pool ID
162 SW_DLLPUBLIC
static void FillUIName ( sal_uInt16 nId
, String
& rFillName
);
163 SW_DLLPUBLIC
static const String
& GetUIName ( sal_uInt16 nId
, const String
& rName
);
165 // This gets the programmatic Name from the Pool ID
166 static void FillProgName( sal_uInt16 nId
, String
& rFillName
);
167 SW_DLLPUBLIC
static const String
& GetProgName ( sal_uInt16 nId
, const String
& rName
);
169 // This gets the PoolId from the UI Name
170 SW_DLLPUBLIC
static sal_uInt16
GetPoolIdFromUIName( const String
& rName
, SwGetPoolIdFromName
);
172 // Get the Pool ID from the programmatic name
173 static sal_uInt16
GetPoolIdFromProgName( const String
& rName
, SwGetPoolIdFromName
);
175 // used to convert the 4 special ExtraProg/UINames for
176 // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB,
177 // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME
179 // Non-matching names remain unchanged.
180 SW_DLLPUBLIC
static const String
GetSpecialExtraProgName( const String
& rExtraUIName
);
181 static const String
GetSpecialExtraUIName( const String
& rExtraProgName
);
183 static const SvStringsDtor
& GetTextUINameArray();
184 static const SvStringsDtor
& GetListsUINameArray();
185 static const SvStringsDtor
& GetExtraUINameArray();
186 static const SvStringsDtor
& GetRegisterUINameArray();
187 static const SvStringsDtor
& GetDocUINameArray();
188 static const SvStringsDtor
& GetHTMLUINameArray();
189 static const SvStringsDtor
& GetFrmFmtUINameArray();
190 static const SvStringsDtor
& GetChrFmtUINameArray();
191 static const SvStringsDtor
& GetHTMLChrFmtUINameArray();
192 static const SvStringsDtor
& GetPageDescUINameArray();
193 static const SvStringsDtor
& GetNumRuleUINameArray();
195 static const SvStringsDtor
& GetTextProgNameArray();
196 static const SvStringsDtor
& GetListsProgNameArray();
197 static const SvStringsDtor
& GetExtraProgNameArray();
198 static const SvStringsDtor
& GetRegisterProgNameArray();
199 static const SvStringsDtor
& GetDocProgNameArray();
200 static const SvStringsDtor
& GetHTMLProgNameArray();
201 static const SvStringsDtor
& GetFrmFmtProgNameArray();
202 static const SvStringsDtor
& GetChrFmtProgNameArray();
203 static const SvStringsDtor
& GetHTMLChrFmtProgNameArray();
204 static const SvStringsDtor
& GetPageDescProgNameArray();
205 static const SvStringsDtor
& GetNumRuleProgNameArray();
207 #endif // _NAME_MAPPER_HXX