1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include "utility.hxx"
24 #include <string_view>
25 #include <rtl/ustring.hxx>
26 #include <svl/SfxBroadcaster.hxx>
27 #include <unotools/configitem.hxx>
31 namespace com::sun::star::uno
33 template <class E
> class Sequence
;
37 class SmSymbolManager
;
56 explicit SmFontFormat(const vcl::Font
& rFont
);
58 vcl::Font
GetFont() const;
59 bool operator==(const SmFontFormat
& rFntFmt
) const;
62 struct SmFntFmtListEntry
67 SmFntFmtListEntry(OUString aId
, SmFontFormat rFntFmt
);
70 class SmFontFormatList
72 std::vector
<SmFntFmtListEntry
> aEntries
;
75 SmFontFormatList(const SmFontFormatList
&) = delete;
76 SmFontFormatList
& operator=(const SmFontFormatList
&) = delete;
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 css::uno::Sequence
<OUString
> m_sUserDefinedNames
;
104 bool bIsOtherModified
;
105 bool bIsFormatModified
;
106 SmFontPickList vFontPickList
[8];
107 sal_Int32 m_nCommitLock
= 0;
109 SmMathConfig(const SmMathConfig
&) = delete;
110 SmMathConfig
& operator=(const SmMathConfig
&) = delete;
112 void StripFontFormatList(const std::vector
<SmSym
>& rSymbols
);
116 void ReadSymbol(SmSym
& rSymbol
, const OUString
& rSymbolName
,
117 std::u16string_view rBaseNode
) const;
118 void ReadFontFormat(SmFontFormat
& rFontFormat
, std::u16string_view rSymbolName
,
119 std::u16string_view rBaseNode
) const;
121 bool SetOtherIfNotEqual(bool& rbItem
, bool bNewVal
);
127 void LoadFontFormatList();
128 void SaveFontFormatList();
130 void SetOtherModified(bool bVal
);
131 bool IsOtherModified() const { return bIsOtherModified
; }
132 void SetFormatModified(bool bVal
);
133 bool IsFormatModified() const { return bIsFormatModified
; }
135 SmFontFormatList
& GetFontFormatList();
136 const SmFontFormatList
& GetFontFormatList() const
138 return const_cast<SmMathConfig
*>(this)->GetFontFormatList();
141 virtual void ImplCommit() override
;
142 void LockCommit() { ++m_nCommitLock
; }
144 // Used to avoid tens of atomic commits in e.g. ItemSetToConfig that calls individual setters
145 friend struct CommitLocker
;
148 SmMathConfig
& m_rConfig
;
149 CommitLocker(SmMathConfig
& rConfig
)
152 m_rConfig
.LockCommit();
154 ~CommitLocker() { m_rConfig
.UnlockCommit(); }
161 virtual ~SmMathConfig() override
;
164 virtual void Notify(const css::uno::Sequence
<OUString
>& rPropertyNames
) override
;
166 SmSymbolManager
& GetSymbolManager();
167 void GetSymbols(std::vector
<SmSym
>& rSymbols
) const;
168 void SetSymbols(const std::vector
<SmSym
>& rNewSymbols
);
170 const SmFormat
& GetStandardFormat() const;
171 void SetStandardFormat(const SmFormat
& rFormat
, bool bSaveFontFormatList
= false);
173 css::uno::Sequence
<OUString
> LoadUserDefinedNames();
174 void GetUserDefinedFormula(std::u16string_view sName
, OUString
& sFormula
);
175 bool HasUserDefinedFormula(std::u16string_view sName
);
176 void SaveUserDefinedFormula(std::u16string_view sName
, const OUString
& sElement
);
177 void DeleteUserDefinedFormula(std::u16string_view sName
);
179 bool IsPrintTitle() const;
180 void SetPrintTitle(bool bVal
);
181 bool IsPrintFormulaText() const;
182 void SetPrintFormulaText(bool bVal
);
183 bool IsPrintFrame() const;
184 void SetPrintFrame(bool bVal
);
185 SmPrintSize
GetPrintSize() const;
186 void SetPrintSize(SmPrintSize eSize
);
187 sal_uInt16
GetPrintZoomFactor() const;
188 void SetPrintZoomFactor(sal_uInt16 nVal
);
189 sal_uInt16
GetSmEditWindowZoomFactor() const;
190 void SetSmEditWindowZoomFactor(sal_uInt16 nVal
);
192 bool IsSaveOnlyUsedSymbols() const;
193 void SetSaveOnlyUsedSymbols(bool bVal
);
194 bool IsAutoCloseBrackets() const;
195 void SetAutoCloseBrackets(bool bVal
);
196 bool IsInlineEditEnable() const;
197 void SetInlineEditEnable(bool bVal
);
198 bool IsIgnoreSpacesRight() const;
199 void SetIgnoreSpacesRight(bool bVal
);
200 bool IsAutoRedraw() const;
201 void SetAutoRedraw(bool bVal
);
202 bool IsShowFormulaCursor() const;
203 void SetShowFormulaCursor(bool bVal
);
205 sal_Int16
GetDefaultSmSyntaxVersion() const;
206 void SetDefaultSmSyntaxVersion(sal_Int16 nVal
);
208 SmFontPickList
& GetFontPickList(sal_uInt16 nIdent
) { return vFontPickList
[nIdent
]; }
210 void ItemSetToConfig(const SfxItemSet
& rSet
);
211 void ConfigToItemSet(SfxItemSet
& rSet
) const;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */