xref: /aoo41x/main/starmath/source/smmod.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
30 
31 
32 #include <tools/globname.hxx>
33 #include <vcl/status.hxx>
34 #include <sfx2/msg.hxx>
35 #include <sfx2/app.hxx>
36 #include <sfx2/objface.hxx>
37 #include <svl/whiter.hxx>
38 #include <sfx2/request.hxx>
39 #include <sfx2/sfx.hrc>
40 #include <sfx2/viewsh.hxx>
41 #include <vcl/wrkwin.hxx>
42 #ifndef _SVX_SVXIDS_HRC //autogen
43 #include <svx/svxids.hrc>
44 #endif
45 #include <vcl/msgbox.hxx>
46 #include <vcl/virdev.hxx>
47 #include <unotools/syslocale.hxx>
48 #include <tools/rtti.hxx>
49 #include "smmod.hxx"
50 #include "symbol.hxx"
51 #include "config.hxx"
52 #ifndef _DIALOG_HXX
53 #include "dialog.hxx"
54 #endif
55 #include "edit.hxx"
56 #include "view.hxx"
57 #include "starmath.hrc"
58 
59 TYPEINIT1( SmModule, SfxModule );
60 
61 #define SmModule
62 #include "smslots.hxx"
63 
64 #include <svx/xmlsecctrl.hxx>
65 
66 
67 
68 SmResId::SmResId( sal_uInt16 nId )
69 	: ResId(nId, *SM_MOD()->GetResMgr())
70 {
71 }
72 
73 /////////////////////////////////////////////////////////////////
74 
75 SmLocalizedSymbolData::SmLocalizedSymbolData() :
76     Resource( SmResId(RID_LOCALIZED_NAMES) ),
77 	aUiSymbolNamesAry		( SmResId(RID_UI_SYMBOL_NAMES) ),
78     aExportSymbolNamesAry   ( SmResId(RID_EXPORT_SYMBOL_NAMES) ),
79     aUiSymbolSetNamesAry    ( SmResId(RID_UI_SYMBOLSET_NAMES) ),
80     aExportSymbolSetNamesAry( SmResId(RID_EXPORT_SYMBOLSET_NAMES) ),
81     p50NamesAry             ( 0 ),
82     p60NamesAry             ( 0 ),
83     n50NamesLang            ( LANGUAGE_NONE ),
84     n60NamesLang            ( LANGUAGE_NONE )
85 {
86 	FreeResource();
87 }
88 
89 
90 SmLocalizedSymbolData::~SmLocalizedSymbolData()
91 {
92     delete p50NamesAry;
93     delete p60NamesAry;
94 }
95 
96 
97 const String SmLocalizedSymbolData::GetUiSymbolName( const String &rExportName ) const
98 {
99 	String aRes;
100 
101     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
102     const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
103     const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
104     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
105     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
106 	{
107         if (rExportName == rExportNames.GetString(i))
108 		{
109             aRes = rUiNames.GetString(i);
110 			break;
111 		}
112 	}
113 
114 	return aRes;
115 }
116 
117 
118 const String SmLocalizedSymbolData::GetExportSymbolName( const String &rUiName ) const
119 {
120 	String aRes;
121 
122     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
123     const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
124     const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
125     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
126     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
127 	{
128         if (rUiName == rUiNames.GetString(i))
129 		{
130 			aRes = rExportNames.GetString(i);
131 			break;
132 		}
133 	}
134 
135 	return aRes;
136 }
137 
138 
139 const String SmLocalizedSymbolData::GetUiSymbolSetName( const String &rExportName ) const
140 {
141 	String aRes;
142 
143     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
144     const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
145     const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
146     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
147     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
148 	{
149         if (rExportName == rExportNames.GetString(i))
150 		{
151             aRes = rUiNames.GetString(i);
152 			break;
153 		}
154 	}
155 
156 	return aRes;
157 }
158 
159 
160 const String SmLocalizedSymbolData::GetExportSymbolSetName( const String &rUiName ) const
161 {
162 	String aRes;
163 
164     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
165     const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
166     const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
167     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
168     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
169 	{
170         if (rUiName == rUiNames.GetString(i))
171 		{
172 			aRes = rExportNames.GetString(i);
173 			break;
174 		}
175 	}
176 
177 	return aRes;
178 }
179 
180 
181 const ResStringArray* SmLocalizedSymbolData::Get50NamesArray( LanguageType nLang )
182 {
183     if (nLang != n50NamesLang)
184     {
185         int nRID;
186         switch (nLang)
187         {
188             case LANGUAGE_FRENCH    : nRID = RID_FRENCH_50_NAMES;  break;
189             case LANGUAGE_ITALIAN   : nRID = RID_ITALIAN_50_NAMES;  break;
190             case LANGUAGE_SWEDISH   : nRID = RID_SWEDISH_50_NAMES;  break;
191             case LANGUAGE_SPANISH   : nRID = RID_SPANISH_50_NAMES;  break;
192             default                 : nRID = -1;  break;
193         }
194         delete p50NamesAry;
195         p50NamesAry = 0;
196         n50NamesLang = nLang;
197         if (-1 != nRID)
198             p50NamesAry = new SmNamesArray( n50NamesLang, nRID );
199     }
200 
201     return p50NamesAry ? &p50NamesAry->GetNamesArray() : 0;
202 }
203 
204 
205 const ResStringArray* SmLocalizedSymbolData::Get60NamesArray( LanguageType nLang )
206 {
207     if (nLang != n60NamesLang)
208     {
209         int nRID;
210         switch (nLang)
211         {
212             case LANGUAGE_FRENCH    : nRID = RID_FRENCH_60_NAMES;  break;
213             case LANGUAGE_ITALIAN   : nRID = RID_ITALIAN_60_NAMES;  break;
214             case LANGUAGE_SWEDISH   : nRID = RID_SWEDISH_60_NAMES;  break;
215             case LANGUAGE_SPANISH   : nRID = RID_SPANISH_60_NAMES;  break;
216             default                 : nRID = -1;  break;
217         }
218         delete p60NamesAry;
219         p60NamesAry = 0;
220         n60NamesLang = nLang;
221         if (-1 != nRID)
222             p60NamesAry = new SmNamesArray( n60NamesLang, nRID );
223     }
224 
225     return p60NamesAry ? &p60NamesAry->GetNamesArray() : 0;
226 }
227 
228 /////////////////////////////////////////////////////////////////
229 
230 SFX_IMPL_INTERFACE(SmModule, SfxModule, SmResId(RID_APPLICATION))
231 {
232 	SFX_STATUSBAR_REGISTRATION(SmResId(RID_STATUSBAR));
233 }
234 
235 
236 SmModule::SmModule(SfxObjectFactory* pObjFact) :
237 	SfxModule(SfxApplication::CreateResManager("sm"), sal_False, pObjFact, NULL),
238     pColorConfig( 0 ),
239     pConfig( 0 ),
240     pLocSymbolData( 0 ),
241     pSysLocale( 0 ),
242     pVirtualDev( 0 )
243 {
244 	SetName( C2S("StarMath" ));
245 }
246 
247 
248 SmModule::~SmModule()
249 {
250 	delete pConfig;
251 	if (pColorConfig)
252 		pColorConfig->RemoveListener(this);
253     delete pColorConfig;
254     delete pLocSymbolData;
255 	delete pSysLocale;
256     delete pVirtualDev;
257 }
258 
259 void SmModule::_CreateSysLocale() const
260 {
261 	SmModule* pThis = (SmModule*)this;
262 	pThis->pSysLocale = new SvtSysLocale;
263 }
264 
265 void SmModule::_CreateVirtualDev() const
266 {
267 	SmModule* pThis = (SmModule*)this;
268     pThis->pVirtualDev = new VirtualDevice;
269     pThis->pVirtualDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
270 }
271 
272 void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
273 {
274     //invalidate all graphic and edit windows
275     const TypeId aSmViewTypeId = TYPE(SmViewShell);
276     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
277     while (pViewShell)
278     {
279         if ((pViewShell->IsA(aSmViewTypeId)))
280         {
281             SmViewShell *pSmView = (SmViewShell *) pViewShell;
282             pSmView->GetGraphicWindow().ApplyColorConfigValues( rColorCfg );
283             SmEditWindow *pEditWin = pSmView->GetEditWindow();
284             if (pEditWin)
285                 pEditWin->ApplyColorConfigValues( rColorCfg );
286         }
287         pViewShell = SfxViewShell::GetNext( *pViewShell );
288     }
289 }
290 
291 svtools::ColorConfig & SmModule::GetColorConfig()
292 {
293     if(!pColorConfig)
294     {
295         pColorConfig = new svtools::ColorConfig;
296         ApplyColorConfigValues( *pColorConfig );
297         pColorConfig->AddListener(this);
298     }
299     return *pColorConfig;
300 }
301 
302 void SmModule::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
303 {
304     ApplyColorConfigValues(*pColorConfig);
305 }
306 
307 SmConfig * SmModule::GetConfig()
308 {
309     if(!pConfig)
310         pConfig = new SmConfig;
311     return pConfig;
312 }
313 
314 SmSymbolManager & SmModule::GetSymbolManager()
315 {
316     return GetConfig()->GetSymbolManager();
317 }
318 
319 SmLocalizedSymbolData & SmModule::GetLocSymbolData() const
320 {
321     if (!pLocSymbolData)
322         ((SmModule *) this)->pLocSymbolData = new SmLocalizedSymbolData;
323     return *pLocSymbolData;
324 }
325 
326 void SmModule::GetState(SfxItemSet &rSet)
327 {
328 	SfxWhichIter aIter(rSet);
329 
330 	for (sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
331 		switch (nWh)
332 		{
333 			case SID_CONFIGEVENT :
334 				rSet.DisableItem(SID_CONFIGEVENT);
335 				break;
336 		}
337 }
338 
339 /* -----------------15.02.99 12:45-------------------
340  *
341  * --------------------------------------------------*/
342 SfxItemSet*	 SmModule::CreateItemSet( sal_uInt16 nId )
343 {
344 	SfxItemSet*	 pRet = 0;
345 	if(nId == SID_SM_EDITOPTIONS)
346 	{
347 		pRet = new SfxItemSet(GetPool(),
348 							 //TP_SMPRINT
349 							 SID_PRINTSIZE, 		SID_PRINTSIZE,
350 							 SID_PRINTZOOM, 		SID_PRINTZOOM,
351 							 SID_PRINTTITLE,		SID_PRINTTITLE,
352 							 SID_PRINTTEXT, 		SID_PRINTTEXT,
353 							 SID_PRINTFRAME,		SID_PRINTFRAME,
354 							 SID_NO_RIGHT_SPACES,	SID_NO_RIGHT_SPACES,
355                              SID_SAVE_ONLY_USED_SYMBOLS, SID_SAVE_ONLY_USED_SYMBOLS,
356 							 0 );
357 
358 			GetConfig()->ConfigToItemSet(*pRet);
359 	}
360 	return pRet;
361 }
362 /* -----------------15.02.99 12:45-------------------
363  *
364  * --------------------------------------------------*/
365 void SmModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet )
366 {
367 	if(nId == SID_SM_EDITOPTIONS)
368 	{
369 		GetConfig()->ItemSetToConfig(rSet);
370 	}
371 }
372 /* -----------------15.02.99 12:45-------------------
373  *
374  * --------------------------------------------------*/
375 SfxTabPage*	 SmModule::CreateTabPage( sal_uInt16 nId, Window* pParent, const SfxItemSet& rSet )
376 {
377 	SfxTabPage*	 pRet = 0;
378 	if(nId == SID_SM_TP_PRINTOPTIONS)
379 		pRet = SmPrintOptionsTabPage::Create( pParent, rSet );
380 	return pRet;
381 
382 }
383