1*1d2dbeb0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1d2dbeb0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1d2dbeb0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1d2dbeb0SAndrew Rist * distributed with this work for additional information 6*1d2dbeb0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1d2dbeb0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1d2dbeb0SAndrew Rist * "License"); you may not use this file except in compliance 9*1d2dbeb0SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*1d2dbeb0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*1d2dbeb0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1d2dbeb0SAndrew Rist * software distributed under the License is distributed on an 15*1d2dbeb0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1d2dbeb0SAndrew Rist * KIND, either express or implied. See the License for the 17*1d2dbeb0SAndrew Rist * specific language governing permissions and limitations 18*1d2dbeb0SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*1d2dbeb0SAndrew Rist *************************************************************/ 21*1d2dbeb0SAndrew Rist 22*1d2dbeb0SAndrew Rist 23cdf0e10cSrcweir #ifndef _SWSTYLENAMEMAPPER_HXX 24cdf0e10cSrcweir #define _SWSTYLENAMEMAPPER_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <sal/types.h> 27cdf0e10cSrcweir #include <tools/string.hxx> 28cdf0e10cSrcweir #include <SwGetPoolIdFromName.hxx> 29cdf0e10cSrcweir #include "swdllapi.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef INCLUDED_HASH_MAP 32cdf0e10cSrcweir #include <hash_map> 33cdf0e10cSrcweir #define INCLUDED_HASH_MAP 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <stringhash.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir /* This class holds all data about the names of styles used in the user 38cdf0e10cSrcweir * interface (UI names...these are localised into different languages). 39cdf0e10cSrcweir * These UI names are loaded from the resource files on demand. 40cdf0e10cSrcweir * 41cdf0e10cSrcweir * It also holds all information about the 'Programmatic' names of styles 42cdf0e10cSrcweir * which remain static (and are hardcoded in the corresponding cxx file) 43cdf0e10cSrcweir * for all languages. 44cdf0e10cSrcweir * 45cdf0e10cSrcweir * This class also provides static functions which can be used for the 46cdf0e10cSrcweir * following conversions: 47cdf0e10cSrcweir * 48cdf0e10cSrcweir * 1. Programmatic Name -> UI Name 49cdf0e10cSrcweir * 2. Programmatic Name -> Pool ID 50cdf0e10cSrcweir * 3. UI Name -> Programmatic Name 51cdf0e10cSrcweir * 4. UI Name -> Pool ID 52cdf0e10cSrcweir * 5. Pool ID -> UI Name 53cdf0e10cSrcweir * 6. Pool ID -> Programmatic Name 54cdf0e10cSrcweir * 55cdf0e10cSrcweir * The relationship of these tables to the style families is as follows: 56cdf0e10cSrcweir * 57cdf0e10cSrcweir * 1. Paragraph contains the Text, Lists, Extra, Register, Doc and HTML 58cdf0e10cSrcweir * name arrays. 59cdf0e10cSrcweir * 2. Character contains the ChrFmt and HTMLChrFmt name arrays. 60cdf0e10cSrcweir * 3. Page contains the PageDesc name array. 61cdf0e10cSrcweir * 4. Frame contains the FrmFmt name array. 62cdf0e10cSrcweir * 5. Numbering Rule contains the NumRule name array. 63cdf0e10cSrcweir */ 64cdf0e10cSrcweir 65cdf0e10cSrcweir /* 66cdf0e10cSrcweir * There is a further complication that came to light later. If someone enters 67cdf0e10cSrcweir * a user-defined style name which is the same as a programmatic name, this 68cdf0e10cSrcweir * name clash must be handled. 69cdf0e10cSrcweir * 70cdf0e10cSrcweir * Therefore, when there is a danger of a nameclash, the boolean bDisambiguate 71cdf0e10cSrcweir * must be set to true in the SwStyleNameMapper call (it defaults to false). 72cdf0e10cSrcweir * This will cause the following to happen: 73cdf0e10cSrcweir * 74cdf0e10cSrcweir * If the UI style name either equals a programmatic name or already ends 75cdf0e10cSrcweir * with " (user)", then it must append " (user)" to the end. 76cdf0e10cSrcweir * 77cdf0e10cSrcweir * When a programmatic name is being converted to a UI name, if it ends in 78cdf0e10cSrcweir * " (user)", we simply remove it. 79cdf0e10cSrcweir */ 80cdf0e10cSrcweir 81cdf0e10cSrcweir class SvStringsDtor; 82cdf0e10cSrcweir class String; 83cdf0e10cSrcweir struct SwTableEntry; 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir typedef ::std::hash_map < const String*, sal_uInt16, StringHash, StringEq > NameToIdHash; 87cdf0e10cSrcweir 88cdf0e10cSrcweir class SwStyleNameMapper 89cdf0e10cSrcweir { 90cdf0e10cSrcweir friend void _InitCore(); 91cdf0e10cSrcweir friend void _FinitCore(); 92cdf0e10cSrcweir 93cdf0e10cSrcweir protected: 94cdf0e10cSrcweir // UI Name tables 95cdf0e10cSrcweir static SvStringsDtor *pTextUINameArray, 96cdf0e10cSrcweir *pListsUINameArray, 97cdf0e10cSrcweir *pExtraUINameArray, 98cdf0e10cSrcweir *pRegisterUINameArray, 99cdf0e10cSrcweir *pDocUINameArray, 100cdf0e10cSrcweir *pHTMLUINameArray, 101cdf0e10cSrcweir *pFrmFmtUINameArray, 102cdf0e10cSrcweir *pChrFmtUINameArray, 103cdf0e10cSrcweir *pHTMLChrFmtUINameArray, 104cdf0e10cSrcweir *pPageDescUINameArray, 105cdf0e10cSrcweir *pNumRuleUINameArray, 106cdf0e10cSrcweir // Programmatic Name tables 107cdf0e10cSrcweir *pTextProgNameArray, 108cdf0e10cSrcweir *pListsProgNameArray, 109cdf0e10cSrcweir *pExtraProgNameArray, 110cdf0e10cSrcweir *pRegisterProgNameArray, 111cdf0e10cSrcweir *pDocProgNameArray, 112cdf0e10cSrcweir *pHTMLProgNameArray, 113cdf0e10cSrcweir *pFrmFmtProgNameArray, 114cdf0e10cSrcweir *pChrFmtProgNameArray, 115cdf0e10cSrcweir *pHTMLChrFmtProgNameArray, 116cdf0e10cSrcweir *pPageDescProgNameArray, 117cdf0e10cSrcweir *pNumRuleProgNameArray; 118cdf0e10cSrcweir 119cdf0e10cSrcweir static NameToIdHash *pParaUIMap, 120cdf0e10cSrcweir *pCharUIMap, 121cdf0e10cSrcweir *pPageUIMap, 122cdf0e10cSrcweir *pFrameUIMap, 123cdf0e10cSrcweir *pNumRuleUIMap, 124cdf0e10cSrcweir 125cdf0e10cSrcweir *pParaProgMap, 126cdf0e10cSrcweir *pCharProgMap, 127cdf0e10cSrcweir *pPageProgMap, 128cdf0e10cSrcweir *pFrameProgMap, 129cdf0e10cSrcweir *pNumRuleProgMap; 130cdf0e10cSrcweir 131cdf0e10cSrcweir static SvStringsDtor* NewUINameArray( SvStringsDtor*&, 132cdf0e10cSrcweir sal_uInt16 nStt, 133cdf0e10cSrcweir sal_uInt16 nEnd ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir static SvStringsDtor* NewProgNameArray( SvStringsDtor*&, 136cdf0e10cSrcweir const SwTableEntry *pTable, 137cdf0e10cSrcweir sal_uInt8 nCount); 138cdf0e10cSrcweir 139cdf0e10cSrcweir static void fillNameFromId ( sal_uInt16 nId, String &rName, sal_Bool bProgName ); 140cdf0e10cSrcweir static const String& getNameFromId ( sal_uInt16 nId, const String &rName, sal_Bool bProgName ); 141cdf0e10cSrcweir static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, sal_Bool bProgName ); 142cdf0e10cSrcweir static sal_Bool SuffixIsUser ( const String & rString ); 143cdf0e10cSrcweir static void CheckSuffixAndDelete ( String & rString ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir public: 146cdf0e10cSrcweir // This gets the UI Name from the programmatic name 147cdf0e10cSrcweir static const String& GetUIName ( const String& rName, SwGetPoolIdFromName ); 148cdf0e10cSrcweir static void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // Get the programmatic Name from the UI name 151cdf0e10cSrcweir static const String& GetProgName ( const String& rName, SwGetPoolIdFromName ); 152cdf0e10cSrcweir static void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir // This gets the UI Name from the Pool ID 155cdf0e10cSrcweir SW_DLLPUBLIC static void FillUIName ( sal_uInt16 nId, String& rFillName ); 156cdf0e10cSrcweir SW_DLLPUBLIC static const String& GetUIName ( sal_uInt16 nId, const String& rName ); 157cdf0e10cSrcweir 158cdf0e10cSrcweir // This gets the programmatic Name from the Pool ID 159cdf0e10cSrcweir static void FillProgName( sal_uInt16 nId, String& rFillName ); 160cdf0e10cSrcweir SW_DLLPUBLIC static const String& GetProgName ( sal_uInt16 nId, const String& rName ); 161cdf0e10cSrcweir 162cdf0e10cSrcweir // This gets the PoolId from the UI Name 163cdf0e10cSrcweir SW_DLLPUBLIC static sal_uInt16 GetPoolIdFromUIName( const String& rName, SwGetPoolIdFromName ); 164cdf0e10cSrcweir 165cdf0e10cSrcweir // Get the Pool ID from the programmatic name 166cdf0e10cSrcweir static sal_uInt16 GetPoolIdFromProgName( const String& rName, SwGetPoolIdFromName ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir // used to convert the 4 special ExtraProg/UINames for 169cdf0e10cSrcweir // RES_POOLCOLL_LABEL_DRAWING, RES_POOLCOLL_LABEL_ABB, 170cdf0e10cSrcweir // RES_POOLCOLL_LABEL_TABLE, RES_POOLCOLL_LABEL_FRAME 171cdf0e10cSrcweir // forth and back. 172cdf0e10cSrcweir // Non-matching names remain unchanged. 173cdf0e10cSrcweir SW_DLLPUBLIC static const String GetSpecialExtraProgName( const String& rExtraUIName ); 174cdf0e10cSrcweir static const String GetSpecialExtraUIName( const String& rExtraProgName ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir static const SvStringsDtor& GetTextUINameArray(); 177cdf0e10cSrcweir static const SvStringsDtor& GetListsUINameArray(); 178cdf0e10cSrcweir static const SvStringsDtor& GetExtraUINameArray(); 179cdf0e10cSrcweir static const SvStringsDtor& GetRegisterUINameArray(); 180cdf0e10cSrcweir static const SvStringsDtor& GetDocUINameArray(); 181cdf0e10cSrcweir static const SvStringsDtor& GetHTMLUINameArray(); 182cdf0e10cSrcweir static const SvStringsDtor& GetFrmFmtUINameArray(); 183cdf0e10cSrcweir static const SvStringsDtor& GetChrFmtUINameArray(); 184cdf0e10cSrcweir static const SvStringsDtor& GetHTMLChrFmtUINameArray(); 185cdf0e10cSrcweir static const SvStringsDtor& GetPageDescUINameArray(); 186cdf0e10cSrcweir static const SvStringsDtor& GetNumRuleUINameArray(); 187cdf0e10cSrcweir 188cdf0e10cSrcweir static const SvStringsDtor& GetTextProgNameArray(); 189cdf0e10cSrcweir static const SvStringsDtor& GetListsProgNameArray(); 190cdf0e10cSrcweir static const SvStringsDtor& GetExtraProgNameArray(); 191cdf0e10cSrcweir static const SvStringsDtor& GetRegisterProgNameArray(); 192cdf0e10cSrcweir static const SvStringsDtor& GetDocProgNameArray(); 193cdf0e10cSrcweir static const SvStringsDtor& GetHTMLProgNameArray(); 194cdf0e10cSrcweir static const SvStringsDtor& GetFrmFmtProgNameArray(); 195cdf0e10cSrcweir static const SvStringsDtor& GetChrFmtProgNameArray(); 196cdf0e10cSrcweir static const SvStringsDtor& GetHTMLChrFmtProgNameArray(); 197cdf0e10cSrcweir static const SvStringsDtor& GetPageDescProgNameArray(); 198cdf0e10cSrcweir static const SvStringsDtor& GetNumRuleProgNameArray(); 199cdf0e10cSrcweir }; 200cdf0e10cSrcweir #endif // _NAME_MAPPER_HXX 201