xref: /aoo42x/main/starmath/inc/symbol.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SYMBOL_HXX
28 #define SYMBOL_HXX
29 
30 #include <vos/refernce.hxx>
31 #include <vcl/font.hxx>
32 #include <tools/list.hxx>
33 #include <tools/debug.hxx>
34 #include <tools/dynary.hxx>
35 #include <svl/lstner.hxx>
36 #include <svl/svarray.hxx>
37 
38 #include <map>
39 #include <vector>
40 #include <set>
41 #include <functional>
42 #include <algorithm>
43 
44 #include "unomodel.hxx"
45 #include "utility.hxx"
46 #include "smmod.hxx"
47 
48 
49 #define SYMBOLSET_NONE  0xFFFF
50 #define SYMBOL_NONE		0xFFFF
51 
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 
55 inline const String GetExportSymbolName( const String &rUiSymbolName )
56 {
57     return SM_MOD()->GetLocSymbolData().GetExportSymbolName( rUiSymbolName );
58 }
59 
60 
61 inline const String GetUiSymbolName( const String &rExportSymbolName )
62 {
63     return SM_MOD()->GetLocSymbolData().GetUiSymbolName( rExportSymbolName );
64 }
65 
66 inline const String GetExportSymbolSetName( const String &rUiSymbolSetName )
67 {
68     return SM_MOD()->GetLocSymbolData().GetExportSymbolSetName( rUiSymbolSetName );
69 }
70 
71 
72 inline const String GetUiSymbolSetName( const String &rExportSymbolSetName )
73 {
74     return SM_MOD()->GetLocSymbolData().GetUiSymbolSetName( rExportSymbolSetName );
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
79 class SmSym
80 {
81     SmFace              m_aFace;
82     String              m_aName;
83     String              m_aExportName;
84     String              m_aSetName;
85     sal_UCS4            m_cChar;
86     sal_Bool                m_bPredefined;
87     sal_Bool                m_bDocSymbol;
88 
89 public:
90     SmSym();
91 	SmSym(const String& rName, const Font& rFont, sal_UCS4 cChar,
92 		  const String& rSet, sal_Bool bIsPredefined = sal_False);
93     SmSym(const SmSym& rSymbol);
94 
95 	SmSym&	   	operator = (const SmSym& rSymbol);
96 
97     const Font&     GetFace() const { return m_aFace; }
98     sal_UCS4        GetCharacter() const { return m_cChar; }
99     const String&   GetName() const { return m_aName; }
100 
101     void            SetFace( const Font& rFont )        { m_aFace = rFont; }
102     void            SetCharacter( sal_UCS4 cChar )   { m_cChar = cChar; }
103 
104 //! since the symbol name is also used as key in the map it should not be possible to change the name
105 //! because ten the key would not be the same as its supposed copy here
106 //    void            SetName( const String &rTxt )       { m_aName = rTxt; }
107 
108     sal_Bool            IsPredefined() const        { return m_bPredefined; }
109     const String &  GetSymbolSetName() const    { return m_aSetName; }
110     void            SetSymbolSetName( const String &rName )     { m_aSetName = rName; }
111     const String &  GetExportName() const       { return m_aExportName; }
112     void            SetExportName( const String &rName )        { m_aExportName = rName; }
113 
114     sal_Bool            IsDocSymbol() const         { return m_bDocSymbol; }
115     void            SetDocSymbol( sal_Bool bVal )   { m_bDocSymbol = bVal; }
116 
117     // true if rSymbol has the same name, font and character
118     bool            IsEqualInUI( const SmSym& rSymbol ) const;
119 };
120 
121 /**************************************************************************/
122 
123 struct lt_String
124 {
125     bool operator()( const String &r1, const String &r2 ) const
126     {
127         // r1 < r2 ?
128         return r1.CompareTo( r2 ) == COMPARE_LESS;
129     }
130 };
131 
132 
133 // type of the actual container to hold the symbols
134 typedef std::map< String, SmSym, lt_String >    SymbolMap_t;
135 
136 // vector of pointers to the actual symbols in the above container
137 typedef std::vector< const SmSym * >            SymbolPtrVec_t;
138 
139 struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool >
140 {
141     bool operator() ( const SmSym *pSym1, const SmSym *pSym2 )
142     {
143         return pSym1->GetCharacter() < pSym2->GetCharacter();
144     }
145 };
146 
147 
148 class SmSymbolManager : public SfxListener
149 {
150     SymbolMap_t         m_aSymbols;
151     bool                m_bModified;
152 
153 	virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
154 						const SfxHint& rHint, const TypeId& rHintType);
155 
156     void        Init();
157     void        Exit();
158 
159 public:
160     SmSymbolManager();
161     SmSymbolManager(const SmSymbolManager& rSymbolSetManager);
162     ~SmSymbolManager();
163 
164     SmSymbolManager &   operator = (const SmSymbolManager& rSymbolSetManager);
165 
166     // symbol sets are for UI purpose only, thus we assemble them here
167     std::set< String >      GetSymbolSetNames() const;
168     const SymbolPtrVec_t    GetSymbolSet(  const String& rSymbolSetName );
169 
170     sal_uInt16                  GetSymbolCount() const  { return static_cast< sal_uInt16 >(m_aSymbols.size()); }
171     const SymbolPtrVec_t    GetSymbols() const;
172     bool                    AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false );
173     void                    RemoveSymbol( const String & rSymbolName );
174 
175 	SmSym	    *	GetSymbolByName(const String& rSymbolName);
176 	const SmSym *	GetSymbolByName(const String& rSymbolName) const
177 	{
178         return ((SmSymbolManager *) this)->GetSymbolByName(rSymbolName);
179 	}
180 
181     bool        IsModified() const          { return m_bModified; }
182     void        SetModified(bool bModify)   { m_bModified = bModify; }
183 
184     void        Load();
185     void        Save();
186 };
187 
188 #endif
189 
190