Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / starmath / source / smmod.cxx
blob3a4722da4b614f1eb18613a3a85702c456ae6797
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 #include <sal/config.h>
22 #include <o3tl/make_unique.hxx>
23 #include <sfx2/objface.hxx>
24 #include <svl/whiter.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <svx/svxids.hrc>
27 #include <unotools/resmgr.hxx>
28 #include <vcl/virdev.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <smmod.hxx>
31 #include "cfgitem.hxx"
32 #include <dialog.hxx>
33 #include <edit.hxx>
34 #include <view.hxx>
35 #include <smmod.hrc>
36 #include <starmath.hrc>
37 #include <svx/modctrl.hxx>
40 #define ShellClass_SmModule
41 #include <smslots.hxx>
43 OUString SmResId(const char* pId)
45 return Translate::get(pId, SM_MOD()->GetResLocale());
48 const OUString SmLocalizedSymbolData::GetUiSymbolName( const OUString &rExportName )
50 OUString aRes;
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]);
57 break;
61 return aRes;
64 const OUString SmLocalizedSymbolData::GetExportSymbolName( const OUString &rUiName )
66 OUString aRes;
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);
74 break;
78 return aRes;
81 const OUString SmLocalizedSymbolData::GetUiSymbolSetName( const OUString &rExportName )
83 OUString aRes;
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]);
90 break;
94 return aRes;
97 const OUString SmLocalizedSymbolData::GetExportSymbolSetName( const OUString &rUiName )
99 OUString aRes;
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);
107 break;
111 return aRes;
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})
124 SetName("StarMath");
126 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
129 SmModule::~SmModule()
131 if (mpColorConfig)
132 mpColorConfig->RemoveListener(this);
133 mpVirtualDev.disposeAndClear();
136 void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
138 //invalidate all graphic and edit windows
139 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
140 while (pViewShell)
142 if (dynamic_cast<const SmViewShell *>(pViewShell) != nullptr)
144 SmViewShell *pSmView = static_cast<SmViewShell *>(pViewShell);
145 pSmView->GetGraphicWindow().ApplyColorConfigValues( rColorCfg );
146 SmEditWindow *pEditWin = pSmView->GetEditWindow();
147 if (pEditWin)
148 pEditWin->ApplyColorConfigValues( rColorCfg );
150 pViewShell = SfxViewShell::GetNext( *pViewShell );
154 svtools::ColorConfig & SmModule::GetColorConfig()
156 if(!mpColorConfig)
158 mpColorConfig.reset(new svtools::ColorConfig);
159 ApplyColorConfigValues( *mpColorConfig );
160 mpColorConfig->AddListener(this);
162 return *mpColorConfig;
165 void SmModule::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints )
167 ApplyColorConfigValues(*mpColorConfig);
170 SmMathConfig * SmModule::GetConfig()
172 if(!mpConfig)
173 mpConfig.reset(new SmMathConfig);
174 return mpConfig.get();
177 SmSymbolManager & SmModule::GetSymbolManager()
179 return GetConfig()->GetSymbolManager();
182 const SvtSysLocale& SmModule::GetSysLocale()
184 if( !mpSysLocale )
185 mpSysLocale.reset(new SvtSysLocale);
186 return *mpSysLocale;
189 VirtualDevice &SmModule::GetDefaultVirtualDev()
191 if (!mpVirtualDev)
193 mpVirtualDev.reset( VclPtr<VirtualDevice>::Create() );
194 mpVirtualDev->SetReferenceDevice( VirtualDevice::RefDevMode::MSO1 );
196 return *mpVirtualDev;
199 void SmModule::GetState(SfxItemSet &rSet)
201 SfxWhichIter aIter(rSet);
203 for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
204 switch (nWh)
206 case SID_CONFIGEVENT :
207 rSet.DisableItem(SID_CONFIGEVENT);
208 break;
212 std::unique_ptr<SfxItemSet> SmModule::CreateItemSet( sal_uInt16 nId )
214 std::unique_ptr<SfxItemSet> pRet;
215 if(nId == SID_SM_EDITOPTIONS)
217 pRet = o3tl::make_unique<SfxItemSet>(
218 GetPool(),
219 svl::Items< //TP_SMPRINT
220 SID_PRINTTITLE, SID_PRINTZOOM,
221 SID_NO_RIGHT_SPACES, SID_SAVE_ONLY_USED_SYMBOLS,
222 SID_AUTO_CLOSE_BRACKETS, SID_AUTO_CLOSE_BRACKETS>{});
224 GetConfig()->ConfigToItemSet(*pRet);
226 return pRet;
229 void SmModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
231 if(nId == SID_SM_EDITOPTIONS)
233 GetConfig()->ItemSetToConfig(rSet);
237 VclPtr<SfxTabPage> SmModule::CreateTabPage( sal_uInt16 nId, TabPageParent pParent, const SfxItemSet& rSet )
239 VclPtr<SfxTabPage> pRet;
240 if(nId == SID_SM_TP_PRINTOPTIONS)
241 pRet = SmPrintOptionsTabPage::Create( TabPageParent(pParent.pParent), rSet );
242 return pRet;
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */