Line data Source code
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 <tools/globname.hxx>
21 : #include <vcl/status.hxx>
22 : #include <sfx2/msg.hxx>
23 : #include <sfx2/app.hxx>
24 : #include <sfx2/objface.hxx>
25 : #include <svl/whiter.hxx>
26 : #include <sfx2/request.hxx>
27 : #include <sfx2/sfx.hrc>
28 : #include <sfx2/viewsh.hxx>
29 : #include <vcl/wrkwin.hxx>
30 : #include <svx/svxids.hrc>
31 : #include <vcl/msgbox.hxx>
32 : #include <vcl/virdev.hxx>
33 : #include <unotools/syslocale.hxx>
34 : #include <tools/rtti.hxx>
35 : #include "smmod.hxx"
36 : #include "symbol.hxx"
37 : #include "config.hxx"
38 : #include "dialog.hxx"
39 : #include "edit.hxx"
40 : #include "view.hxx"
41 : #include "starmath.hrc"
42 : #include "svx/modctrl.hxx"
43 :
44 0 : TYPEINIT1( SmModule, SfxModule );
45 :
46 : #define SmModule
47 : #include "smslots.hxx"
48 :
49 : #include <svx/xmlsecctrl.hxx>
50 :
51 :
52 :
53 1516 : SmResId::SmResId( sal_uInt16 nId )
54 1516 : : ResId(nId, *SM_MOD()->GetResMgr())
55 : {
56 1516 : }
57 :
58 : /////////////////////////////////////////////////////////////////
59 :
60 8 : SmLocalizedSymbolData::SmLocalizedSymbolData() :
61 : Resource( SmResId(RID_LOCALIZED_NAMES) ),
62 : aUiSymbolNamesAry ( SmResId(RID_UI_SYMBOL_NAMES) ),
63 : aExportSymbolNamesAry ( SmResId(RID_EXPORT_SYMBOL_NAMES) ),
64 : aUiSymbolSetNamesAry ( SmResId(RID_UI_SYMBOLSET_NAMES) ),
65 : aExportSymbolSetNamesAry( SmResId(RID_EXPORT_SYMBOLSET_NAMES) ),
66 : p50NamesAry ( 0 ),
67 : p60NamesAry ( 0 ),
68 : n50NamesLang ( LANGUAGE_NONE ),
69 8 : n60NamesLang ( LANGUAGE_NONE )
70 : {
71 8 : FreeResource();
72 8 : }
73 :
74 :
75 8 : SmLocalizedSymbolData::~SmLocalizedSymbolData()
76 : {
77 4 : delete p50NamesAry;
78 4 : delete p60NamesAry;
79 4 : }
80 :
81 :
82 264 : const String SmLocalizedSymbolData::GetUiSymbolName( const String &rExportName ) const
83 : {
84 264 : String aRes;
85 :
86 264 : const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
87 264 : const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
88 264 : const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
89 264 : sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
90 8844 : for (sal_uInt16 i = 0; i < nCount && !aRes.Len(); ++i)
91 : {
92 8844 : if (rExportNames.GetString(i).equals(rExportName))
93 : {
94 264 : aRes = rUiNames.GetString(i);
95 264 : break;
96 : }
97 : }
98 :
99 264 : return aRes;
100 : }
101 :
102 :
103 0 : const String SmLocalizedSymbolData::GetExportSymbolName( const String &rUiName ) const
104 : {
105 0 : String aRes;
106 :
107 0 : const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
108 0 : const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
109 0 : const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
110 0 : sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
111 0 : for (sal_uInt16 i = 0; i < nCount && !aRes.Len(); ++i)
112 : {
113 0 : if (rUiNames.GetString(i).equals(rUiName))
114 : {
115 0 : aRes = rExportNames.GetString(i);
116 0 : break;
117 : }
118 : }
119 :
120 0 : return aRes;
121 : }
122 :
123 :
124 268 : const String SmLocalizedSymbolData::GetUiSymbolSetName( const String &rExportName ) const
125 : {
126 268 : String aRes;
127 :
128 268 : const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
129 268 : const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
130 268 : const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
131 268 : sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
132 316 : for (sal_uInt16 i = 0; i < nCount && !aRes.Len(); ++i)
133 : {
134 316 : if (rExportNames.GetString(i).equals(rExportName))
135 : {
136 268 : aRes = rUiNames.GetString(i);
137 268 : break;
138 : }
139 : }
140 :
141 268 : return aRes;
142 : }
143 :
144 :
145 130 : const String SmLocalizedSymbolData::GetExportSymbolSetName( const String &rUiName ) const
146 : {
147 130 : String aRes;
148 :
149 130 : const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
150 130 : const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
151 130 : const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
152 130 : sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
153 154 : for (sal_uInt16 i = 0; i < nCount && !aRes.Len(); ++i)
154 : {
155 154 : if (rUiNames.GetString(i).equals(rUiName))
156 : {
157 130 : aRes = rExportNames.GetString(i);
158 130 : break;
159 : }
160 : }
161 :
162 130 : return aRes;
163 : }
164 :
165 :
166 0 : const ResStringArray* SmLocalizedSymbolData::Get50NamesArray( LanguageType nLang )
167 : {
168 0 : if (nLang != n50NamesLang)
169 : {
170 : int nRID;
171 0 : switch (nLang)
172 : {
173 0 : case LANGUAGE_FRENCH : nRID = RID_FRENCH_50_NAMES; break;
174 0 : case LANGUAGE_ITALIAN : nRID = RID_ITALIAN_50_NAMES; break;
175 0 : case LANGUAGE_SWEDISH : nRID = RID_SWEDISH_50_NAMES; break;
176 0 : case LANGUAGE_SPANISH : nRID = RID_SPANISH_50_NAMES; break;
177 0 : default : nRID = -1; break;
178 : }
179 0 : delete p50NamesAry;
180 0 : p50NamesAry = 0;
181 0 : n50NamesLang = nLang;
182 0 : if (-1 != nRID)
183 0 : p50NamesAry = new SmNamesArray( n50NamesLang, nRID );
184 : }
185 :
186 0 : return p50NamesAry ? &p50NamesAry->GetNamesArray() : 0;
187 : }
188 :
189 :
190 0 : const ResStringArray* SmLocalizedSymbolData::Get60NamesArray( LanguageType nLang )
191 : {
192 0 : if (nLang != n60NamesLang)
193 : {
194 : int nRID;
195 0 : switch (nLang)
196 : {
197 0 : case LANGUAGE_FRENCH : nRID = RID_FRENCH_60_NAMES; break;
198 0 : case LANGUAGE_ITALIAN : nRID = RID_ITALIAN_60_NAMES; break;
199 0 : case LANGUAGE_SWEDISH : nRID = RID_SWEDISH_60_NAMES; break;
200 0 : case LANGUAGE_SPANISH : nRID = RID_SPANISH_60_NAMES; break;
201 0 : default : nRID = -1; break;
202 : }
203 0 : delete p60NamesAry;
204 0 : p60NamesAry = 0;
205 0 : n60NamesLang = nLang;
206 0 : if (-1 != nRID)
207 0 : p60NamesAry = new SmNamesArray( n60NamesLang, nRID );
208 : }
209 :
210 0 : return p60NamesAry ? &p60NamesAry->GetNamesArray() : 0;
211 : }
212 :
213 : /////////////////////////////////////////////////////////////////
214 :
215 16 : SFX_IMPL_INTERFACE(SmModule, SfxModule, SmResId(RID_APPLICATION))
216 : {
217 4 : SFX_STATUSBAR_REGISTRATION(SmResId(RID_STATUSBAR));
218 4 : }
219 :
220 :
221 4 : SmModule::SmModule(SfxObjectFactory* pObjFact) :
222 : SfxModule(SfxApplication::CreateResManager("sm"), sal_False, pObjFact, NULL),
223 : pColorConfig( 0 ),
224 : pConfig( 0 ),
225 : pLocSymbolData( 0 ),
226 : pSysLocale( 0 ),
227 4 : pVirtualDev( 0 )
228 : {
229 4 : SetName(rtl::OUString("StarMath"));
230 :
231 4 : SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
232 4 : }
233 :
234 :
235 0 : SmModule::~SmModule()
236 : {
237 0 : delete pConfig;
238 0 : if (pColorConfig)
239 0 : pColorConfig->RemoveListener(this);
240 0 : delete pColorConfig;
241 0 : delete pLocSymbolData;
242 0 : delete pSysLocale;
243 0 : delete pVirtualDev;
244 0 : }
245 :
246 4 : void SmModule::_CreateSysLocale() const
247 : {
248 4 : SmModule* pThis = (SmModule*)this;
249 4 : pThis->pSysLocale = new SvtSysLocale;
250 4 : }
251 :
252 4 : void SmModule::_CreateVirtualDev() const
253 : {
254 4 : SmModule* pThis = (SmModule*)this;
255 4 : pThis->pVirtualDev = new VirtualDevice;
256 4 : pThis->pVirtualDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
257 4 : }
258 :
259 4 : void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
260 : {
261 : //invalidate all graphic and edit windows
262 4 : const TypeId aSmViewTypeId = TYPE(SmViewShell);
263 4 : SfxViewShell* pViewShell = SfxViewShell::GetFirst();
264 82 : while (pViewShell)
265 : {
266 74 : if ((pViewShell->IsA(aSmViewTypeId)))
267 : {
268 0 : SmViewShell *pSmView = (SmViewShell *) pViewShell;
269 0 : pSmView->GetGraphicWindow().ApplyColorConfigValues( rColorCfg );
270 0 : SmEditWindow *pEditWin = pSmView->GetEditWindow();
271 0 : if (pEditWin)
272 0 : pEditWin->ApplyColorConfigValues( rColorCfg );
273 : }
274 74 : pViewShell = SfxViewShell::GetNext( *pViewShell );
275 : }
276 4 : }
277 :
278 30729 : svtools::ColorConfig & SmModule::GetColorConfig()
279 : {
280 30729 : if(!pColorConfig)
281 : {
282 4 : pColorConfig = new svtools::ColorConfig;
283 4 : ApplyColorConfigValues( *pColorConfig );
284 4 : pColorConfig->AddListener(this);
285 : }
286 30729 : return *pColorConfig;
287 : }
288 :
289 0 : void SmModule::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
290 : {
291 0 : ApplyColorConfigValues(*pColorConfig);
292 0 : }
293 :
294 3258 : SmConfig * SmModule::GetConfig()
295 : {
296 3258 : if(!pConfig)
297 4 : pConfig = new SmConfig;
298 3258 : return pConfig;
299 : }
300 :
301 2536 : SmSymbolManager & SmModule::GetSymbolManager()
302 : {
303 2536 : return GetConfig()->GetSymbolManager();
304 : }
305 :
306 1320 : SmLocalizedSymbolData & SmModule::GetLocSymbolData() const
307 : {
308 1320 : if (!pLocSymbolData)
309 4 : ((SmModule *) this)->pLocSymbolData = new SmLocalizedSymbolData;
310 1320 : return *pLocSymbolData;
311 : }
312 :
313 0 : void SmModule::GetState(SfxItemSet &rSet)
314 : {
315 0 : SfxWhichIter aIter(rSet);
316 :
317 0 : for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
318 0 : switch (nWh)
319 : {
320 : case SID_CONFIGEVENT :
321 0 : rSet.DisableItem(SID_CONFIGEVENT);
322 0 : break;
323 0 : }
324 0 : }
325 :
326 0 : SfxItemSet* SmModule::CreateItemSet( sal_uInt16 nId )
327 : {
328 0 : SfxItemSet* pRet = 0;
329 0 : if(nId == SID_SM_EDITOPTIONS)
330 : {
331 0 : pRet = new SfxItemSet(GetPool(),
332 : //TP_SMPRINT
333 : SID_PRINTSIZE, SID_PRINTSIZE,
334 : SID_PRINTZOOM, SID_PRINTZOOM,
335 : SID_PRINTTITLE, SID_PRINTTITLE,
336 : SID_PRINTTEXT, SID_PRINTTEXT,
337 : SID_PRINTFRAME, SID_PRINTFRAME,
338 : SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
339 : SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
340 0 : 0 );
341 :
342 0 : GetConfig()->ConfigToItemSet(*pRet);
343 : }
344 0 : return pRet;
345 : }
346 0 : void SmModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
347 : {
348 0 : if(nId == SID_SM_EDITOPTIONS)
349 : {
350 0 : GetConfig()->ItemSetToConfig(rSet);
351 : }
352 0 : }
353 0 : SfxTabPage* SmModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
354 : {
355 0 : SfxTabPage* pRet = 0;
356 0 : if(nId == SID_SM_TP_PRINTOPTIONS)
357 0 : pRet = SmPrintOptionsTabPage::Create( pParent, rSet );
358 0 : return pRet;
359 :
360 12 : }
361 :
362 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|