| 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 | /** This stuff is used to work with %charname. |
| 21 | * |
| 22 | * Will remember the char name, char code and font. |
| 23 | */ |
| 24 | |
| 25 | #pragma once |
| 26 | |
| 27 | #include <map> |
| 28 | #include <vector> |
| 29 | #include <set> |
| 30 | |
| 31 | #include "format.hxx" |
| 32 | #include "utility.hxx" |
| 33 | |
| 34 | |
| 35 | #define SYMBOL_NONE 0xFFFF |
| 36 | |
| 37 | class SmSym |
| 38 | { |
| 39 | private: |
| 40 | SmFace m_aFace; |
| 41 | OUString m_aUiName; |
| 42 | OUString m_aExportName; |
| 43 | OUString m_aSetName; |
| 44 | sal_UCS4 m_cChar; |
| 45 | bool m_bPredefined; |
| 46 | |
| 47 | public: |
| 48 | SmSym(); |
| 49 | SmSym(const OUString& rName, const vcl::Font& rFont, sal_UCS4 cChar, |
| 50 | const OUString& rSet, bool bIsPredefined = false); |
| 51 | SmSym(const SmSym& rSymbol); |
| 52 | |
| 53 | SmSym& operator = (const SmSym& rSymbol); |
| 54 | |
| 55 | const vcl::Font& GetFace(const SmFormat* pFormat = nullptr) const; |
| 56 | sal_UCS4 GetCharacter() const { return m_cChar; } |
| 57 | const OUString& GetUiName() const { return m_aUiName; } |
| 58 | |
| 59 | bool IsPredefined() const { return m_bPredefined; } |
| 60 | const OUString& GetSymbolSetName() const { return m_aSetName; } |
| 61 | const OUString& GetExportName() const { return m_aExportName; } |
| 62 | void SetExportName( const OUString &rName ) { m_aExportName = rName; } |
| 63 | |
| 64 | // true if rSymbol has the same name, font and character |
| 65 | bool IsEqualInUI( const SmSym& rSymbol ) const; |
| 66 | }; |
| 67 | |
| 68 | // type of the actual container to hold the symbols |
| 69 | typedef std::map< OUString, SmSym > SymbolMap_t; |
| 70 | |
| 71 | // vector of pointers to the actual symbols in the above container |
| 72 | typedef std::vector< const SmSym * > SymbolPtrVec_t; |
| 73 | |
| 74 | |
| 75 | class SmSymbolManager |
| 76 | { |
| 77 | private: |
| 78 | SymbolMap_t m_aSymbols; |
| 79 | bool m_bModified; |
| 80 | |
| 81 | public: |
| 82 | SmSymbolManager(); |
| 83 | SmSymbolManager(const SmSymbolManager& rSymbolSetManager); |
| 84 | ~SmSymbolManager(); |
| 85 | |
| 86 | SmSymbolManager & operator = (const SmSymbolManager& rSymbolSetManager); |
| 87 | |
| 88 | // symbol sets are for UI purpose only, thus we assemble them here |
| 89 | std::set< OUString > GetSymbolSetNames() const; |
| 90 | SymbolPtrVec_t GetSymbolSet( std::u16string_view rSymbolSetName ); |
| 91 | |
| 92 | SymbolPtrVec_t GetSymbols() const; |
| 93 | bool AddOrReplaceSymbol( const SmSym & rSymbol, bool bForceChange = false ); |
| 94 | void RemoveSymbol( const OUString & rSymbolName ); |
| 95 | |
| 96 | SmSym* GetSymbolByName(std::u16string_view rSymbolName); |
| 97 | SmSym* GetSymbolByUiName(std::u16string_view rSymbolName); |
| 98 | SmSym* GetSymbolByExportName(std::u16string_view rSymbolName); |
| 99 | |
| 100 | bool IsModified() const { return m_bModified; } |
| 101 | void SetModified(bool bModify) { m_bModified = bModify; } |
| 102 | |
| 103 | void Load(); |
| 104 | void Save(); |
| 105 | }; |
| 106 | |
| 107 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |