LCOV - code coverage report
Current view: top level - sw/source/core/uibase/utlui - initui.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 50 121 41.3 %
Date: 2014-04-11 Functions: 7 26 26.9 %
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 <unotools/localedatawrapper.hxx>
      21             : #include <viewsh.hxx>
      22             : #include <initui.hxx>
      23             : #include <edtwin.hxx>
      24             : #include <shellres.hxx>
      25             : #include <fldbas.hxx>
      26             : #include <glosdoc.hxx>
      27             : #include <gloslst.hxx>
      28             : 
      29             : #include <utlui.hrc>
      30             : #include <initui.hrc>
      31             : #include <comcore.hrc>
      32             : #include <authfld.hxx>
      33             : #include <dbmgr.hxx>
      34             : #include <unotools/syslocale.hxx>
      35             : 
      36             : #include <unomid.h>
      37             : 
      38             : // Global Pointer
      39             : 
      40             : SwGlossaries*       pGlossaries = 0;
      41             : 
      42             : // Provides all needed paths. Is initialized by UI.
      43             : SwGlossaryList*     pGlossaryList = 0;
      44             : 
      45             : namespace
      46             : {
      47             : 
      48             : enum CachedStringID
      49             : {
      50             :     OldGrfCat,
      51             :     OldTabCat,
      52             :     OldFrmCat,
      53             :     OldDrwCat,
      54             :     CurrGlosGroup,
      55             :     CachedStrings
      56             : };
      57             : 
      58             : OUString *StringCache[CachedStrings] = {0};
      59             : 
      60           0 : inline OUString GetCachedString(CachedStringID id)
      61             : {
      62           0 :     return StringCache[id] ? *StringCache[id] : OUString();
      63             : }
      64             : 
      65           0 : inline void SetCachedString(CachedStringID id, const OUString& sStr)
      66             : {
      67           0 :     if (StringCache[id])
      68             :     {
      69           0 :         *StringCache[id] = sStr;
      70             :     }
      71             :     else
      72             :     {
      73           0 :         StringCache[id] = new OUString(sStr);
      74             :     }
      75           0 : }
      76             : 
      77          37 : void ClearStringCache()
      78             : {
      79         222 :     for (int i=0; i<CachedStrings; ++i)
      80             :     {
      81         185 :         delete StringCache[i];
      82             :     }
      83          37 : }
      84             : 
      85             : }
      86             : 
      87           0 : OUString GetOldGrfCat()
      88             : {
      89           0 :     return GetCachedString(OldGrfCat);
      90             : }
      91             : 
      92           0 : void SetOldGrfCat(const OUString& sStr)
      93             : {
      94           0 :     SetCachedString(OldGrfCat, sStr);
      95           0 : }
      96             : 
      97           0 : OUString GetOldTabCat()
      98             : {
      99           0 :     return GetCachedString(OldTabCat);
     100             : }
     101             : 
     102           0 : void SetOldTabCat(const OUString& sStr)
     103             : {
     104           0 :     SetCachedString(OldTabCat, sStr);
     105           0 : }
     106             : 
     107           0 : OUString GetOldFrmCat()
     108             : {
     109           0 :     return GetCachedString(OldFrmCat);
     110             : }
     111             : 
     112           0 : void SetOldFrmCat(const OUString& sStr)
     113             : {
     114           0 :     SetCachedString(OldFrmCat, sStr);
     115           0 : }
     116             : 
     117           0 : OUString GetOldDrwCat()
     118             : {
     119           0 :     return GetCachedString(OldDrwCat);
     120             : }
     121             : 
     122           0 : void SetOldDrwCat(const OUString& sStr)
     123             : {
     124           0 :     SetCachedString(OldDrwCat, sStr);
     125           0 : }
     126             : 
     127           0 : OUString GetCurrGlosGroup()
     128             : {
     129           0 :     return GetCachedString(CurrGlosGroup);
     130             : }
     131             : 
     132           0 : void SetCurrGlosGroup(const OUString& sStr)
     133             : {
     134           0 :     SetCachedString(CurrGlosGroup, sStr);
     135           0 : }
     136             : 
     137             : namespace
     138             : {
     139             : 
     140             : std::vector<OUString>* pAuthFieldNameList = 0;
     141             : std::vector<OUString>* pAuthFieldTypeList = 0;
     142             : 
     143             : }
     144             : 
     145             : // Finish UI
     146             : 
     147          37 : void _FinitUI()
     148             : {
     149          37 :     SwNewDBMgr::RemoveDbtoolsClient();
     150          37 :     delete SwViewShell::GetShellRes();
     151          37 :     SwViewShell::SetShellRes( 0 );
     152             : 
     153          37 :     SwEditWin::_FinitStaticData();
     154             : 
     155          37 :     DELETEZ(pGlossaries);
     156             : 
     157          37 :     delete SwFieldType::pFldNames;
     158             : 
     159          37 :     ClearStringCache();
     160          37 :     delete pGlossaryList;
     161          37 :     delete pAuthFieldNameList;
     162          37 :     delete pAuthFieldTypeList;
     163             : 
     164          37 : }
     165             : 
     166             : // Initialise
     167             : 
     168          37 : void _InitUI()
     169             : {
     170             :     // ShellResource gives the CORE the possibility to work with resources.
     171          37 :     SwViewShell::SetShellRes( new ShellResource );
     172          37 :     SwEditWin::_InitStaticData();
     173          37 : }
     174             : 
     175          38 : ShellResource::ShellResource()
     176             :     : Resource( SW_RES(RID_SW_SHELLRES) ),
     177             :     aPostItAuthor( SW_RES( STR_POSTIT_AUTHOR ) ),
     178             :     aPostItPage( SW_RES( STR_POSTIT_PAGE ) ),
     179             :     aPostItLine( SW_RES( STR_POSTIT_LINE ) ),
     180             : 
     181             :     aCalc_Syntax( SW_RES( STR_CALC_SYNTAX ) ),
     182             :     aCalc_ZeroDiv( SW_RES( STR_CALC_ZERODIV ) ),
     183             :     aCalc_Brack( SW_RES( STR_CALC_BRACK ) ),
     184             :     aCalc_Pow( SW_RES( STR_CALC_POW ) ),
     185             :     aCalc_VarNFnd( SW_RES( STR_CALC_VARNFND ) ),
     186             :     aCalc_Overflow( SW_RES( STR_CALC_OVERFLOW ) ),
     187             :     aCalc_WrongTime( SW_RES( STR_CALC_WRONGTIME ) ),
     188             :     aCalc_Default( SW_RES( STR_CALC_DEFAULT ) ),
     189             :     aCalc_Error( SW_RES( STR_CALC_ERROR ) ),
     190             : 
     191             :     aGetRefFld_Up( SW_RES( STR_GETREFFLD_UP ) ),
     192             :     aGetRefFld_Down( SW_RES( STR_GETREFFLD_DOWN ) ),
     193             :     // #i81002#
     194             :     aGetRefFld_RefItemNotFound( SW_RES( STR_GETREFFLD_REFITEMNOTFOUND ) ),
     195             :     aStrAllPageHeadFoot( SW_RES( STR_ALLPAGE_HEADFOOT ) ),
     196             :     aStrNone( SW_RES( STR_TEMPLATE_NONE )),
     197             :     aFixedStr( SW_RES( STR_FIELD_FIXED )),
     198             :     sDurationFormat( SW_RES( STR_DURATION_FORMAT )),
     199             : 
     200             :     aTOXIndexName(          SW_RES(STR_TOI)),
     201             :     aTOXUserName(           SW_RES(STR_TOU)),
     202             :     aTOXContentName(        SW_RES(STR_TOC)),
     203             :     aTOXIllustrationsName(  SW_RES(STR_TOX_ILL)),
     204             :     aTOXObjectsName(        SW_RES(STR_TOX_OBJ)),
     205             :     aTOXTablesName(         SW_RES(STR_TOX_TBL)),
     206             :     aTOXAuthoritiesName(    SW_RES(STR_TOX_AUTH)),
     207             :     aTOXCitationName(    SW_RES(STR_TOX_CITATION)),
     208             :     aLinkCtrlClick(SW_RESSTR(STR_LINK_CTRL_CLICK)),
     209             :     aLinkClick(SW_RESSTR(STR_LINK_CLICK)),
     210             :     pAutoFmtNameLst(0),
     211             :     sPageDescFirstName(     SW_RES(STR_PAGEDESC_FIRSTNAME)),
     212             :     sPageDescFollowName(    SW_RES(STR_PAGEDESC_FOLLOWNAME)),
     213          38 :     sPageDescName(          SW_RES(STR_PAGEDESC_NAME))
     214             : {
     215          38 :     const sal_uInt16 nCount = FLD_DOCINFO_END - FLD_DOCINFO_BEGIN;
     216             : 
     217          38 :     KeyCode aCode( KEY_SPACE );
     218          38 :     KeyCode aModifiedCode( KEY_SPACE, KEY_MOD1 );
     219          38 :     OUString aModStr( aModifiedCode.GetName() );
     220          38 :     aModStr = aModStr.replaceFirst(aCode.GetName(), OUString());
     221          38 :     aModStr = aModStr.replaceAll("+", OUString());
     222          38 :     aLinkCtrlClick = aLinkCtrlClick.replaceAll("%s", aModStr);
     223             : 
     224         380 :     for(sal_uInt16 i = 0; i < nCount; ++i)
     225         342 :         aDocInfoLst.push_back(OUString(SW_RESSTR(FLD_DOCINFO_BEGIN + i)));
     226             : 
     227          38 :     FreeResource();
     228          38 : }
     229             : 
     230          76 : ShellResource::~ShellResource()
     231             : {
     232          38 :     delete pAutoFmtNameLst;
     233          38 : }
     234             : 
     235          15 : OUString ShellResource::GetPageDescName(sal_uInt16 nNo, PageNameMode eMode)
     236             : {
     237          15 :     OUString sRet;
     238             : 
     239          15 :     switch (eMode)
     240             :     {
     241             :         case NORMAL_PAGE:
     242          13 :             sRet = sPageDescName;
     243          13 :             break;
     244             :         case FIRST_PAGE:
     245           1 :             sRet = sPageDescFirstName;
     246           1 :             break;
     247             :         case FOLLOW_PAGE:
     248           1 :             sRet = sPageDescFollowName;
     249           1 :             break;
     250             :     }
     251             : 
     252          15 :     return sRet.replaceFirst( "$(ARG1)", OUString::number( nNo ));
     253             : }
     254             : 
     255           5 : SwGlossaries* GetGlossaries()
     256             : {
     257           5 :     if (!pGlossaries)
     258           2 :         pGlossaries = new SwGlossaries;
     259           5 :     return (pGlossaries);
     260             : }
     261             : 
     262           0 : bool HasGlossaryList()
     263             : {
     264           0 :     return pGlossaryList != 0;
     265             : }
     266             : 
     267           0 : SwGlossaryList* GetGlossaryList()
     268             : {
     269           0 :     if(!pGlossaryList)
     270           0 :         pGlossaryList = new SwGlossaryList();
     271             : 
     272           0 :     return pGlossaryList;
     273             : }
     274             : 
     275           0 : struct ImpAutoFmtNameListLoader : public Resource
     276             : {
     277             :     ImpAutoFmtNameListLoader( std::vector<OUString>& rLst );
     278             : };
     279             : 
     280           0 : void ShellResource::_GetAutoFmtNameLst() const
     281             : {
     282             :     assert(!pAutoFmtNameLst);
     283           0 :     pAutoFmtNameLst = new std::vector<OUString>;
     284           0 :     pAutoFmtNameLst->reserve(STR_AUTOFMTREDL_END);
     285           0 :     ImpAutoFmtNameListLoader aTmp(*pAutoFmtNameLst);
     286           0 : }
     287             : 
     288           0 : ImpAutoFmtNameListLoader::ImpAutoFmtNameListLoader( std::vector<OUString>& rLst )
     289           0 :     : Resource( ResId(RID_SHELLRES_AUTOFMTSTRS, *pSwResMgr) )
     290             : {
     291           0 :     for( sal_uInt16 n = 0; n < STR_AUTOFMTREDL_END; ++n )
     292             :     {
     293           0 :         OUString p(ResId(n + 1, *pSwResMgr));
     294           0 :         if(STR_AUTOFMTREDL_TYPO == n)
     295             :         {
     296             : #ifdef WNT
     297             :             // For Windows, a special treatment is necessary because MS has
     298             :             // forgotten some characters in the dialog font here.
     299             :             p = p.replaceFirst("%1", ",,");
     300             :             p = p.replaceFirst("%2", "''");
     301             : #else
     302           0 :             const SvtSysLocale aSysLocale;
     303           0 :             const LocaleDataWrapper& rLclD = aSysLocale.GetLocaleData();
     304             :             // With real operating systems it also works without special handling.
     305           0 :             p = p.replaceFirst("%1", rLclD.getDoubleQuotationMarkStart());
     306           0 :             p = p.replaceFirst("%2", rLclD.getDoubleQuotationMarkEnd());
     307             : #endif
     308             :         }
     309           0 :         rLst.insert(rLst.begin() + n, p);
     310           0 :     }
     311           0 :     FreeResource();
     312           0 : }
     313             : 
     314           0 : OUString SwAuthorityFieldType::GetAuthFieldName(ToxAuthorityField eType)
     315             : {
     316           0 :     if(!pAuthFieldNameList)
     317             :     {
     318           0 :         pAuthFieldNameList = new std::vector<OUString>;
     319           0 :         pAuthFieldNameList->reserve(AUTH_FIELD_END);
     320           0 :         for(sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i)
     321           0 :             pAuthFieldNameList->push_back(SW_RES(STR_AUTH_FIELD_START + i));
     322             :     }
     323           0 :     return (*pAuthFieldNameList)[static_cast< sal_uInt16 >(eType)];
     324             : }
     325             : 
     326           0 : OUString SwAuthorityFieldType::GetAuthTypeName(ToxAuthorityType eType)
     327             : {
     328           0 :     if(!pAuthFieldTypeList)
     329             :     {
     330           0 :         pAuthFieldTypeList = new std::vector<OUString>;
     331           0 :         pAuthFieldTypeList->reserve(AUTH_TYPE_END);
     332           0 :         for(sal_uInt16 i = 0; i < AUTH_TYPE_END; ++i)
     333           0 :             pAuthFieldTypeList->push_back(SW_RES(STR_AUTH_TYPE_START + i));
     334             :     }
     335           0 :     return (*pAuthFieldTypeList)[static_cast< sal_uInt16 >(eType)];
     336             : }
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10