/src/libreoffice/starmath/inc/cfgitem.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include "utility.hxx" |
23 | | |
24 | | #include <string_view> |
25 | | #include <rtl/ustring.hxx> |
26 | | #include <svl/SfxBroadcaster.hxx> |
27 | | #include <unotools/configitem.hxx> |
28 | | |
29 | | #include "types.hxx" |
30 | | |
31 | | class SmSym; |
32 | | class SmSymbolManager; |
33 | | class SmFormat; |
34 | | namespace vcl |
35 | | { |
36 | | class Font; |
37 | | } |
38 | | struct SmCfgOther; |
39 | | class SfxItemSet; |
40 | | |
41 | | struct SmFontFormat |
42 | | { |
43 | | OUString aName; |
44 | | sal_Int16 nCharSet; |
45 | | sal_Int16 nFamily; |
46 | | sal_Int16 nPitch; |
47 | | sal_Int16 nWeight; |
48 | | sal_Int16 nItalic; |
49 | | |
50 | | SmFontFormat(); |
51 | | explicit SmFontFormat(const vcl::Font& rFont); |
52 | | |
53 | | vcl::Font GetFont() const; |
54 | | bool operator==(const SmFontFormat& rFntFmt) const; |
55 | | }; |
56 | | |
57 | | struct SmFntFmtListEntry |
58 | | { |
59 | | OUString aId; |
60 | | SmFontFormat aFntFmt; |
61 | | |
62 | | SmFntFmtListEntry(OUString aId, SmFontFormat rFntFmt); |
63 | | }; |
64 | | |
65 | | class SmFontFormatList |
66 | | { |
67 | | std::vector<SmFntFmtListEntry> aEntries; |
68 | | bool bModified; |
69 | | |
70 | | SmFontFormatList(const SmFontFormatList&) = delete; |
71 | | SmFontFormatList& operator=(const SmFontFormatList&) = delete; |
72 | | |
73 | | public: |
74 | | SmFontFormatList(); |
75 | | |
76 | | void Clear(); |
77 | | void AddFontFormat(const OUString& rFntFmtId, const SmFontFormat& rFntFmt); |
78 | | void RemoveFontFormat(std::u16string_view rFntFmtId); |
79 | | |
80 | | const SmFontFormat* GetFontFormat(std::u16string_view rFntFmtId) const; |
81 | | const SmFontFormat* GetFontFormat(size_t nPos) const; |
82 | | OUString GetFontFormatId(const SmFontFormat& rFntFmt) const; |
83 | | OUString GetFontFormatId(const SmFontFormat& rFntFmt, bool bAdd); |
84 | | OUString GetFontFormatId(size_t nPos) const; |
85 | | OUString GetNewFontFormatId() const; |
86 | 0 | size_t GetCount() const { return aEntries.size(); } |
87 | | |
88 | 0 | bool IsModified() const { return bModified; } |
89 | 0 | void SetModified(bool bVal) { bModified = bVal; } |
90 | | }; |
91 | | |
92 | | class SmMathConfig final : public utl::ConfigItem, public SfxBroadcaster |
93 | | { |
94 | | std::unique_ptr<SmFormat> pFormat; |
95 | | std::unique_ptr<SmCfgOther> pOther; |
96 | | std::unique_ptr<SmFontFormatList> pFontFormatList; |
97 | | std::unique_ptr<SmSymbolManager> pSymbolMgr; |
98 | | css::uno::Sequence<OUString> m_sUserDefinedNames; |
99 | | bool bIsOtherModified; |
100 | | bool bIsFormatModified; |
101 | | SmFontPickList vFontPickList[8]; |
102 | | sal_Int32 m_nCommitLock = 0; |
103 | | |
104 | | SmMathConfig(const SmMathConfig&) = delete; |
105 | | SmMathConfig& operator=(const SmMathConfig&) = delete; |
106 | | |
107 | | void StripFontFormatList(const std::vector<SmSym>& rSymbols); |
108 | | |
109 | | void Save(); |
110 | | |
111 | | void ReadSymbol(SmSym& rSymbol, const OUString& rSymbolName, |
112 | | std::u16string_view rBaseNode) const; |
113 | | void ReadFontFormat(SmFontFormat& rFontFormat, std::u16string_view rSymbolName, |
114 | | std::u16string_view rBaseNode) const; |
115 | | |
116 | | bool SetOtherIfNotEqual(bool& rbItem, bool bNewVal); |
117 | | |
118 | | void LoadOther(); |
119 | | void SaveOther(); |
120 | | void LoadFormat(); |
121 | | void SaveFormat(); |
122 | | void LoadFontFormatList(); |
123 | | void SaveFontFormatList(); |
124 | | |
125 | | void SetOtherModified(bool bVal); |
126 | 0 | bool IsOtherModified() const { return bIsOtherModified; } |
127 | | void SetFormatModified(bool bVal); |
128 | 0 | bool IsFormatModified() const { return bIsFormatModified; } |
129 | | |
130 | | SmFontFormatList& GetFontFormatList(); |
131 | | const SmFontFormatList& GetFontFormatList() const |
132 | 0 | { |
133 | 0 | return const_cast<SmMathConfig*>(this)->GetFontFormatList(); |
134 | 0 | } |
135 | | |
136 | | virtual void ImplCommit() override; |
137 | 0 | void LockCommit() { ++m_nCommitLock; } |
138 | | void UnlockCommit(); |
139 | | // Used to avoid tens of atomic commits in e.g. ItemSetToConfig that calls individual setters |
140 | | friend struct CommitLocker; |
141 | | struct CommitLocker |
142 | | { |
143 | | SmMathConfig& m_rConfig; |
144 | | CommitLocker(SmMathConfig& rConfig) |
145 | 0 | : m_rConfig(rConfig) |
146 | 0 | { |
147 | 0 | m_rConfig.LockCommit(); |
148 | 0 | } |
149 | 0 | ~CommitLocker() { m_rConfig.UnlockCommit(); } |
150 | | }; |
151 | | |
152 | | void Clear(); |
153 | | |
154 | | public: |
155 | | SmMathConfig(); |
156 | | virtual ~SmMathConfig() override; |
157 | | |
158 | | // utl::ConfigItem |
159 | | virtual void Notify(const css::uno::Sequence<OUString>& rPropertyNames) override; |
160 | | |
161 | | SmSymbolManager& GetSymbolManager(); |
162 | | void GetSymbols(std::vector<SmSym>& rSymbols) const; |
163 | | void SetSymbols(const std::vector<SmSym>& rNewSymbols); |
164 | | |
165 | | const SmFormat& GetStandardFormat() const; |
166 | | void SetStandardFormat(const SmFormat& rFormat, bool bSaveFontFormatList = false); |
167 | | |
168 | | css::uno::Sequence<OUString> LoadUserDefinedNames(); |
169 | | void GetUserDefinedFormula(std::u16string_view sName, OUString& sFormula); |
170 | | bool HasUserDefinedFormula(std::u16string_view sName); |
171 | | void SaveUserDefinedFormula(std::u16string_view sName, const OUString& sElement); |
172 | | void DeleteUserDefinedFormula(std::u16string_view sName); |
173 | | |
174 | | bool IsPrintTitle() const; |
175 | | void SetPrintTitle(bool bVal); |
176 | | bool IsPrintFormulaText() const; |
177 | | void SetPrintFormulaText(bool bVal); |
178 | | bool IsPrintFrame() const; |
179 | | void SetPrintFrame(bool bVal); |
180 | | SmPrintSize GetPrintSize() const; |
181 | | void SetPrintSize(SmPrintSize eSize); |
182 | | sal_uInt16 GetPrintZoomFactor() const; |
183 | | void SetPrintZoomFactor(sal_uInt16 nVal); |
184 | | sal_uInt16 GetSmEditWindowZoomFactor() const; |
185 | | void SetSmEditWindowZoomFactor(sal_uInt16 nVal); |
186 | | |
187 | | bool IsSaveOnlyUsedSymbols() const; |
188 | | void SetSaveOnlyUsedSymbols(bool bVal); |
189 | | bool IsAutoCloseBrackets() const; |
190 | | void SetAutoCloseBrackets(bool bVal); |
191 | | bool IsInlineEditEnable() const; |
192 | | void SetInlineEditEnable(bool bVal); |
193 | | bool IsIgnoreSpacesRight() const; |
194 | | void SetIgnoreSpacesRight(bool bVal); |
195 | | bool IsAutoRedraw() const; |
196 | | void SetAutoRedraw(bool bVal); |
197 | | bool IsShowFormulaCursor() const; |
198 | | void SetShowFormulaCursor(bool bVal); |
199 | | |
200 | | sal_Int16 GetDefaultSmSyntaxVersion() const; |
201 | | void SetDefaultSmSyntaxVersion(sal_Int16 nVal); |
202 | | |
203 | 0 | SmFontPickList& GetFontPickList(sal_uInt16 nIdent) { return vFontPickList[nIdent]; } |
204 | | |
205 | | void ItemSetToConfig(const SfxItemSet& rSet); |
206 | | void ConfigToItemSet(SfxItemSet& rSet) const; |
207 | | }; |
208 | | |
209 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |