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 <sfx2/objface.hxx>
23 #include <svl/whiter.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <svx/svxids.hrc>
26 #include <unotools/resmgr.hxx>
27 #include <vcl/virdev.hxx>
28 #include <unotools/syslocale.hxx>
30 #include "cfgitem.hxx"
35 #include <starmath.hrc>
36 #include <svx/modctrl.hxx>
37 #include <svtools/colorcfg.hxx>
40 #define ShellClass_SmModule
41 #include <smslots.hxx>
43 OUString
SmResId(const char* pId
)
45 return Translate::get(pId
, SM_MOD()->GetResLocale());
48 OUString
SmLocalizedSymbolData::GetUiSymbolName( const OUString
&rExportName
)
52 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES
); ++i
)
54 if (rExportName
.equalsAscii(strchr(RID_UI_SYMBOL_NAMES
[i
], '\004') + 1))
56 aRes
= SmResId(RID_UI_SYMBOL_NAMES
[i
]);
64 OUString
SmLocalizedSymbolData::GetExportSymbolName( const OUString
&rUiName
)
68 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOL_NAMES
); ++i
)
70 if (rUiName
== SmResId(RID_UI_SYMBOL_NAMES
[i
]))
72 const char *pKey
= strchr(RID_UI_SYMBOL_NAMES
[i
], '\004') + 1;
73 aRes
= OUString(pKey
, strlen(pKey
), RTL_TEXTENCODING_UTF8
);
81 OUString
SmLocalizedSymbolData::GetUiSymbolSetName( const OUString
&rExportName
)
85 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES
); ++i
)
87 if (rExportName
.equalsAscii(strchr(RID_UI_SYMBOLSET_NAMES
[i
], '\004') + 1))
89 aRes
= SmResId(RID_UI_SYMBOLSET_NAMES
[i
]);
97 OUString
SmLocalizedSymbolData::GetExportSymbolSetName( const OUString
&rUiName
)
101 for (size_t i
= 0; i
< SAL_N_ELEMENTS(RID_UI_SYMBOLSET_NAMES
); ++i
)
103 if (rUiName
== SmResId(RID_UI_SYMBOLSET_NAMES
[i
]))
105 const char *pKey
= strchr(RID_UI_SYMBOLSET_NAMES
[i
], '\004') + 1;
106 aRes
= OUString(pKey
, strlen(pKey
), RTL_TEXTENCODING_UTF8
);
114 SFX_IMPL_INTERFACE(SmModule
, SfxModule
)
116 void SmModule::InitInterface_Impl()
118 GetStaticInterface()->RegisterStatusBar(StatusBarId::MathStatusBar
);
121 SmModule::SmModule(SfxObjectFactory
* pObjFact
)
122 : SfxModule("sm", {pObjFact
})
126 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED
, this);
129 SmModule::~SmModule()
132 mpColorConfig
->RemoveListener(this);
133 mpVirtualDev
.disposeAndClear();
136 svtools::ColorConfig
& SmModule::GetColorConfig()
140 mpColorConfig
.reset(new svtools::ColorConfig
);
141 mpColorConfig
->AddListener(this);
143 return *mpColorConfig
;
146 void SmModule::ConfigurationChanged(utl::ConfigurationBroadcaster
* pBrdCst
, ConfigurationHints
)
148 if (pBrdCst
!= mpColorConfig
.get())
151 SfxViewShell
* pViewShell
= SfxViewShell::GetFirst();
154 // FIXME: What if pViewShell is for a different document,
155 // but OTOH Math is presumably never used through
156 // LibreOfficeKit, so maybe an irrelevant concern?
157 if (dynamic_cast<const SmViewShell
*>(pViewShell
) != nullptr)
158 pViewShell
->GetWindow()->Invalidate();
159 pViewShell
= SfxViewShell::GetNext(*pViewShell
);
163 SmMathConfig
* SmModule::GetConfig()
166 mpConfig
.reset(new SmMathConfig
);
167 return mpConfig
.get();
170 SmSymbolManager
& SmModule::GetSymbolManager()
172 return GetConfig()->GetSymbolManager();
175 const SvtSysLocale
& SmModule::GetSysLocale()
178 mpSysLocale
.reset(new SvtSysLocale
);
182 VirtualDevice
&SmModule::GetDefaultVirtualDev()
186 mpVirtualDev
.reset( VclPtr
<VirtualDevice
>::Create() );
187 mpVirtualDev
->SetReferenceDevice( VirtualDevice::RefDevMode::MSO1
);
189 return *mpVirtualDev
;
192 void SmModule::GetState(SfxItemSet
&rSet
)
194 SfxWhichIter
aIter(rSet
);
196 for (sal_uInt16 nWh
= aIter
.FirstWhich(); 0 != nWh
; nWh
= aIter
.NextWhich())
199 case SID_CONFIGEVENT
:
200 rSet
.DisableItem(SID_CONFIGEVENT
);
205 std::unique_ptr
<SfxItemSet
> SmModule::CreateItemSet( sal_uInt16 nId
)
207 std::unique_ptr
<SfxItemSet
> pRet
;
208 if(nId
== SID_SM_EDITOPTIONS
)
210 pRet
= std::make_unique
<SfxItemSet
>(
212 svl::Items
< //TP_SMPRINT
213 SID_PRINTTITLE
, SID_PRINTZOOM
,
214 SID_NO_RIGHT_SPACES
, SID_SAVE_ONLY_USED_SYMBOLS
,
215 SID_AUTO_CLOSE_BRACKETS
, SID_AUTO_CLOSE_BRACKETS
>{});
217 GetConfig()->ConfigToItemSet(*pRet
);
222 void SmModule::ApplyItemSet( sal_uInt16 nId
, const SfxItemSet
& rSet
)
224 if(nId
== SID_SM_EDITOPTIONS
)
226 GetConfig()->ItemSetToConfig(rSet
);
230 std::unique_ptr
<SfxTabPage
> SmModule::CreateTabPage( sal_uInt16 nId
, weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
232 std::unique_ptr
<SfxTabPage
> xRet
;
233 if (nId
== SID_SM_TP_PRINTOPTIONS
)
234 xRet
= SmPrintOptionsTabPage::Create(pPage
, pController
, rSet
);
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */