merge the formfield patch from ooo-build
[ooovba.git] / starmath / source / smmod.cxx
blobbbfefb705f3705511d6f62d46c9e1bb9f0922240
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: smmod.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #include <tools/globname.hxx>
36 #include <vcl/status.hxx>
37 #include <sfx2/msg.hxx>
38 #include <sfx2/app.hxx>
39 #include <sfx2/objface.hxx>
40 #include <svtools/whiter.hxx>
41 #include <sfx2/request.hxx>
42 #include <sfx2/sfx.hrc>
43 #include <sfx2/viewsh.hxx>
44 #include <vcl/wrkwin.hxx>
45 #ifndef _SVX_SVXIDS_HRC //autogen
46 #include <svx/svxids.hrc>
47 #endif
48 #include <vcl/msgbox.hxx>
49 #include <vcl/virdev.hxx>
50 #include <svtools/syslocale.hxx>
51 #include <tools/rtti.hxx>
52 #include "smmod.hxx"
53 #include "symbol.hxx"
54 #include "config.hxx"
55 #ifndef _DIALOG_HXX
56 #include "dialog.hxx"
57 #endif
58 #include "edit.hxx"
59 #include "view.hxx"
60 #include "starmath.hrc"
61 #include "svx/modctrl.hxx"
63 TYPEINIT1( SmModule, SfxModule );
65 #define SmModule
66 #include "smslots.hxx"
68 #include <svx/xmlsecctrl.hxx>
72 SmResId::SmResId( USHORT nId )
73 : ResId(nId, *SM_MOD()->GetResMgr())
77 /////////////////////////////////////////////////////////////////
79 SmLocalizedSymbolData::SmLocalizedSymbolData() :
80 Resource( SmResId(RID_LOCALIZED_NAMES) ),
81 aUiSymbolNamesAry ( SmResId(RID_UI_SYMBOL_NAMES) ),
82 aExportSymbolNamesAry ( SmResId(RID_EXPORT_SYMBOL_NAMES) ),
83 aUiSymbolSetNamesAry ( SmResId(RID_UI_SYMBOLSET_NAMES) ),
84 aExportSymbolSetNamesAry( SmResId(RID_EXPORT_SYMBOLSET_NAMES) ),
85 p50NamesAry ( 0 ),
86 p60NamesAry ( 0 ),
87 n50NamesLang ( LANGUAGE_NONE ),
88 n60NamesLang ( LANGUAGE_NONE )
90 FreeResource();
94 SmLocalizedSymbolData::~SmLocalizedSymbolData()
96 delete p50NamesAry;
97 delete p60NamesAry;
101 const String SmLocalizedSymbolData::GetUiSymbolName( const String &rExportName ) const
103 String aRes;
105 const SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
106 const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
107 const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
108 USHORT nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
109 for (USHORT i = 0; i < nCount && !aRes.Len(); ++i)
111 if (rExportName == rExportNames.GetString(i))
113 aRes = rUiNames.GetString(i);
114 break;
118 return aRes;
122 const String SmLocalizedSymbolData::GetExportSymbolName( const String &rUiName ) const
124 String aRes;
126 const SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
127 const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
128 const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
129 USHORT nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
130 for (USHORT i = 0; i < nCount && !aRes.Len(); ++i)
132 if (rUiName == rUiNames.GetString(i))
134 aRes = rExportNames.GetString(i);
135 break;
139 return aRes;
143 const String SmLocalizedSymbolData::GetUiSymbolSetName( const String &rExportName ) const
145 String aRes;
147 const SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
148 const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
149 const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
150 USHORT nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
151 for (USHORT i = 0; i < nCount && !aRes.Len(); ++i)
153 if (rExportName == rExportNames.GetString(i))
155 aRes = rUiNames.GetString(i);
156 break;
160 return aRes;
164 const String SmLocalizedSymbolData::GetExportSymbolSetName( const String &rUiName ) const
166 String aRes;
168 const SmLocalizedSymbolData &rData = SM_MOD1()->GetLocSymbolData();
169 const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
170 const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
171 USHORT nCount = sal::static_int_cast< xub_StrLen >(rUiNames.Count());
172 for (USHORT i = 0; i < nCount && !aRes.Len(); ++i)
174 if (rUiName == rUiNames.GetString(i))
176 aRes = rExportNames.GetString(i);
177 break;
181 return aRes;
185 const ResStringArray* SmLocalizedSymbolData::Get50NamesArray( LanguageType nLang )
187 if (nLang != n50NamesLang)
189 int nRID;
190 switch (nLang)
192 case LANGUAGE_FRENCH : nRID = RID_FRENCH_50_NAMES; break;
193 case LANGUAGE_ITALIAN : nRID = RID_ITALIAN_50_NAMES; break;
194 case LANGUAGE_SWEDISH : nRID = RID_SWEDISH_50_NAMES; break;
195 case LANGUAGE_SPANISH : nRID = RID_SPANISH_50_NAMES; break;
196 default : nRID = -1; break;
198 delete p50NamesAry;
199 p50NamesAry = 0;
200 n50NamesLang = nLang;
201 if (-1 != nRID)
202 p50NamesAry = new SmNamesArray( n50NamesLang, nRID );
205 return p50NamesAry ? &p50NamesAry->GetNamesArray() : 0;
209 const ResStringArray* SmLocalizedSymbolData::Get60NamesArray( LanguageType nLang )
211 if (nLang != n60NamesLang)
213 int nRID;
214 switch (nLang)
216 case LANGUAGE_FRENCH : nRID = RID_FRENCH_60_NAMES; break;
217 case LANGUAGE_ITALIAN : nRID = RID_ITALIAN_60_NAMES; break;
218 case LANGUAGE_SWEDISH : nRID = RID_SWEDISH_60_NAMES; break;
219 case LANGUAGE_SPANISH : nRID = RID_SPANISH_60_NAMES; break;
220 default : nRID = -1; break;
222 delete p60NamesAry;
223 p60NamesAry = 0;
224 n60NamesLang = nLang;
225 if (-1 != nRID)
226 p60NamesAry = new SmNamesArray( n60NamesLang, nRID );
229 return p60NamesAry ? &p60NamesAry->GetNamesArray() : 0;
232 /////////////////////////////////////////////////////////////////
234 SFX_IMPL_INTERFACE(SmModule, SfxModule, SmResId(RID_APPLICATION))
236 SFX_STATUSBAR_REGISTRATION(SmResId(RID_STATUSBAR));
240 SmModule::SmModule(SfxObjectFactory* pObjFact) :
241 SfxModule(SfxApplication::CreateResManager("sm"), FALSE, pObjFact, NULL),
242 pColorConfig( 0 ),
243 pConfig( 0 ),
244 pLocSymbolData( 0 ),
245 pSysLocale( 0 ),
246 pVirtualDev( 0 )
248 SetName( C2S("StarMath" ));
250 SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
254 SmModule::~SmModule()
256 delete pConfig;
257 delete pColorConfig;
258 delete pLocSymbolData;
259 delete pSysLocale;
260 delete pVirtualDev;
263 void SmModule::_CreateSysLocale() const
265 SmModule* pThis = (SmModule*)this;
266 pThis->pSysLocale = new SvtSysLocale;
269 void SmModule::_CreateVirtualDev() const
271 SmModule* pThis = (SmModule*)this;
272 pThis->pVirtualDev = new VirtualDevice;
273 pThis->pVirtualDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
276 void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
278 //invalidate all graphic and edit windows
279 const TypeId aSmViewTypeId = TYPE(SmViewShell);
280 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
281 while (pViewShell)
283 if ((pViewShell->IsA(aSmViewTypeId)))
285 SmViewShell *pSmView = (SmViewShell *) pViewShell;
286 pSmView->GetGraphicWindow().ApplyColorConfigValues( rColorCfg );
287 SmEditWindow *pEditWin = pSmView->GetEditWindow();
288 if (pEditWin)
289 pEditWin->ApplyColorConfigValues( rColorCfg );
291 pViewShell = SfxViewShell::GetNext( *pViewShell );
295 svtools::ColorConfig & SmModule::GetColorConfig()
297 if(!pColorConfig)
299 pColorConfig = new svtools::ColorConfig;
300 ApplyColorConfigValues( *pColorConfig );
301 StartListening( *pColorConfig );
303 return *pColorConfig;
306 void SmModule::Notify( SfxBroadcaster & /*rBC*/, const SfxHint &rHint )
308 if (rHint.ISA(SfxSimpleHint))
310 ULONG nHintId = ((SfxSimpleHint&)rHint).GetId();
311 if (SFX_HINT_COLORS_CHANGED == nHintId)
312 ApplyColorConfigValues(*pColorConfig);
316 SmConfig * SmModule::GetConfig()
318 if(!pConfig)
319 pConfig = new SmConfig;
320 return pConfig;
323 SmSymSetManager & SmModule::GetSymSetManager()
325 return GetConfig()->GetSymSetManager();
328 SmLocalizedSymbolData & SmModule::GetLocSymbolData() const
330 if (!pLocSymbolData)
331 ((SmModule *) this)->pLocSymbolData = new SmLocalizedSymbolData;
332 return *pLocSymbolData;
335 void SmModule::GetState(SfxItemSet &rSet)
337 SfxWhichIter aIter(rSet);
339 for (USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich())
340 switch (nWh)
342 case SID_CONFIGEVENT :
343 rSet.DisableItem(SID_CONFIGEVENT);
344 break;
348 void SmModule::FillStatusBar(StatusBar &rBar)
350 rBar.InsertItem(SID_TEXTSTATUS, 300, SIB_LEFT | SIB_IN);
351 rBar.InsertItem(SID_ATTR_ZOOM, rBar.GetTextWidth(C2S(" 100% ")));
352 rBar.InsertItem(SID_MODIFYSTATUS, rBar.GetTextWidth(C2S(" * ")));
353 rBar.InsertItem( SID_SIGNATURE, XmlSecStatusBarControl::GetDefItemWidth( rBar ), SIB_USERDRAW );
354 rBar.SetHelpId(SID_SIGNATURE, SID_SIGNATURE);
358 /* -----------------15.02.99 12:45-------------------
360 * --------------------------------------------------*/
361 SfxItemSet* SmModule::CreateItemSet( USHORT nId )
363 SfxItemSet* pRet = 0;
364 if(nId == SID_SM_EDITOPTIONS)
366 pRet = new SfxItemSet(GetPool(),
367 //TP_SMPRINT
368 SID_PRINTSIZE, SID_PRINTSIZE,
369 SID_PRINTZOOM, SID_PRINTZOOM,
370 SID_PRINTTITLE, SID_PRINTTITLE,
371 SID_PRINTTEXT, SID_PRINTTEXT,
372 SID_PRINTFRAME, SID_PRINTFRAME,
373 SID_NO_RIGHT_SPACES, SID_NO_RIGHT_SPACES,
374 0 );
376 GetConfig()->ConfigToItemSet(*pRet);
378 return pRet;
380 /* -----------------15.02.99 12:45-------------------
382 * --------------------------------------------------*/
383 void SmModule::ApplyItemSet( USHORT nId, const SfxItemSet& rSet )
385 if(nId == SID_SM_EDITOPTIONS)
387 GetConfig()->ItemSetToConfig(rSet);
390 /* -----------------15.02.99 12:45-------------------
392 * --------------------------------------------------*/
393 SfxTabPage* SmModule::CreateTabPage( USHORT nId, Window* pParent, const SfxItemSet& rSet )
395 SfxTabPage* pRet = 0;
396 if(nId == SID_SM_TP_PRINTOPTIONS)
397 pRet = SmPrintOptionsTabPage::Create( pParent, rSet );
398 return pRet;