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 SYMBOL_HXX 28*cdf0e10cSrcweir #define SYMBOL_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <vos/refernce.hxx> 31*cdf0e10cSrcweir #include <vcl/font.hxx> 32*cdf0e10cSrcweir #include <tools/list.hxx> 33*cdf0e10cSrcweir #include <tools/debug.hxx> 34*cdf0e10cSrcweir #include <tools/dynary.hxx> 35*cdf0e10cSrcweir #include <svl/lstner.hxx> 36*cdf0e10cSrcweir #include <svl/svarray.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <map> 39*cdf0e10cSrcweir #include <vector> 40*cdf0e10cSrcweir #include <set> 41*cdf0e10cSrcweir #include <functional> 42*cdf0e10cSrcweir #include <algorithm> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include "unomodel.hxx" 45*cdf0e10cSrcweir #include "utility.hxx" 46*cdf0e10cSrcweir #include "smmod.hxx" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #define SYMBOLSET_NONE 0xFFFF 50*cdf0e10cSrcweir #define SYMBOL_NONE 0xFFFF 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////// 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir inline const String GetExportSymbolName( const String &rUiSymbolName ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetExportSymbolName( rUiSymbolName ); 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir inline const String GetUiSymbolName( const String &rExportSymbolName ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetUiSymbolName( rExportSymbolName ); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir inline const String GetExportSymbolSetName( const String &rUiSymbolSetName ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetExportSymbolSetName( rUiSymbolSetName ); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir inline const String GetUiSymbolSetName( const String &rExportSymbolSetName ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetUiSymbolSetName( rExportSymbolSetName ); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////// 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir class SmSym 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir SmFace m_aFace; 82*cdf0e10cSrcweir String m_aName; 83*cdf0e10cSrcweir String m_aExportName; 84*cdf0e10cSrcweir String m_aSetName; 85*cdf0e10cSrcweir sal_UCS4 m_cChar; 86*cdf0e10cSrcweir sal_Bool m_bPredefined; 87*cdf0e10cSrcweir sal_Bool m_bDocSymbol; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir public: 90*cdf0e10cSrcweir SmSym(); 91*cdf0e10cSrcweir SmSym(const String& rName, const Font& rFont, sal_UCS4 cChar, 92*cdf0e10cSrcweir const String& rSet, sal_Bool bIsPredefined = sal_False); 93*cdf0e10cSrcweir SmSym(const SmSym& rSymbol); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir SmSym& operator = (const SmSym& rSymbol); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir const Font& GetFace() const { return m_aFace; } 98*cdf0e10cSrcweir sal_UCS4 GetCharacter() const { return m_cChar; } 99*cdf0e10cSrcweir const String& GetName() const { return m_aName; } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void SetFace( const Font& rFont ) { m_aFace = rFont; } 102*cdf0e10cSrcweir void SetCharacter( sal_UCS4 cChar ) { m_cChar = cChar; } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir //! since the symbol name is also used as key in the map it should not be possible to change the name 105*cdf0e10cSrcweir //! because ten the key would not be the same as its supposed copy here 106*cdf0e10cSrcweir // void SetName( const String &rTxt ) { m_aName = rTxt; } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir sal_Bool IsPredefined() const { return m_bPredefined; } 109*cdf0e10cSrcweir const String & GetSymbolSetName() const { return m_aSetName; } 110*cdf0e10cSrcweir void SetSymbolSetName( const String &rName ) { m_aSetName = rName; } 111*cdf0e10cSrcweir const String & GetExportName() const { return m_aExportName; } 112*cdf0e10cSrcweir void SetExportName( const String &rName ) { m_aExportName = rName; } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir sal_Bool IsDocSymbol() const { return m_bDocSymbol; } 115*cdf0e10cSrcweir void SetDocSymbol( sal_Bool bVal ) { m_bDocSymbol = bVal; } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // true if rSymbol has the same name, font and character 118*cdf0e10cSrcweir bool IsEqualInUI( const SmSym& rSymbol ) const; 119*cdf0e10cSrcweir }; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /**************************************************************************/ 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir struct lt_String 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir bool operator()( const String &r1, const String &r2 ) const 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir // r1 < r2 ? 128*cdf0e10cSrcweir return r1.CompareTo( r2 ) == COMPARE_LESS; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir }; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // type of the actual container to hold the symbols 134*cdf0e10cSrcweir typedef std::map< String, SmSym, lt_String > SymbolMap_t; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // vector of pointers to the actual symbols in the above container 137*cdf0e10cSrcweir typedef std::vector< const SmSym * > SymbolPtrVec_t; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool > 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir bool operator() ( const SmSym *pSym1, const SmSym *pSym2 ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir return pSym1->GetCharacter() < pSym2->GetCharacter(); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir }; 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir class SmSymbolManager : public SfxListener 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir SymbolMap_t m_aSymbols; 151*cdf0e10cSrcweir bool m_bModified; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType, 154*cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir void Init(); 157*cdf0e10cSrcweir void Exit(); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir public: 160*cdf0e10cSrcweir SmSymbolManager(); 161*cdf0e10cSrcweir SmSymbolManager(const SmSymbolManager& rSymbolSetManager); 162*cdf0e10cSrcweir ~SmSymbolManager(); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // symbol sets are for UI purpose only, thus we assemble them here 167*cdf0e10cSrcweir std::set< String > GetSymbolSetNames() const; 168*cdf0e10cSrcweir const SymbolPtrVec_t GetSymbolSet( const String& rSymbolSetName ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir sal_uInt16 GetSymbolCount() const { return static_cast< sal_uInt16 >(m_aSymbols.size()); } 171*cdf0e10cSrcweir const SymbolPtrVec_t GetSymbols() const; 172*cdf0e10cSrcweir bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false ); 173*cdf0e10cSrcweir void RemoveSymbol( const String & rSymbolName ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir SmSym * GetSymbolByName(const String& rSymbolName); 176*cdf0e10cSrcweir const SmSym * GetSymbolByName(const String& rSymbolName) const 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir return ((SmSymbolManager *) this)->GetSymbolByName(rSymbolName); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir bool IsModified() const { return m_bModified; } 182*cdf0e10cSrcweir void SetModified(bool bModify) { m_bModified = bModify; } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void Load(); 185*cdf0e10cSrcweir void Save(); 186*cdf0e10cSrcweir }; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir #endif 189*cdf0e10cSrcweir 190