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 SYMBOL_NONE 0xFFFF
38 :
39 :
40 :
41 :
42 : inline const OUString GetExportSymbolName( const OUString &rUiSymbolName )
43 : {
44 : return SmLocalizedSymbolData::GetExportSymbolName( rUiSymbolName );
45 : }
46 :
47 :
48 660 : inline const OUString GetUiSymbolName( const OUString &rExportSymbolName )
49 : {
50 660 : return SmLocalizedSymbolData::GetUiSymbolName( rExportSymbolName );
51 : }
52 :
53 130 : inline const OUString GetExportSymbolSetName( const OUString &rUiSymbolSetName )
54 : {
55 130 : return SmLocalizedSymbolData::GetExportSymbolSetName( rUiSymbolSetName );
56 : }
57 :
58 :
59 660 : inline const OUString GetUiSymbolSetName( const OUString &rExportSymbolSetName )
60 : {
61 660 : return SmLocalizedSymbolData::GetUiSymbolSetName( rExportSymbolSetName );
62 : }
63 :
64 :
65 :
66 1860 : class SmSym
67 : {
68 : private:
69 : SmFace m_aFace;
70 : OUString m_aName;
71 : OUString m_aExportName;
72 : OUString m_aSetName;
73 : sal_UCS4 m_cChar;
74 : bool m_bPredefined;
75 : bool m_bDocSymbol;
76 :
77 : public:
78 : SmSym();
79 : SmSym(const OUString& rName, const vcl::Font& rFont, sal_UCS4 cChar,
80 : const OUString& rSet, bool bIsPredefined = false);
81 : SmSym(const SmSym& rSymbol);
82 :
83 : SmSym& operator = (const SmSym& rSymbol);
84 :
85 670 : const vcl::Font& GetFace() const { return m_aFace; }
86 670 : sal_UCS4 GetCharacter() const { return m_cChar; }
87 2400 : const OUString& GetName() const { return m_aName; }
88 :
89 : void SetFace( const vcl::Font& rFont ) { m_aFace = rFont; }
90 : void SetCharacter( sal_UCS4 cChar ) { m_cChar = cChar; }
91 :
92 134640 : bool IsPredefined() const { return m_bPredefined; }
93 1990 : const OUString& GetSymbolSetName() const { return m_aSetName; }
94 : void SetSymbolSetName( const OUString &rName ) { m_aSetName = rName; }
95 0 : const OUString& GetExportName() const { return m_aExportName; }
96 0 : void SetExportName( const OUString &rName ) { m_aExportName = rName; }
97 :
98 : bool IsDocSymbol() const { return m_bDocSymbol; }
99 0 : void SetDocSymbol( bool bVal ) { m_bDocSymbol = bVal; }
100 :
101 : // true if rSymbol has the same name, font and character
102 : bool IsEqualInUI( const SmSym& rSymbol ) const;
103 : };
104 :
105 : // type of the actual container to hold the symbols
106 : typedef std::map< OUString, SmSym > SymbolMap_t;
107 :
108 : // vector of pointers to the actual symbols in the above container
109 : typedef std::vector< const SmSym * > SymbolPtrVec_t;
110 :
111 : struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool >
112 : {
113 0 : bool operator() ( const SmSym *pSym1, const SmSym *pSym2 ) const
114 : {
115 0 : return pSym1->GetCharacter() < pSym2->GetCharacter();
116 : }
117 : };
118 :
119 :
120 : class SmSymbolManager : public SfxListener
121 : {
122 : private:
123 : SymbolMap_t m_aSymbols;
124 : bool m_bModified;
125 :
126 : virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
127 : const SfxHint& rHint, const TypeId& rHintType) SAL_OVERRIDE;
128 :
129 : public:
130 : SmSymbolManager();
131 : SmSymbolManager(const SmSymbolManager& rSymbolSetManager);
132 : virtual ~SmSymbolManager();
133 :
134 : SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager);
135 :
136 : // symbol sets are for UI purpose only, thus we assemble them here
137 : std::set< OUString > GetSymbolSetNames() const;
138 : const SymbolPtrVec_t GetSymbolSet( const OUString& rSymbolSetName );
139 :
140 : const SymbolPtrVec_t GetSymbols() const;
141 : bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false );
142 : void RemoveSymbol( const OUString & rSymbolName );
143 :
144 : SmSym * GetSymbolByName(const OUString& rSymbolName);
145 : const SmSym * GetSymbolByName(const OUString& rSymbolName) const
146 : {
147 : return const_cast<SmSymbolManager *>(this)->GetSymbolByName(rSymbolName);
148 : }
149 :
150 0 : bool IsModified() const { return m_bModified; }
151 1860 : void SetModified(bool bModify) { m_bModified = bModify; }
152 :
153 : void Load();
154 : void Save();
155 : };
156 :
157 : #endif
158 :
159 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|