LibreOffice Module starmath (master) 1
smmod.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <o3tl/string_view.hxx>
23#include <sfx2/objface.hxx>
24#include <svl/whiter.hxx>
25#include <sfx2/viewsh.hxx>
26#include <svx/svxids.hrc>
27#include <vcl/virdev.hxx>
29#include <smmod.hxx>
30#include <cfgitem.hxx>
31#include <dialog.hxx>
32#include <view.hxx>
33#include <smmod.hrc>
34#include <starmath.hrc>
35#include <svx/modctrl.hxx>
36#include <svtools/colorcfg.hxx>
37
38
39#define ShellClass_SmModule
40#include <smslots.hxx>
41
42OUString SmResId(TranslateId aId)
43{
44 return Translate::get(aId, SM_MOD()->GetResLocale());
45}
46
47OUString SmLocalizedSymbolData::GetUiSymbolName( std::u16string_view rExportName )
48{
49 OUString aRes;
50
51 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES); ++i)
52 {
53 if (o3tl::equalsAscii(rExportName, RID_UI_SYMBOL_NAMES[i].mpId))
54 {
55 aRes = SmResId(RID_UI_SYMBOL_NAMES[i]);
56 break;
57 }
58 }
59
60 return aRes;
61}
62
63OUString SmLocalizedSymbolData::GetExportSymbolName( std::u16string_view rUiName )
64{
65 OUString aRes;
66
67 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES); ++i)
68 {
69 if (rUiName == SmResId(RID_UI_SYMBOL_NAMES[i]))
70 {
71 const char *pKey = RID_UI_SYMBOL_NAMES[i].mpId;
72 aRes = OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
73 break;
74 }
75 }
76
77 return aRes;
78}
79
80OUString SmLocalizedSymbolData::GetUiSymbolSetName( std::u16string_view rExportName )
81{
82 OUString aRes;
83
84 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES); ++i)
85 {
86 if (o3tl::equalsAscii(rExportName, RID_UI_SYMBOLSET_NAMES[i].mpId))
87 {
88 aRes = SmResId(RID_UI_SYMBOLSET_NAMES[i]);
89 break;
90 }
91 }
92
93 return aRes;
94}
95
96OUString SmLocalizedSymbolData::GetExportSymbolSetName( std::u16string_view rUiName )
97{
98 OUString aRes;
99
100 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES); ++i)
101 {
102 if (rUiName == SmResId(RID_UI_SYMBOLSET_NAMES[i]))
103 {
104 const char *pKey = RID_UI_SYMBOLSET_NAMES[i].mpId;
105 aRes = OUString(pKey, strlen(pKey), RTL_TEXTENCODING_UTF8);
106 break;
107 }
108 }
109
110 return aRes;
111}
112
114
115void SmModule::InitInterface_Impl()
116{
117 GetStaticInterface()->RegisterStatusBar(StatusBarId::MathStatusBar);
118}
119
121 : SfxModule("sm", {pObjFact})
122{
123 SetName("StarMath");
124
125 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
126}
127
129{
130 if (mpColorConfig)
131 mpColorConfig->RemoveListener(this);
133}
134
136{
137 if(!mpColorConfig)
138 {
140 mpColorConfig->AddListener(this);
141 }
142 return *mpColorConfig;
143}
144
146{
147 if (pBrdCst != mpColorConfig.get())
148 return;
149
150 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
151 while (pViewShell)
152 {
153 // FIXME: What if pViewShell is for a different document,
154 // but OTOH Math is presumably never used through
155 // LibreOfficeKit, so maybe an irrelevant concern?
156 if (dynamic_cast<const SmViewShell *>(pViewShell) != nullptr)
157 pViewShell->GetWindow()->Invalidate();
158 pViewShell = SfxViewShell::GetNext(*pViewShell);
159 }
160}
161
163{
164 if(!mpConfig)
165 mpConfig.reset(new SmMathConfig);
166 return mpConfig.get();
167}
168
170{
171 return GetConfig()->GetSymbolManager();
172}
173
175{
176 if( !moSysLocale )
177 moSysLocale.emplace();
178 return *moSysLocale;
179}
180
182{
183 if (!mpVirtualDev)
184 {
186 mpVirtualDev->SetReferenceDevice( VirtualDevice::RefDevMode::MSO1 );
187 }
188 return *mpVirtualDev;
189}
190
192{
193 SfxWhichIter aIter(rSet);
194
195 for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
196 switch (nWh)
197 {
198 case SID_CONFIGEVENT :
199 rSet.DisableItem(SID_CONFIGEVENT);
200 break;
201 }
202}
203
204std::optional<SfxItemSet> SmModule::CreateItemSet( sal_uInt16 nId )
205{
206 std::optional<SfxItemSet> pRet;
207 if(nId == SID_SM_EDITOPTIONS)
208 {
209 pRet.emplace(
210 GetPool(),
211 svl::Items< //TP_SMPRINT
212 SID_PRINTTITLE, SID_PRINTZOOM,
213 SID_NO_RIGHT_SPACES, SID_SAVE_ONLY_USED_SYMBOLS,
214 SID_AUTO_CLOSE_BRACKETS, SID_SMEDITWINDOWZOOM>);
215
216 GetConfig()->ConfigToItemSet(*pRet);
217 }
218 return pRet;
219}
220
221void SmModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
222{
223 if(nId == SID_SM_EDITOPTIONS)
224 {
226 }
227}
228
229std::unique_ptr<SfxTabPage> SmModule::CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet )
230{
231 std::unique_ptr<SfxTabPage> xRet;
232 if (nId == SID_SM_TP_PRINTOPTIONS)
233 xRet = SmPrintOptionsTabPage::Create(pPage, pController, rSet);
234 return xRet;
235}
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DisableItem(sal_uInt16 nWhich)
SfxItemPool & GetPool() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static SAL_WARN_UNUSED_RESULT SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
vcl::Window * GetWindow() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
void ItemSetToConfig(const SfxItemSet &rSet)
Definition: cfgitem.cxx:1358
void ConfigToItemSet(SfxItemSet &rSet) const
Definition: cfgitem.cxx:1415
SmSymbolManager & GetSymbolManager()
Definition: cfgitem.cxx:465
virtual std::unique_ptr< SfxTabPage > CreateTabPage(sal_uInt16 nId, weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet) override
Definition: smmod.cxx:229
SmMathConfig * GetConfig()
Definition: smmod.cxx:162
virtual void ConfigurationChanged(utl::ConfigurationBroadcaster *, ConfigurationHints) override
Definition: smmod.cxx:145
VirtualDevice & GetDefaultVirtualDev()
Definition: smmod.cxx:181
SmModule(SfxObjectFactory *pObjFact)
Definition: smmod.cxx:120
virtual ~SmModule() override
Definition: smmod.cxx:128
virtual void ApplyItemSet(sal_uInt16 nId, const SfxItemSet &rSet) override
Definition: smmod.cxx:221
svtools::ColorConfig & GetColorConfig()
Definition: smmod.cxx:135
std::unique_ptr< SmMathConfig > mpConfig
Definition: smmod.hxx:64
virtual std::optional< SfxItemSet > CreateItemSet(sal_uInt16 nId) override
Definition: smmod.cxx:204
const SvtSysLocale & GetSysLocale()
Definition: smmod.cxx:174
std::optional< SvtSysLocale > moSysLocale
Definition: smmod.hxx:65
VclPtr< VirtualDevice > mpVirtualDev
Definition: smmod.hxx:66
SmSymbolManager & GetSymbolManager()
Definition: smmod.cxx:169
static void GetState(SfxItemSet &)
Definition: smmod.cxx:191
std::unique_ptr< svtools::ColorConfig > mpColorConfig
Definition: smmod.hxx:63
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: dialog.cxx:237
void disposeAndClear()
void reset(reference_type *pBody)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
#define SAL_N_ELEMENTS(arr)
OUString GetExportSymbolSetName(std::u16string_view rUiName)
Definition: smmod.cxx:96
OUString GetExportSymbolName(std::u16string_view rUiName)
Definition: smmod.cxx:63
OUString GetUiSymbolName(std::u16string_view rExportName)
Definition: smmod.cxx:47
OUString GetUiSymbolSetName(std::u16string_view rExportName)
Definition: smmod.cxx:80
OUString get(TranslateId sContextAndId, const std::locale &loc)
int i
bool equalsAscii(std::u16string_view s1, std::string_view s2)
static constexpr auto Items
sal_Int16 nId
ConfigurationHints
static SfxItemSet & rSet
#define SFX_IMPL_INTERFACE(Class, SuperClass)
OUString SmResId(TranslateId aId)
Definition: smmod.cxx:42
#define SM_MOD()
Definition: smmod.hxx:98