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 .
20 #include <sal/config.h>
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>
28 #include <unotools/syslocale.hxx>
30 #include <cfgitem.hxx>
34 #include <starmath.hrc>
35 #include <svx/modctrl.hxx>
36 #include <svtools/colorcfg.hxx>
39 #define ShellClass_SmModule
40 #include <smslots.hxx>
42 OUString
SmResId(TranslateId aId
)
44 return Translate::get(aId
, SM_MOD()->GetResLocale());
47 OUString
SmLocalizedSymbolData::GetUiSymbolName( std::u16string_view rExportName
)
51 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES
); ++i
)
53 if (o3tl::equalsAscii(rExportName
, RID_UI_SYMBOL_NAMES
[i
].mpId
))
55 aRes
= SmResId(RID_UI_SYMBOL_NAMES
[i
]);
63 OUString
SmLocalizedSymbolData::GetExportSymbolName( std::u16string_view rUiName
)
67 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES
); ++i
)
69 if (rUiName
== SmResId(RID_UI_SYMBOL_NAMES
[i
]))
71 const char *pKey
= RID_UI_SYMBOL_NAMES
[i
].mpId
;
72 aRes
= OUString(pKey
, strlen(pKey
), RTL_TEXTENCODING_UTF8
);
80 OUString
SmLocalizedSymbolData::GetUiSymbolSetName( std::u16string_view rExportName
)
84 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES
); ++i
)
86 if (o3tl::equalsAscii(rExportName
, RID_UI_SYMBOLSET_NAMES
[i
].mpId
))
88 aRes
= SmResId(RID_UI_SYMBOLSET_NAMES
[i
]);
96 OUString
SmLocalizedSymbolData::GetExportSymbolSetName( std::u16string_view rUiName
)
100 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES
); ++i
)
102 if (rUiName
== SmResId(RID_UI_SYMBOLSET_NAMES
[i
]))
104 const char *pKey
= RID_UI_SYMBOLSET_NAMES
[i
].mpId
;
105 aRes
= OUString(pKey
, strlen(pKey
), RTL_TEXTENCODING_UTF8
);
113 SFX_IMPL_INTERFACE(SmModule
, SfxModule
)
115 void SmModule::InitInterface_Impl()
117 GetStaticInterface()->RegisterStatusBar(StatusBarId::MathStatusBar
);
120 SmModule::SmModule(SfxObjectFactory
* pObjFact
)
121 : SfxModule("sm", {pObjFact
})
125 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED
, this);
128 SmModule::~SmModule()
131 mpColorConfig
->RemoveListener(this);
132 mpVirtualDev
.disposeAndClear();
135 svtools::ColorConfig
& SmModule::GetColorConfig()
139 mpColorConfig
.reset(new svtools::ColorConfig
);
140 mpColorConfig
->AddListener(this);
142 return *mpColorConfig
;
145 void SmModule::ConfigurationChanged(utl::ConfigurationBroadcaster
* pBrdCst
, ConfigurationHints
)
147 if (pBrdCst
!= mpColorConfig
.get())
150 SfxViewShell
* pViewShell
= SfxViewShell::GetFirst();
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
);
162 SmMathConfig
* SmModule::GetConfig()
165 mpConfig
.reset(new SmMathConfig
);
166 return mpConfig
.get();
169 SmSymbolManager
& SmModule::GetSymbolManager()
171 return GetConfig()->GetSymbolManager();
174 const SvtSysLocale
& SmModule::GetSysLocale()
177 moSysLocale
.emplace();
181 VirtualDevice
&SmModule::GetDefaultVirtualDev()
185 mpVirtualDev
.reset( VclPtr
<VirtualDevice
>::Create() );
186 mpVirtualDev
->SetReferenceDevice( VirtualDevice::RefDevMode::MSO1
);
188 return *mpVirtualDev
;
191 void SmModule::GetState(SfxItemSet
&rSet
)
193 SfxWhichIter
aIter(rSet
);
195 for (sal_uInt16 nWh
= aIter
.FirstWhich(); 0 != nWh
; nWh
= aIter
.NextWhich())
198 case SID_CONFIGEVENT
:
199 rSet
.DisableItem(SID_CONFIGEVENT
);
204 std::optional
<SfxItemSet
> SmModule::CreateItemSet( sal_uInt16 nId
)
206 std::optional
<SfxItemSet
> pRet
;
207 if(nId
== SID_SM_EDITOPTIONS
)
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
>);
216 GetConfig()->ConfigToItemSet(*pRet
);
221 void SmModule::ApplyItemSet( sal_uInt16 nId
, const SfxItemSet
& rSet
)
223 if(nId
== SID_SM_EDITOPTIONS
)
225 GetConfig()->ItemSetToConfig(rSet
);
229 std::unique_ptr
<SfxTabPage
> SmModule::CreateTabPage( sal_uInt16 nId
, weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
231 std::unique_ptr
<SfxTabPage
> xRet
;
232 if (nId
== SID_SM_TP_PRINTOPTIONS
)
233 xRet
= SmPrintOptionsTabPage::Create(pPage
, pController
, rSet
);
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */