cURL: follow redirects
[LibreOffice.git] / starmath / source / smmod.cxx
blob8fc5c8d56313b6f72b31a228320bffc452dd0f9e
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 <sfx2/objface.hxx>
21 #include <svl/whiter.hxx>
22 #include <sfx2/sfx.hrc>
23 #include <sfx2/viewsh.hxx>
24 #include <svx/svxids.hrc>
25 #include <vcl/virdev.hxx>
26 #include <unotools/syslocale.hxx>
27 #include "smmod.hxx"
28 #include "symbol.hxx"
29 #include "cfgitem.hxx"
30 #include "dialog.hxx"
31 #include "edit.hxx"
32 #include "view.hxx"
33 #include "starmath.hrc"
34 #include "svx/modctrl.hxx"
37 #define SmModule
38 #include "smslots.hxx"
40 SmResId::SmResId( sal_uInt16 nId )
41 : ResId(nId, *SM_MOD()->GetResMgr())
45 SmLocalizedSymbolData::SmLocalizedSymbolData() :
46 aUiSymbolNamesAry ( SmResId(RID_UI_SYMBOL_NAMES) ),
47 aExportSymbolNamesAry ( SmResId(RID_EXPORT_SYMBOL_NAMES) ),
48 aUiSymbolSetNamesAry ( SmResId(RID_UI_SYMBOLSET_NAMES) ),
49 aExportSymbolSetNamesAry( SmResId(RID_EXPORT_SYMBOLSET_NAMES) )
53 SmLocalizedSymbolData::~SmLocalizedSymbolData()
57 const OUString SmLocalizedSymbolData::GetUiSymbolName( const OUString &rExportName )
59 OUString aRes;
61 const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
62 const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
63 const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
64 sal_uInt32 nCount = rExportNames.Count();
65 for (sal_uInt32 i = 0; i < nCount; ++i)
67 if (rExportNames.GetString(i).equals(rExportName))
69 aRes = rUiNames.GetString(i);
70 break;
74 return aRes;
77 const OUString SmLocalizedSymbolData::GetExportSymbolName( const OUString &rUiName )
79 OUString aRes;
81 const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
82 const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
83 const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
84 sal_uInt32 nCount = rUiNames.Count();
85 for (sal_uInt32 i = 0; i < nCount; ++i)
87 if (rUiNames.GetString(i).equals(rUiName))
89 aRes = rExportNames.GetString(i);
90 break;
94 return aRes;
97 const OUString SmLocalizedSymbolData::GetUiSymbolSetName( const OUString &rExportName )
99 OUString aRes;
101 const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
102 const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
103 const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
104 sal_uInt32 nCount = rExportNames.Count();
105 for (sal_uInt32 i = 0; i < nCount; ++i)
107 if (rExportNames.GetString(i).equals(rExportName))
109 aRes = rUiNames.GetString(i);
110 break;
114 return aRes;
117 const OUString SmLocalizedSymbolData::GetExportSymbolSetName( const OUString &rUiName )
119 OUString aRes;
121 const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
122 const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
123 const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
124 sal_uInt32 nCount = rUiNames.Count();
125 for (sal_uInt32 i = 0; i < nCount; ++i)
127 if (rUiNames.GetString(i).equals(rUiName))
129 aRes = rExportNames.GetString(i);
130 break;
134 return aRes;
137 SFX_IMPL_INTERFACE(SmModule, SfxModule)
139 void SmModule::InitInterface_Impl()
141 GetStaticInterface()->RegisterStatusBar(RID_STATUSBAR);
144 SmModule::SmModule(SfxObjectFactory* pObjFact) :
145 SfxModule("sm", {pObjFact})
147 SetName("StarMath");
149 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
152 SmModule::~SmModule()
154 if (mpColorConfig)
155 mpColorConfig->RemoveListener(this);
156 mpVirtualDev.disposeAndClear();
159 void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
161 //invalidate all graphic and edit windows
162 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
163 while (pViewShell)
165 if ((dynamic_cast<const SmViewShell *>(pViewShell) != nullptr))
167 SmViewShell *pSmView = static_cast<SmViewShell *>(pViewShell);
168 pSmView->GetGraphicWindow().ApplyColorConfigValues( rColorCfg );
169 SmEditWindow *pEditWin = pSmView->GetEditWindow();
170 if (pEditWin)
171 pEditWin->ApplyColorConfigValues( rColorCfg );
173 pViewShell = SfxViewShell::GetNext( *pViewShell );
177 svtools::ColorConfig & SmModule::GetColorConfig()
179 if(!mpColorConfig)
181 mpColorConfig.reset(new svtools::ColorConfig);
182 ApplyColorConfigValues( *mpColorConfig );
183 mpColorConfig->AddListener(this);
185 return *mpColorConfig;
188 void SmModule::ConfigurationChanged( utl::ConfigurationBroadcaster*, ConfigurationHints )
190 ApplyColorConfigValues(*mpColorConfig);
193 SmMathConfig * SmModule::GetConfig()
195 if(!mpConfig)
196 mpConfig.reset(new SmMathConfig);
197 return mpConfig.get();
200 SmSymbolManager & SmModule::GetSymbolManager()
202 return GetConfig()->GetSymbolManager();
205 SmLocalizedSymbolData & SmModule::GetLocSymbolData()
207 if (!mpLocSymbolData)
208 mpLocSymbolData.reset(new SmLocalizedSymbolData);
209 return *mpLocSymbolData;
212 const SvtSysLocale& SmModule::GetSysLocale()
214 if( !mpSysLocale )
215 mpSysLocale.reset(new SvtSysLocale);
216 return *mpSysLocale;
219 VirtualDevice &SmModule::GetDefaultVirtualDev()
221 if (!mpVirtualDev)
223 mpVirtualDev.reset( VclPtr<VirtualDevice>::Create() );
224 mpVirtualDev->SetReferenceDevice( VirtualDevice::RefDevMode::MSO1 );
226 return *mpVirtualDev;
229 void SmModule::GetState(SfxItemSet &rSet)
231 SfxWhichIter aIter(rSet);
233 for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
234 switch (nWh)
236 case SID_CONFIGEVENT :
237 rSet.DisableItem(SID_CONFIGEVENT);
238 break;
242 SfxItemSet* SmModule::CreateItemSet( sal_uInt16 nId )
244 SfxItemSet* pRet = nullptr;
245 if(nId == SID_SM_EDITOPTIONS)
247 pRet = new SfxItemSet(GetPool(),
248 //TP_SMPRINT
249 SID_PRINTSIZE, SID_PRINTSIZE,
250 SID_PRINTZOOM, SID_PRINTZOOM,
251 SID_PRINTTITLE, SID_PRINTTITLE,
252 SID_PRINTTEXT, SID_PRINTTEXT,
253 SID_PRINTFRAME, SID_PRINTFRAME,
254 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
255 SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
256 SID_AUTO_CLOSE_BRACKETS, SID_AUTO_CLOSE_BRACKETS,
257 0 );
259 GetConfig()->ConfigToItemSet(*pRet);
261 return pRet;
264 void SmModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
266 if(nId == SID_SM_EDITOPTIONS)
268 GetConfig()->ItemSetToConfig(rSet);
272 VclPtr<SfxTabPage> SmModule::CreateTabPage( sal_uInt16 nId, vcl::Window* pParent, const SfxItemSet& rSet )
274 VclPtr<SfxTabPage> pRet;
275 if(nId == SID_SM_TP_PRINTOPTIONS)
276 pRet = SmPrintOptionsTabPage::Create( pParent, rSet );
277 return pRet;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */