Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_STARMATH_INC_SYMBOL_HXX
21 : #define INCLUDED_STARMATH_INC_SYMBOL_HXX
22 :
23 : #include <vcl/font.hxx>
24 : #include <svl/lstner.hxx>
25 :
26 : #include <map>
27 : #include <vector>
28 : #include <set>
29 : #include <functional>
30 : #include <algorithm>
31 :
32 : #include "unomodel.hxx"
33 : #include "utility.hxx"
34 : #include "smmod.hxx"
35 :
36 :
37 : #define SYMBOLSET_NONE 0xFFFF
38 : #define SYMBOL_NONE 0xFFFF
39 :
40 :
41 :
42 :
43 : inline const OUString GetExportSymbolName( const OUString &rUiSymbolName )
44 : {
45 : return SM_MOD()->GetLocSymbolData().GetExportSymbolName( rUiSymbolName );
46 : }
47 :
48 :
49 1320 : inline const OUString GetUiSymbolName( const OUString &rExportSymbolName )
50 : {
51 1320 : return SM_MOD()->GetLocSymbolData().GetUiSymbolName( rExportSymbolName );
52 : }
53 :
54 260 : inline const OUString GetExportSymbolSetName( const OUString &rUiSymbolSetName )
55 : {
56 260 : return SM_MOD()->GetLocSymbolData().GetExportSymbolSetName( rUiSymbolSetName );
57 : }
58 :
59 :
60 1320 : inline const OUString GetUiSymbolSetName( const OUString &rExportSymbolSetName )
61 : {
62 1320 : return SM_MOD()->GetLocSymbolData().GetUiSymbolSetName( rExportSymbolSetName );
63 : }
64 :
65 :
66 :
67 3720 : class SmSym
68 : {
69 : private:
70 : SmFace m_aFace;
71 : OUString m_aName;
72 : OUString m_aExportName;
73 : OUString m_aSetName;
74 : sal_UCS4 m_cChar;
75 : bool m_bPredefined;
76 : bool m_bDocSymbol;
77 :
78 : public:
79 : SmSym();
80 : SmSym(const OUString& rName, const vcl::Font& rFont, sal_UCS4 cChar,
81 : const OUString& rSet, bool bIsPredefined = false);
82 : SmSym(const SmSym& rSymbol);
83 :
84 : SmSym& operator = (const SmSym& rSymbol);
85 :
86 1340 : const vcl::Font& GetFace() const { return m_aFace; }
87 1340 : sal_UCS4 GetCharacter() const { return m_cChar; }
88 4800 : const OUString& GetName() const { return m_aName; }
89 :
90 : void SetFace( const vcl::Font& rFont ) { m_aFace = rFont; }
91 : void SetCharacter( sal_UCS4 cChar ) { m_cChar = cChar; }
92 :
93 268320 : bool IsPredefined() const { return m_bPredefined; }
94 3980 : const OUString& GetSymbolSetName() const { return m_aSetName; }
95 : void SetSymbolSetName( const OUString &rName ) { m_aSetName = rName; }
96 0 : const OUString& GetExportName() const { return m_aExportName; }
97 0 : void SetExportName( const OUString &rName ) { m_aExportName = rName; }
98 :
99 : bool IsDocSymbol() const { return m_bDocSymbol; }
100 0 : void SetDocSymbol( bool bVal ) { m_bDocSymbol = bVal; }
101 :
102 : // true if rSymbol has the same name, font and character
103 : bool IsEqualInUI( const SmSym& rSymbol ) const;
104 : };
105 :
106 : // type of the actual container to hold the symbols
107 : typedef std::map< OUString, SmSym > SymbolMap_t;
108 :
109 : // vector of pointers to the actual symbols in the above container
110 : typedef std::vector< const SmSym * > SymbolPtrVec_t;
111 :
112 : struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool >
113 : {
114 0 : bool operator() ( const SmSym *pSym1, const SmSym *pSym2 ) const
115 : {
116 0 : return pSym1->GetCharacter() < pSym2->GetCharacter();
117 : }
118 : };
119 :
120 :
121 : class SmSymbolManager : public SfxListener
122 : {
123 : private:
124 : SymbolMap_t m_aSymbols;
125 : bool m_bModified;
126 :
127 : virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
128 : const SfxHint& rHint, const TypeId& rHintType) SAL_OVERRIDE;
129 :
130 : public:
131 : SmSymbolManager();
132 : SmSymbolManager(const SmSymbolManager& rSymbolSetManager);
133 : virtual ~SmSymbolManager();
134 :
135 : SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager);
136 :
137 : // symbol sets are for UI purpose only, thus we assemble them here
138 : std::set< OUString > GetSymbolSetNames() const;
139 : const SymbolPtrVec_t GetSymbolSet( const OUString& rSymbolSetName );
140 :
141 : sal_uInt16 GetSymbolCount() const { return static_cast< sal_uInt16 >(m_aSymbols.size()); }
142 : const SymbolPtrVec_t GetSymbols() const;
143 : bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false );
144 : void RemoveSymbol( const OUString & rSymbolName );
145 :
146 : SmSym * GetSymbolByName(const OUString& rSymbolName);
147 : const SmSym * GetSymbolByName(const OUString& rSymbolName) const
148 : {
149 : return ((SmSymbolManager *) this)->GetSymbolByName(rSymbolName);
150 : }
151 :
152 0 : bool IsModified() const { return m_bModified; }
153 3720 : void SetModified(bool bModify) { m_bModified = bModify; }
154 :
155 : void Load();
156 : void Save();
157 : };
158 :
159 : #endif
160 :
161 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|