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