LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/starmath/source - smmod.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 95 166 57.2 %
Date: 2013-07-09 Functions: 25 35 71.4 %
Legend: Lines: hit not hit

          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         102 : TYPEINIT1( SmModule, SfxModule );
      45             : 
      46             : #define SmModule
      47             : #include "smslots.hxx"
      48             : 
      49             : #include <svx/xmlsecctrl.hxx>
      50             : 
      51             : 
      52             : 
      53        2745 : SmResId::SmResId( sal_uInt16 nId )
      54        2745 :     : ResId(nId, *SM_MOD()->GetResMgr())
      55             : {
      56        2745 : }
      57             : 
      58             : /////////////////////////////////////////////////////////////////
      59             : 
      60          10 : 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          10 :     n60NamesLang            ( LANGUAGE_NONE )
      70             : {
      71          10 :     FreeResource();
      72          10 : }
      73             : 
      74             : 
      75          10 : SmLocalizedSymbolData::~SmLocalizedSymbolData()
      76             : {
      77           5 :     delete p50NamesAry;
      78           5 :     delete p60NamesAry;
      79           5 : }
      80             : 
      81             : 
      82         330 : const String SmLocalizedSymbolData::GetUiSymbolName( const String &rExportName ) const
      83             : {
      84         330 :     String aRes;
      85             : 
      86         330 :     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
      87         330 :     const ResStringArray &rUiNames = rData.GetUiSymbolNamesArray();
      88         330 :     const ResStringArray &rExportNames = rData.GetExportSymbolNamesArray();
      89         330 :     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
      90       11055 :     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
      91             :     {
      92       11055 :         if (rExportNames.GetString(i).equals(rExportName))
      93             :         {
      94         330 :             aRes = rUiNames.GetString(i);
      95         330 :             break;
      96             :         }
      97             :     }
      98             : 
      99         330 :     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         335 : const String SmLocalizedSymbolData::GetUiSymbolSetName( const String &rExportName ) const
     125             : {
     126         335 :     String aRes;
     127             : 
     128         335 :     const SmLocalizedSymbolData &rData = SM_MOD()->GetLocSymbolData();
     129         335 :     const ResStringArray &rUiNames = rData.GetUiSymbolSetNamesArray();
     130         335 :     const ResStringArray &rExportNames = rData.GetExportSymbolSetNamesArray();
     131         335 :     sal_uInt16 nCount = sal::static_int_cast< xub_StrLen >(rExportNames.Count());
     132         395 :     for (sal_uInt16 i = 0;  i < nCount  &&  !aRes.Len();  ++i)
     133             :     {
     134         395 :         if (rExportNames.GetString(i).equals(rExportName))
     135             :         {
     136         335 :             aRes = rUiNames.GetString(i);
     137         335 :             break;
     138             :         }
     139             :     }
     140             : 
     141         335 :     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         312 : SFX_IMPL_INTERFACE(SmModule, SfxModule, SmResId(RID_APPLICATION))
     216             : {
     217           7 :     SFX_STATUSBAR_REGISTRATION(SmResId(RID_STATUSBAR));
     218           7 : }
     219             : 
     220             : 
     221           7 : 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           7 :     pVirtualDev( 0 )
     228             : {
     229           7 :     SetName(OUString("StarMath"));
     230             : 
     231           7 :     SvxModifyControl::RegisterControl(SID_DOC_MODIFIED, this);
     232           7 : }
     233             : 
     234             : 
     235           6 : SmModule::~SmModule()
     236             : {
     237           2 :     delete pConfig;
     238           2 :     if (pColorConfig)
     239           2 :         pColorConfig->RemoveListener(this);
     240           2 :     delete pColorConfig;
     241           2 :     delete pLocSymbolData;
     242           2 :     delete pSysLocale;
     243           2 :     delete pVirtualDev;
     244           4 : }
     245             : 
     246           7 : void SmModule::_CreateSysLocale() const
     247             : {
     248           7 :     SmModule* pThis = (SmModule*)this;
     249           7 :     pThis->pSysLocale = new SvtSysLocale;
     250           7 : }
     251             : 
     252           7 : void SmModule::_CreateVirtualDev() const
     253             : {
     254           7 :     SmModule* pThis = (SmModule*)this;
     255           7 :     pThis->pVirtualDev = new VirtualDevice;
     256           7 :     pThis->pVirtualDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
     257           7 : }
     258             : 
     259           7 : void SmModule::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
     260             : {
     261             :     //invalidate all graphic and edit windows
     262           7 :     const TypeId aSmViewTypeId = TYPE(SmViewShell);
     263           7 :     SfxViewShell* pViewShell = SfxViewShell::GetFirst();
     264          15 :     while (pViewShell)
     265             :     {
     266           1 :         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           1 :         pViewShell = SfxViewShell::GetNext( *pViewShell );
     275             :     }
     276           7 : }
     277             : 
     278       33272 : svtools::ColorConfig & SmModule::GetColorConfig()
     279             : {
     280       33272 :     if(!pColorConfig)
     281             :     {
     282           7 :         pColorConfig = new svtools::ColorConfig;
     283           7 :         ApplyColorConfigValues( *pColorConfig );
     284           7 :         pColorConfig->AddListener(this);
     285             :     }
     286       33272 :     return *pColorConfig;
     287             : }
     288             : 
     289           0 : void SmModule::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
     290             : {
     291           0 :     ApplyColorConfigValues(*pColorConfig);
     292           0 : }
     293             : 
     294        2708 : SmConfig * SmModule::GetConfig()
     295             : {
     296        2708 :     if(!pConfig)
     297           7 :         pConfig = new SmConfig;
     298        2708 :     return pConfig;
     299             : }
     300             : 
     301        1784 : SmSymbolManager & SmModule::GetSymbolManager()
     302             : {
     303        1784 :     return GetConfig()->GetSymbolManager();
     304             : }
     305             : 
     306        1585 : SmLocalizedSymbolData & SmModule::GetLocSymbolData() const
     307             : {
     308        1585 :     if (!pLocSymbolData)
     309           5 :         ((SmModule *) this)->pLocSymbolData = new SmLocalizedSymbolData;
     310        1585 :     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          21 : }
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10