tdf#150927: properly handle nesting in tables
[LibreOffice.git] / starmath / inc / cfgitem.hxx
blob607f92d4e1b0686a031150e921a941b3a23b05f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "utility.hxx"
24 #include <string_view>
25 #include <rtl/ustring.hxx>
26 #include <svl/SfxBroadcaster.hxx>
27 #include <unotools/configitem.hxx>
29 #include "types.hxx"
31 namespace com::sun::star::uno
33 template <class E> class Sequence;
36 class SmSym;
37 class SmSymbolManager;
38 class SmFormat;
39 namespace vcl
41 class Font;
43 struct SmCfgOther;
44 class SfxItemSet;
46 struct SmFontFormat
48 OUString aName;
49 sal_Int16 nCharSet;
50 sal_Int16 nFamily;
51 sal_Int16 nPitch;
52 sal_Int16 nWeight;
53 sal_Int16 nItalic;
55 SmFontFormat();
56 explicit SmFontFormat(const vcl::Font& rFont);
58 vcl::Font GetFont() const;
59 bool operator==(const SmFontFormat& rFntFmt) const;
62 struct SmFntFmtListEntry
64 OUString aId;
65 SmFontFormat aFntFmt;
67 SmFntFmtListEntry(OUString aId, SmFontFormat rFntFmt);
70 class SmFontFormatList
72 std::vector<SmFntFmtListEntry> aEntries;
73 bool bModified;
75 SmFontFormatList(const SmFontFormatList&) = delete;
76 SmFontFormatList& operator=(const SmFontFormatList&) = delete;
78 public:
79 SmFontFormatList();
81 void Clear();
82 void AddFontFormat(const OUString& rFntFmtId, const SmFontFormat& rFntFmt);
83 void RemoveFontFormat(std::u16string_view rFntFmtId);
85 const SmFontFormat* GetFontFormat(std::u16string_view rFntFmtId) const;
86 const SmFontFormat* GetFontFormat(size_t nPos) const;
87 OUString GetFontFormatId(const SmFontFormat& rFntFmt) const;
88 OUString GetFontFormatId(const SmFontFormat& rFntFmt, bool bAdd);
89 OUString GetFontFormatId(size_t nPos) const;
90 OUString GetNewFontFormatId() const;
91 size_t GetCount() const { return aEntries.size(); }
93 bool IsModified() const { return bModified; }
94 void SetModified(bool bVal) { bModified = bVal; }
97 class SmMathConfig final : public utl::ConfigItem, public SfxBroadcaster
99 std::unique_ptr<SmFormat> pFormat;
100 std::unique_ptr<SmCfgOther> pOther;
101 std::unique_ptr<SmFontFormatList> pFontFormatList;
102 std::unique_ptr<SmSymbolManager> pSymbolMgr;
103 bool bIsOtherModified;
104 bool bIsFormatModified;
105 SmFontPickList vFontPickList[7];
106 sal_Int32 m_nCommitLock = 0;
108 SmMathConfig(const SmMathConfig&) = delete;
109 SmMathConfig& operator=(const SmMathConfig&) = delete;
111 void StripFontFormatList(const std::vector<SmSym>& rSymbols);
113 void Save();
115 void ReadSymbol(SmSym& rSymbol, const OUString& rSymbolName,
116 std::u16string_view rBaseNode) const;
117 void ReadFontFormat(SmFontFormat& rFontFormat, std::u16string_view rSymbolName,
118 std::u16string_view rBaseNode) const;
120 bool SetOtherIfNotEqual(bool& rbItem, bool bNewVal);
122 void LoadOther();
123 void SaveOther();
124 void LoadFormat();
125 void SaveFormat();
126 void LoadFontFormatList();
127 void SaveFontFormatList();
129 void SetOtherModified(bool bVal);
130 bool IsOtherModified() const { return bIsOtherModified; }
131 void SetFormatModified(bool bVal);
132 bool IsFormatModified() const { return bIsFormatModified; }
134 SmFontFormatList& GetFontFormatList();
135 const SmFontFormatList& GetFontFormatList() const
137 return const_cast<SmMathConfig*>(this)->GetFontFormatList();
140 virtual void ImplCommit() override;
141 void LockCommit() { ++m_nCommitLock; }
142 void UnlockCommit();
143 // Used to avoid tens of atomic commits in e.g. ItemSetToConfig that calls individual setters
144 friend struct CommitLocker;
145 struct CommitLocker
147 SmMathConfig& m_rConfig;
148 CommitLocker(SmMathConfig& rConfig)
149 : m_rConfig(rConfig)
151 m_rConfig.LockCommit();
153 ~CommitLocker() { m_rConfig.UnlockCommit(); }
156 void Clear();
158 public:
159 SmMathConfig();
160 virtual ~SmMathConfig() override;
162 // utl::ConfigItem
163 virtual void Notify(const css::uno::Sequence<OUString>& rPropertyNames) override;
165 SmSymbolManager& GetSymbolManager();
166 void GetSymbols(std::vector<SmSym>& rSymbols) const;
167 void SetSymbols(const std::vector<SmSym>& rNewSymbols);
169 const SmFormat& GetStandardFormat() const;
170 void SetStandardFormat(const SmFormat& rFormat, bool bSaveFontFormatList = false);
172 bool IsPrintTitle() const;
173 void SetPrintTitle(bool bVal);
174 bool IsPrintFormulaText() const;
175 void SetPrintFormulaText(bool bVal);
176 bool IsPrintFrame() const;
177 void SetPrintFrame(bool bVal);
178 SmPrintSize GetPrintSize() const;
179 void SetPrintSize(SmPrintSize eSize);
180 sal_uInt16 GetPrintZoomFactor() const;
181 void SetPrintZoomFactor(sal_uInt16 nVal);
182 sal_uInt16 GetSmEditWindowZoomFactor() const;
183 void SetSmEditWindowZoomFactor(sal_uInt16 nVal);
185 bool IsSaveOnlyUsedSymbols() const;
186 void SetSaveOnlyUsedSymbols(bool bVal);
187 bool IsAutoCloseBrackets() const;
188 void SetAutoCloseBrackets(bool bVal);
189 bool IsIgnoreSpacesRight() const;
190 void SetIgnoreSpacesRight(bool bVal);
191 bool IsAutoRedraw() const;
192 void SetAutoRedraw(bool bVal);
193 bool IsShowFormulaCursor() const;
194 void SetShowFormulaCursor(bool bVal);
196 sal_uInt16 GetDefaultSmSyntaxVersion() const;
197 void SetDefaultSmSyntaxVersion(sal_uInt16 nVal);
199 SmFontPickList& GetFontPickList(sal_uInt16 nIdent) { return vFontPickList[nIdent]; }
201 void ItemSetToConfig(const SfxItemSet& rSet);
202 void ConfigToItemSet(SfxItemSet& rSet) const;
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */