Branch data 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 SYMBOL_HXX
21 : : #define 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 String GetExportSymbolName( const String &rUiSymbolName )
44 : : {
45 : : return SM_MOD()->GetLocSymbolData().GetExportSymbolName( rUiSymbolName );
46 : : }
47 : :
48 : :
49 : 396 : inline const String GetUiSymbolName( const String &rExportSymbolName )
50 : : {
51 : 396 : return SM_MOD()->GetLocSymbolData().GetUiSymbolName( rExportSymbolName );
52 : : }
53 : :
54 : 0 : inline const String GetExportSymbolSetName( const String &rUiSymbolSetName )
55 : : {
56 : 0 : return SM_MOD()->GetLocSymbolData().GetExportSymbolSetName( rUiSymbolSetName );
57 : : }
58 : :
59 : :
60 : 396 : inline const String GetUiSymbolSetName( const String &rExportSymbolSetName )
61 : : {
62 : 396 : return SM_MOD()->GetLocSymbolData().GetUiSymbolSetName( rExportSymbolSetName );
63 : : }
64 : :
65 : : ////////////////////////////////////////////////////////////////////////////////
66 : :
67 [ + - ][ + - ]: 2556 : class SmSym
[ + - ]
68 : : {
69 : : private:
70 : : SmFace m_aFace;
71 : : String m_aName;
72 : : String m_aExportName;
73 : : String m_aSetName;
74 : : sal_UCS4 m_cChar;
75 : : bool m_bPredefined;
76 : : bool m_bDocSymbol;
77 : :
78 : : public:
79 : : SmSym();
80 : : SmSym(const String& rName, const Font& rFont, sal_UCS4 cChar,
81 : : const String& rSet, bool bIsPredefined = false);
82 : : SmSym(const SmSym& rSymbol);
83 : :
84 : : SmSym& operator = (const SmSym& rSymbol);
85 : :
86 : 324 : const Font& GetFace() const { return m_aFace; }
87 : 324 : sal_UCS4 GetCharacter() const { return m_cChar; }
88 : 1440 : const String& GetName() const { return m_aName; }
89 : :
90 : : void SetFace( const Font& rFont ) { m_aFace = rFont; }
91 : : void SetCharacter( sal_UCS4 cChar ) { m_cChar = cChar; }
92 : :
93 : : //! since the symbol name is also used as key in the map it should not be possible to change the name
94 : : //! because ten the key would not be the same as its supposed copy here
95 : : // void SetName( const String &rTxt ) { m_aName = rTxt; }
96 : :
97 : 204480 : bool IsPredefined() const { return m_bPredefined; }
98 : 1116 : const String & GetSymbolSetName() const { return m_aSetName; }
99 : : void SetSymbolSetName( const String &rName ) { m_aSetName = rName; }
100 : 0 : const String & GetExportName() const { return m_aExportName; }
101 : 0 : void SetExportName( const String &rName ) { m_aExportName = rName; }
102 : :
103 : : bool IsDocSymbol() const { return m_bDocSymbol; }
104 : 0 : void SetDocSymbol( bool bVal ) { m_bDocSymbol = bVal; }
105 : :
106 : : // true if rSymbol has the same name, font and character
107 : : bool IsEqualInUI( const SmSym& rSymbol ) const;
108 : : };
109 : :
110 : : /**************************************************************************/
111 : :
112 : : struct lt_String
113 : : {
114 : 14112 : bool operator()( const String &r1, const String &r2 ) const
115 : : {
116 : : // r1 < r2 ?
117 : 14112 : return r1.CompareTo( r2 ) == COMPARE_LESS;
118 : : }
119 : : };
120 : :
121 : :
122 : : // type of the actual container to hold the symbols
123 : : typedef std::map< String, SmSym, lt_String > SymbolMap_t;
124 : :
125 : : // vector of pointers to the actual symbols in the above container
126 : : typedef std::vector< const SmSym * > SymbolPtrVec_t;
127 : :
128 : : struct lt_SmSymPtr : public std::binary_function< const SmSym *, const SmSym *, bool >
129 : : {
130 : 0 : bool operator() ( const SmSym *pSym1, const SmSym *pSym2 ) const
131 : : {
132 : 0 : return pSym1->GetCharacter() < pSym2->GetCharacter();
133 : : }
134 : : };
135 : :
136 : :
137 : : class SmSymbolManager : public SfxListener
138 : : {
139 : : private:
140 : : SymbolMap_t m_aSymbols;
141 : : bool m_bModified;
142 : :
143 : : virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType,
144 : : const SfxHint& rHint, const TypeId& rHintType);
145 : :
146 : : public:
147 : : SmSymbolManager();
148 : : SmSymbolManager(const SmSymbolManager& rSymbolSetManager);
149 : : ~SmSymbolManager();
150 : :
151 : : SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager);
152 : :
153 : : // symbol sets are for UI purpose only, thus we assemble them here
154 : : std::set< String > GetSymbolSetNames() const;
155 : : const SymbolPtrVec_t GetSymbolSet( const String& rSymbolSetName );
156 : :
157 : : sal_uInt16 GetSymbolCount() const { return static_cast< sal_uInt16 >(m_aSymbols.size()); }
158 : : const SymbolPtrVec_t GetSymbols() const;
159 : : bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false );
160 : : void RemoveSymbol( const String & rSymbolName );
161 : :
162 : : SmSym * GetSymbolByName(const String& rSymbolName);
163 : : const SmSym * GetSymbolByName(const String& rSymbolName) const
164 : : {
165 : : return ((SmSymbolManager *) this)->GetSymbolByName(rSymbolName);
166 : : }
167 : :
168 : 0 : bool IsModified() const { return m_bModified; }
169 : 2556 : void SetModified(bool bModify) { m_bModified = bModify; }
170 : :
171 : : void Load();
172 : : void Save();
173 : : };
174 : :
175 : : #endif
176 : :
177 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|