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