1*f6a9d5caSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6a9d5caSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6a9d5caSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6a9d5caSAndrew Rist * distributed with this work for additional information
6*f6a9d5caSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6a9d5caSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6a9d5caSAndrew Rist * "License"); you may not use this file except in compliance
9*f6a9d5caSAndrew Rist * with the License. You may obtain a copy of the License at
10*f6a9d5caSAndrew Rist *
11*f6a9d5caSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6a9d5caSAndrew Rist *
13*f6a9d5caSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6a9d5caSAndrew Rist * software distributed under the License is distributed on an
15*f6a9d5caSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6a9d5caSAndrew Rist * KIND, either express or implied. See the License for the
17*f6a9d5caSAndrew Rist * specific language governing permissions and limitations
18*f6a9d5caSAndrew Rist * under the License.
19*f6a9d5caSAndrew Rist *
20*f6a9d5caSAndrew Rist *************************************************************/
21*f6a9d5caSAndrew Rist
22*f6a9d5caSAndrew Rist
23cdf0e10cSrcweir #ifndef SYMBOL_HXX
24cdf0e10cSrcweir #define SYMBOL_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <vos/refernce.hxx>
27cdf0e10cSrcweir #include <vcl/font.hxx>
28cdf0e10cSrcweir #include <tools/list.hxx>
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <tools/dynary.hxx>
31cdf0e10cSrcweir #include <svl/lstner.hxx>
32cdf0e10cSrcweir #include <svl/svarray.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <map>
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir #include <set>
37cdf0e10cSrcweir #include <functional>
38cdf0e10cSrcweir #include <algorithm>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include "unomodel.hxx"
41cdf0e10cSrcweir #include "utility.hxx"
42cdf0e10cSrcweir #include "smmod.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir #define SYMBOLSET_NONE 0xFFFF
46cdf0e10cSrcweir #define SYMBOL_NONE 0xFFFF
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
50cdf0e10cSrcweir
GetExportSymbolName(const String & rUiSymbolName)51cdf0e10cSrcweir inline const String GetExportSymbolName( const String &rUiSymbolName )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetExportSymbolName( rUiSymbolName );
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
56cdf0e10cSrcweir
GetUiSymbolName(const String & rExportSymbolName)57cdf0e10cSrcweir inline const String GetUiSymbolName( const String &rExportSymbolName )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetUiSymbolName( rExportSymbolName );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
GetExportSymbolSetName(const String & rUiSymbolSetName)62cdf0e10cSrcweir inline const String GetExportSymbolSetName( const String &rUiSymbolSetName )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetExportSymbolSetName( rUiSymbolSetName );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir
GetUiSymbolSetName(const String & rExportSymbolSetName)68cdf0e10cSrcweir inline const String GetUiSymbolSetName( const String &rExportSymbolSetName )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir return SM_MOD()->GetLocSymbolData().GetUiSymbolSetName( rExportSymbolSetName );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
74cdf0e10cSrcweir
75cdf0e10cSrcweir class SmSym
76cdf0e10cSrcweir {
77cdf0e10cSrcweir SmFace m_aFace;
78cdf0e10cSrcweir String m_aName;
79cdf0e10cSrcweir String m_aExportName;
80cdf0e10cSrcweir String m_aSetName;
81cdf0e10cSrcweir sal_UCS4 m_cChar;
82cdf0e10cSrcweir sal_Bool m_bPredefined;
83cdf0e10cSrcweir sal_Bool m_bDocSymbol;
84cdf0e10cSrcweir
85cdf0e10cSrcweir public:
86cdf0e10cSrcweir SmSym();
87cdf0e10cSrcweir SmSym(const String& rName, const Font& rFont, sal_UCS4 cChar,
88cdf0e10cSrcweir const String& rSet, sal_Bool bIsPredefined = sal_False);
89cdf0e10cSrcweir SmSym(const SmSym& rSymbol);
90cdf0e10cSrcweir
91cdf0e10cSrcweir SmSym& operator = (const SmSym& rSymbol);
92cdf0e10cSrcweir
GetFace() const93cdf0e10cSrcweir const Font& GetFace() const { return m_aFace; }
GetCharacter() const94cdf0e10cSrcweir sal_UCS4 GetCharacter() const { return m_cChar; }
GetName() const95cdf0e10cSrcweir const String& GetName() const { return m_aName; }
96cdf0e10cSrcweir
SetFace(const Font & rFont)97cdf0e10cSrcweir void SetFace( const Font& rFont ) { m_aFace = rFont; }
SetCharacter(sal_UCS4 cChar)98cdf0e10cSrcweir void SetCharacter( sal_UCS4 cChar ) { m_cChar = cChar; }
99cdf0e10cSrcweir
100cdf0e10cSrcweir //! since the symbol name is also used as key in the map it should not be possible to change the name
101cdf0e10cSrcweir //! because ten the key would not be the same as its supposed copy here
102cdf0e10cSrcweir // void SetName( const String &rTxt ) { m_aName = rTxt; }
103cdf0e10cSrcweir
IsPredefined() const104cdf0e10cSrcweir sal_Bool IsPredefined() const { return m_bPredefined; }
GetSymbolSetName() const105cdf0e10cSrcweir const String & GetSymbolSetName() const { return m_aSetName; }
SetSymbolSetName(const String & rName)106cdf0e10cSrcweir void SetSymbolSetName( const String &rName ) { m_aSetName = rName; }
GetExportName() const107cdf0e10cSrcweir const String & GetExportName() const { return m_aExportName; }
SetExportName(const String & rName)108cdf0e10cSrcweir void SetExportName( const String &rName ) { m_aExportName = rName; }
109cdf0e10cSrcweir
IsDocSymbol() const110cdf0e10cSrcweir sal_Bool IsDocSymbol() const { return m_bDocSymbol; }
SetDocSymbol(sal_Bool bVal)111cdf0e10cSrcweir void SetDocSymbol( sal_Bool bVal ) { m_bDocSymbol = bVal; }
112cdf0e10cSrcweir
113cdf0e10cSrcweir // true if rSymbol has the same name, font and character
114cdf0e10cSrcweir bool IsEqualInUI( const SmSym& rSymbol ) const;
115cdf0e10cSrcweir };
116cdf0e10cSrcweir
117cdf0e10cSrcweir /**************************************************************************/
118cdf0e10cSrcweir
119cdf0e10cSrcweir struct lt_String
120cdf0e10cSrcweir {
operator ()lt_String121cdf0e10cSrcweir bool operator()( const String &r1, const String &r2 ) const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir // r1 < r2 ?
124cdf0e10cSrcweir return r1.CompareTo( r2 ) == COMPARE_LESS;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir };
127cdf0e10cSrcweir
128cdf0e10cSrcweir
129cdf0e10cSrcweir // type of the actual container to hold the symbols
130cdf0e10cSrcweir typedef std::map< String, SmSym, lt_String > SymbolMap_t;
131cdf0e10cSrcweir
132cdf0e10cSrcweir // vector of pointers to the actual symbols in the above container
133cdf0e10cSrcweir typedef std::vector< const SmSym * > SymbolPtrVec_t;
134cdf0e10cSrcweir
135cdf0e10cSrcweir struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool >
136cdf0e10cSrcweir {
operator ()lt_SmSymPtr137cdf0e10cSrcweir bool operator() ( const SmSym *pSym1, const SmSym *pSym2 )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir return pSym1->GetCharacter() < pSym2->GetCharacter();
140cdf0e10cSrcweir }
141cdf0e10cSrcweir };
142cdf0e10cSrcweir
143cdf0e10cSrcweir
144cdf0e10cSrcweir class SmSymbolManager : public SfxListener
145cdf0e10cSrcweir {
146cdf0e10cSrcweir SymbolMap_t m_aSymbols;
147cdf0e10cSrcweir bool m_bModified;
148cdf0e10cSrcweir
149cdf0e10cSrcweir virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
150cdf0e10cSrcweir const SfxHint& rHint, const TypeId& rHintType);
151cdf0e10cSrcweir
152cdf0e10cSrcweir void Init();
153cdf0e10cSrcweir void Exit();
154cdf0e10cSrcweir
155cdf0e10cSrcweir public:
156cdf0e10cSrcweir SmSymbolManager();
157cdf0e10cSrcweir SmSymbolManager(const SmSymbolManager& rSymbolSetManager);
158cdf0e10cSrcweir ~SmSymbolManager();
159cdf0e10cSrcweir
160cdf0e10cSrcweir SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager);
161cdf0e10cSrcweir
162cdf0e10cSrcweir // symbol sets are for UI purpose only, thus we assemble them here
163cdf0e10cSrcweir std::set< String > GetSymbolSetNames() const;
164cdf0e10cSrcweir const SymbolPtrVec_t GetSymbolSet( const String& rSymbolSetName );
165cdf0e10cSrcweir
GetSymbolCount() const166cdf0e10cSrcweir sal_uInt16 GetSymbolCount() const { return static_cast< sal_uInt16 >(m_aSymbols.size()); }
167cdf0e10cSrcweir const SymbolPtrVec_t GetSymbols() const;
168cdf0e10cSrcweir bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false );
169cdf0e10cSrcweir void RemoveSymbol( const String & rSymbolName );
170cdf0e10cSrcweir
171cdf0e10cSrcweir SmSym * GetSymbolByName(const String& rSymbolName);
GetSymbolByName(const String & rSymbolName) const172cdf0e10cSrcweir const SmSym * GetSymbolByName(const String& rSymbolName) const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir return ((SmSymbolManager *) this)->GetSymbolByName(rSymbolName);
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
IsModified() const177cdf0e10cSrcweir bool IsModified() const { return m_bModified; }
SetModified(bool bModify)178cdf0e10cSrcweir void SetModified(bool bModify) { m_bModified = bModify; }
179cdf0e10cSrcweir
180cdf0e10cSrcweir void Load();
181cdf0e10cSrcweir void Save();
182cdf0e10cSrcweir };
183cdf0e10cSrcweir
184cdf0e10cSrcweir #endif
185cdf0e10cSrcweir
186