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