LCOV - code coverage report
Current view: top level - sc/source/core/data - global.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 361 555 65.0 %
Date: 2015-06-13 12:38:46 Functions: 48 59 81.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 <vcl/svapp.hxx>
      21             : #include "scitems.hxx"
      22             : #include <svx/algitem.hxx>
      23             : #include <editeng/brushitem.hxx>
      24             : #include <editeng/editobj.hxx>
      25             : #include <editeng/scripttypeitem.hxx>
      26             : #include <svl/srchitem.hxx>
      27             : #include <editeng/langitem.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <sfx2/objsh.hxx>
      31             : #include <sfx2/viewfrm.hxx>
      32             : #include <sfx2/viewsh.hxx>
      33             : #include <svl/stritem.hxx>
      34             : #include <svl/zforlist.hxx>
      35             : #include <svl/zformat.hxx>
      36             : #include <vcl/image.hxx>
      37             : #include <vcl/virdev.hxx>
      38             : #include <vcl/settings.hxx>
      39             : #include <sal/macros.h>
      40             : #include <tools/rcid.h>
      41             : #include <unotools/charclass.hxx>
      42             : #include <unotools/securityoptions.hxx>
      43             : #include <stdlib.h>
      44             : #include <time.h>
      45             : #include <ctype.h>
      46             : #include <numeric>
      47             : #include <svx/svdmodel.hxx>
      48             : 
      49             : #include <i18nlangtag/mslangid.hxx>
      50             : #include <com/sun/star/lang/Locale.hpp>
      51             : #include <comphelper/processfactory.hxx>
      52             : #include <comphelper/random.hxx>
      53             : #include <comphelper/string.hxx>
      54             : #include <unotools/calendarwrapper.hxx>
      55             : #include <unotools/collatorwrapper.hxx>
      56             : #include <com/sun/star/i18n/CollatorOptions.hpp>
      57             : #include <unotools/intlwrapper.hxx>
      58             : #include <unotools/syslocale.hxx>
      59             : #include <unotools/transliterationwrapper.hxx>
      60             : 
      61             : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
      62             : 
      63             : #include "global.hxx"
      64             : #include "scresid.hxx"
      65             : #include "autoform.hxx"
      66             : #include "document.hxx"
      67             : #include "patattr.hxx"
      68             : #include "addincol.hxx"
      69             : #include "adiasync.hxx"
      70             : #include "userlist.hxx"
      71             : #include "interpre.hxx"
      72             : #include "strload.hxx"
      73             : #include "docpool.hxx"
      74             : #include "unitconv.hxx"
      75             : #include "compiler.hxx"
      76             : #include "parclass.hxx"
      77             : #include "funcdesc.hxx"
      78             : #include "globstr.hrc"
      79             : #include "scfuncs.hrc"
      80             : #include "sc.hrc"
      81             : #include "scmod.hxx"
      82             : #include "appoptio.hxx"
      83             : #include "editutil.hxx"
      84             : 
      85             : tools::SvRef<ScDocShell>*  ScGlobal::pDrawClipDocShellRef = NULL;
      86             : SvxSearchItem*  ScGlobal::pSearchItem = NULL;
      87             : ScAutoFormat*   ScGlobal::pAutoFormat = NULL;
      88             : FuncCollection* ScGlobal::pFuncCollection = NULL;
      89             : ScUnoAddInCollection* ScGlobal::pAddInCollection = NULL;
      90             : ScUserList*     ScGlobal::pUserList = NULL;
      91             : OUString**      ScGlobal::ppRscString = NULL;
      92             : LanguageType    ScGlobal::eLnge = LANGUAGE_SYSTEM;
      93             : ::com::sun::star::lang::Locale*     ScGlobal::pLocale = NULL;
      94             : SvtSysLocale*   ScGlobal::pSysLocale = NULL;
      95             : const CharClass*  ScGlobal::pCharClass = NULL;
      96             : const LocaleDataWrapper*  ScGlobal::pLocaleData = NULL;
      97             : CalendarWrapper* ScGlobal::pCalendar = NULL;
      98             : CollatorWrapper* ScGlobal::pCollator = NULL;
      99             : CollatorWrapper* ScGlobal::pCaseCollator = NULL;
     100             : ::utl::TransliterationWrapper* ScGlobal::pTransliteration = NULL;
     101             : ::utl::TransliterationWrapper* ScGlobal::pCaseTransliteration = NULL;
     102          52 : ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XOrdinalSuffix> ScGlobal::xOrdinalSuffix = NULL;
     103             : IntlWrapper*    ScGlobal::pScIntlWrapper = NULL;
     104             : sal_Unicode     ScGlobal::cListDelimiter = ',';
     105             : OUString*       ScGlobal::pEmptyOUString = NULL;
     106             : OUString*       ScGlobal::pStrClipDocName = NULL;
     107             : 
     108             : SvxBrushItem*   ScGlobal::pEmptyBrushItem = NULL;
     109             : SvxBrushItem*   ScGlobal::pButtonBrushItem = NULL;
     110             : SvxBrushItem*   ScGlobal::pEmbeddedBrushItem = NULL;
     111             : SvxBrushItem*   ScGlobal::pProtectedBrushItem = NULL;
     112             : 
     113             : ImageList*      ScGlobal::pOutlineBitmaps = NULL;
     114             : 
     115             : ScFunctionList* ScGlobal::pStarCalcFunctionList = NULL;
     116             : ScFunctionMgr*  ScGlobal::pStarCalcFunctionMgr  = NULL;
     117             : 
     118             : ScUnitConverter* ScGlobal::pUnitConverter = NULL;
     119             : SvNumberFormatter* ScGlobal::pEnglishFormatter = NULL;
     120             : ScFieldEditEngine* ScGlobal::pFieldEditEngine = NULL;
     121             : 
     122             : double          ScGlobal::nScreenPPTX           = 96.0;
     123             : double          ScGlobal::nScreenPPTY           = 96.0;
     124             : 
     125             : sal_uInt16          ScGlobal::nDefFontHeight        = 225;
     126             : sal_uInt16          ScGlobal::nStdRowHeight         = 256;
     127             : 
     128             : long            ScGlobal::nLastRowHeightExtra   = 0;
     129             : long            ScGlobal::nLastColWidthExtra    = STD_EXTRA_WIDTH;
     130             : 
     131             : static sal_uInt16 nPPTZoom = 0; // ScreenZoom used to determine nScreenPPTX/Y
     132             : 
     133             : SfxViewShell* pScActiveViewShell = NULL; //FIXME: Make this a member
     134             : sal_uInt16 nScClickMouseModifier = 0;    //FIXME: This too
     135             : sal_uInt16 nScFillModeMouseModifier = 0; //FIXME: And this
     136             : 
     137             : // Static functions
     138             : 
     139     6694959 : bool ScGlobal::HasAttrChanged( const SfxItemSet&  rNewAttrs,
     140             :                                const SfxItemSet&  rOldAttrs,
     141             :                                const sal_uInt16       nWhich )
     142             : {
     143     6694959 :     bool                bInvalidate = false;
     144     6694959 :     const SfxItemState  eNewState   = rNewAttrs.GetItemState( nWhich );
     145     6694959 :     const SfxItemState  eOldState   = rOldAttrs.GetItemState( nWhich );
     146             : 
     147     6694959 :     if ( eNewState == eOldState )
     148             :     {
     149             :         // Both Items set
     150             :         // PoolItems, meaning comparing pointers is valid
     151     6669965 :         if ( SfxItemState::SET == eOldState )
     152      853693 :             bInvalidate = (&rNewAttrs.Get( nWhich ) != &rOldAttrs.Get( nWhich ));
     153             :     }
     154             :     else
     155             :     {
     156             :         // Contains a Default Item
     157             :         // PoolItems, meaning Item comparison necessary
     158             :         const SfxPoolItem& rOldItem = ( SfxItemState::SET == eOldState )
     159        1513 :                     ? rOldAttrs.Get( nWhich )
     160       26507 :                     : rOldAttrs.GetPool()->GetDefaultItem( nWhich );
     161             : 
     162             :         const SfxPoolItem& rNewItem = ( SfxItemState::SET == eNewState )
     163       23481 :                     ? rNewAttrs.Get( nWhich )
     164       48475 :                     : rNewAttrs.GetPool()->GetDefaultItem( nWhich );
     165             : 
     166       24994 :         bInvalidate = rNewItem != rOldItem;
     167             :     }
     168             : 
     169     6694959 :     return bInvalidate;
     170             : }
     171             : 
     172        1739 : sal_uLong ScGlobal::GetStandardFormat( SvNumberFormatter& rFormatter,
     173             :         sal_uLong nFormat, short nType )
     174             : {
     175        1739 :     const SvNumberformat* pFormat = rFormatter.GetEntry( nFormat );
     176        1739 :     if ( pFormat )
     177        1739 :         return rFormatter.GetStandardFormat( nFormat, nType, pFormat->GetLanguage() );
     178           0 :     return rFormatter.GetStandardFormat( nType, eLnge );
     179             : }
     180             : 
     181           2 : sal_uInt16 ScGlobal::GetStandardRowHeight()
     182             : {
     183           2 :     return nStdRowHeight;
     184             : }
     185             : 
     186          44 : SvNumberFormatter* ScGlobal::GetEnglishFormatter()
     187             : {
     188          44 :     if ( !pEnglishFormatter )
     189             :     {
     190             :         pEnglishFormatter = new SvNumberFormatter(
     191           3 :             ::comphelper::getProcessComponentContext(), LANGUAGE_ENGLISH_US );
     192           3 :         pEnglishFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT );
     193             :     }
     194          44 :     return pEnglishFormatter;
     195             : }
     196             : 
     197      287209 : bool ScGlobal::CheckWidthInvalidate( bool& bNumFormatChanged,
     198             :                                      const SfxItemSet& rNewAttrs,
     199             :                                      const SfxItemSet& rOldAttrs )
     200             : {
     201             :     // Check whether attribute changes in rNewAttrs compared to rOldAttrs render
     202             :     // the text width at a cell invalid
     203             :     bNumFormatChanged =
     204      287209 :             HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_VALUE_FORMAT );
     205             :     return ( bNumFormatChanged
     206      285320 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LANGUAGE_FORMAT )
     207      285320 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT )
     208      284624 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT )
     209      282105 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT )
     210      281926 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_HEIGHT )
     211      279649 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_HEIGHT )
     212      279594 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_HEIGHT )
     213      279551 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_WEIGHT )
     214      277363 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_WEIGHT )
     215      277338 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_WEIGHT )
     216      277313 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_POSTURE )
     217      277239 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CJK_FONT_POSTURE )
     218      277214 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_CTL_FONT_POSTURE )
     219      277189 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_UNDERLINE )
     220      277115 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_OVERLINE )
     221      277085 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CROSSEDOUT )
     222      277032 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_CONTOUR )
     223      277008 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_FONT_SHADOWED )
     224      276984 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_STACKED )
     225      275238 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_VALUE )
     226      275219 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_ROTATE_MODE )
     227      275219 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_LINEBREAK )
     228      562314 :         || HasAttrChanged( rNewAttrs, rOldAttrs, ATTR_MARGIN )
     229      287209 :         );
     230             : }
     231             : 
     232          22 : const SvxSearchItem& ScGlobal::GetSearchItem()
     233             : {
     234          22 :     if (!pSearchItem)
     235             :     {
     236           1 :         pSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
     237           1 :         pSearchItem->SetAppFlag( SvxSearchApp::CALC );
     238             :     }
     239          22 :     return *pSearchItem;
     240             : }
     241             : 
     242          22 : void ScGlobal::SetSearchItem( const SvxSearchItem& rNew )
     243             : {
     244             :     // FIXME: An assignement operator would be nice here
     245          22 :     delete pSearchItem;
     246          22 :     pSearchItem = static_cast<SvxSearchItem*>(rNew.Clone());
     247             : 
     248          22 :     pSearchItem->SetWhich( SID_SEARCH_ITEM );
     249          22 :     pSearchItem->SetAppFlag( SvxSearchApp::CALC );
     250          22 : }
     251             : 
     252           0 : void ScGlobal::ClearAutoFormat()
     253             : {
     254           0 :     if (pAutoFormat!=NULL)
     255             :     {
     256           0 :         delete pAutoFormat;
     257           0 :         pAutoFormat=NULL;
     258             :     }
     259           0 : }
     260             : 
     261          25 : ScAutoFormat* ScGlobal::GetAutoFormat()
     262             : {
     263          25 :     return pAutoFormat;
     264             : }
     265             : 
     266         432 : ScAutoFormat* ScGlobal::GetOrCreateAutoFormat()
     267             : {
     268         432 :     if ( !pAutoFormat )
     269             :     {
     270           2 :         pAutoFormat = new ScAutoFormat;
     271           2 :         pAutoFormat->Load();
     272             :     }
     273             : 
     274         432 :     return pAutoFormat;
     275             : }
     276             : 
     277        3221 : FuncCollection* ScGlobal::GetFuncCollection()
     278             : {
     279        3221 :     if (!pFuncCollection)
     280          13 :         pFuncCollection = new FuncCollection();
     281        3221 :     return pFuncCollection;
     282             : }
     283             : 
     284        3533 : ScUnoAddInCollection* ScGlobal::GetAddInCollection()
     285             : {
     286        3533 :     if (!pAddInCollection)
     287          38 :         pAddInCollection = new ScUnoAddInCollection();
     288        3533 :     return pAddInCollection;
     289             : }
     290             : 
     291          12 : ScUserList* ScGlobal::GetUserList()
     292             : {
     293             :     // Hack: Load Cfg item at the App
     294          12 :     global_InitAppOptions();
     295             : 
     296          12 :     if (!pUserList)
     297           0 :         pUserList = new ScUserList();
     298          12 :     return pUserList;
     299             : }
     300             : 
     301          52 : void ScGlobal::SetUserList( const ScUserList* pNewList )
     302             : {
     303          52 :     if ( pNewList )
     304             :     {
     305          52 :         if ( !pUserList )
     306          52 :             pUserList = new ScUserList( *pNewList );
     307             :         else
     308           0 :             *pUserList = *pNewList;
     309             :     }
     310             :     else
     311             :     {
     312           0 :         delete pUserList;
     313           0 :         pUserList = NULL;
     314             :     }
     315          52 : }
     316             : 
     317       42846 : const OUString& ScGlobal::GetRscString( sal_uInt16 nIndex )
     318             : {
     319             :     assert( nIndex < SC_GLOBSTR_STR_COUNT);
     320       42846 :     if( !ppRscString[ nIndex ] )
     321             :     {
     322         993 :         OpCode eOp = ocNone;
     323             :         // Map former globstr.src strings moved to compiler.src
     324         993 :         switch (nIndex)
     325             :         {
     326             :             case STR_NULL_ERROR:
     327           0 :                 eOp = ocErrNull;
     328           0 :                 break;
     329             :             case STR_DIV_ZERO:
     330           2 :                 eOp = ocErrDivZero;
     331           2 :                 break;
     332             :             case STR_NO_VALUE:
     333           1 :                 eOp = ocErrValue;
     334           1 :                 break;
     335             :             case STR_NOREF_STR:
     336           0 :                 eOp = ocErrRef;
     337           0 :                 break;
     338             :             case STR_NO_NAME_REF:
     339           0 :                 eOp = ocErrName;
     340           0 :                 break;
     341             :             case STR_NUM_ERROR:
     342           1 :                 eOp = ocErrNum;
     343           1 :                 break;
     344             :             case STR_NV_STR:
     345           2 :                 eOp = ocErrNA;
     346           2 :                 break;
     347             :             default:
     348             :                 ;   // nothing
     349             :         }
     350         993 :         if (eOp != ocNone)
     351           6 :             ppRscString[ nIndex ] = new OUString( ScCompiler::GetNativeSymbol( eOp));
     352             :         else
     353         987 :             ppRscString[ nIndex ] = new OUString( SC_STRLOAD( RID_GLOBSTR, nIndex ));
     354             :     }
     355       42846 :     return *ppRscString[ nIndex ];
     356             : }
     357             : 
     358         173 : OUString ScGlobal::GetErrorString(sal_uInt16 nErrNumber)
     359             : {
     360         173 :     OUString sResStr;
     361         173 :     switch (nErrNumber)
     362             :     {
     363          28 :         case NOTAVAILABLE          : nErrNumber = STR_NV_STR; break;
     364          35 :         case errNoRef              : nErrNumber = STR_NO_REF_TABLE; break;
     365           0 :         case errNoName             : nErrNumber = STR_NO_NAME_REF; break;
     366           0 :         case errNoAddin            : nErrNumber = STR_NO_ADDIN; break;
     367           0 :         case errNoMacro            : nErrNumber = STR_NO_MACRO; break;
     368             :         case errDoubleRef          :
     369          16 :         case errNoValue            : nErrNumber = STR_NO_VALUE; break;
     370           0 :         case errNoCode             : nErrNumber = STR_NULL_ERROR; break;
     371           9 :         case errDivisionByZero     : nErrNumber = STR_DIV_ZERO; break;
     372          61 :         case errIllegalFPOperation : nErrNumber = STR_NUM_ERROR; break;
     373             : 
     374          24 :         default          : sResStr = GetRscString(STR_ERROR_STR) + OUString::number( nErrNumber );
     375          24 :                            nErrNumber = 0;
     376          24 :                            break;
     377             :     }
     378         173 :     if( nErrNumber )
     379         149 :         sResStr = GetRscString( nErrNumber );
     380         173 :     return sResStr;
     381             : }
     382             : 
     383           0 : OUString ScGlobal::GetLongErrorString(sal_uInt16 nErrNumber)
     384             : {
     385           0 :     switch (nErrNumber)
     386             :     {
     387             :         case 0:
     388           0 :             break;
     389             :         case 1:
     390             :         case errIllegalArgument:
     391           0 :             nErrNumber = STR_LONG_ERR_ILL_ARG;
     392           0 :         break;
     393             :         case 2:
     394             :         case 3:
     395             :         case 4:
     396             :         case 5:
     397             :         case errIllegalFPOperation:
     398           0 :             nErrNumber = STR_LONG_ERR_ILL_FPO;
     399           0 :         break;
     400             :         case errIllegalChar:
     401           0 :             nErrNumber = STR_LONG_ERR_ILL_CHAR;
     402           0 :         break;
     403             :         case errIllegalParameter:
     404           0 :             nErrNumber = STR_LONG_ERR_ILL_PAR;
     405           0 :         break;
     406             :         case errSeparator:
     407           0 :             nErrNumber = STR_LONG_ERR_ILL_SEP;
     408           0 :         break;
     409             :         case errPair:
     410             :         case errPairExpected:
     411           0 :             nErrNumber = STR_LONG_ERR_PAIR;
     412           0 :         break;
     413             :         case errOperatorExpected:
     414           0 :             nErrNumber = STR_LONG_ERR_OP_EXP;
     415           0 :         break;
     416             :         case errVariableExpected:
     417             :         case errParameterExpected:
     418           0 :             nErrNumber = STR_LONG_ERR_VAR_EXP;
     419           0 :         break;
     420             :         case errCodeOverflow:
     421           0 :             nErrNumber = STR_LONG_ERR_CODE_OVF;
     422           0 :         break;
     423             :         case errStringOverflow:
     424           0 :             nErrNumber = STR_LONG_ERR_STR_OVF;
     425           0 :         break;
     426             :         case errStackOverflow:
     427             :         case errInterpOverflow:
     428           0 :             nErrNumber = STR_LONG_ERR_STACK_OVF;
     429           0 :         break;
     430             :         case errIllegalJump:
     431             :         case errUnknownState:
     432             :         case errUnknownVariable:
     433             :         case errUnknownOpCode:
     434             :         case errUnknownStackVariable:
     435             :         case errUnknownToken:
     436             :         case errNoCode:
     437             :         case errDoubleRef:
     438           0 :             nErrNumber = STR_LONG_ERR_SYNTAX;
     439           0 :         break;
     440             :         case errCircularReference:
     441           0 :             nErrNumber = STR_LONG_ERR_CIRC_REF;
     442           0 :         break;
     443             :         case errNoConvergence:
     444           0 :             nErrNumber = STR_LONG_ERR_NO_CONV;
     445           0 :         break;
     446             :         case errNoRef:
     447           0 :             nErrNumber = STR_LONG_ERR_NO_REF;
     448           0 :         break;
     449             :         case errNoName:
     450           0 :             nErrNumber = STR_LONG_ERR_NO_NAME;
     451           0 :         break;
     452             :         case errNoAddin:
     453           0 :             nErrNumber = STR_LONG_ERR_NO_ADDIN;
     454           0 :         break;
     455             :         case errNoMacro:
     456           0 :             nErrNumber = STR_LONG_ERR_NO_MACRO;
     457           0 :         break;
     458             :         case errDivisionByZero:
     459           0 :             nErrNumber = STR_LONG_ERR_DIV_ZERO;
     460           0 :         break;
     461             :         case errNestedArray:
     462           0 :             nErrNumber = STR_ERR_LONG_NESTED_ARRAY;
     463           0 :         break;
     464             :         case errNoValue:
     465           0 :             nErrNumber = STR_LONG_ERR_NO_VALUE;
     466           0 :         break;
     467             :         case NOTAVAILABLE:
     468           0 :             nErrNumber = STR_LONG_ERR_NV;
     469           0 :         break;
     470             :         default:
     471           0 :             nErrNumber = STR_ERROR_STR;
     472           0 :         break;
     473             :     }
     474           0 :     OUString aRes( GetRscString( nErrNumber ) );
     475           0 :     return aRes;
     476             : }
     477             : 
     478           0 : SvxBrushItem* ScGlobal::GetButtonBrushItem()
     479             : {
     480           0 :     pButtonBrushItem->SetColor( Application::GetSettings().GetStyleSettings().GetFaceColor() );
     481           0 :     return pButtonBrushItem;
     482             : }
     483             : 
     484       77131 : const OUString& ScGlobal::GetEmptyOUString()
     485             : {
     486       77131 :     return *pEmptyOUString;
     487             : }
     488             : 
     489           7 : ImageList* ScGlobal::GetOutlineSymbols()
     490             : {
     491           7 :     ImageList*& rpImageList = pOutlineBitmaps;
     492           7 :     if( !rpImageList )
     493           3 :         rpImageList = new ImageList( ScResId( RID_OUTLINEBITMAPS ) );
     494           7 :     return rpImageList;
     495             : }
     496             : 
     497          52 : void ScGlobal::Init()
     498             : {
     499          52 :     pEmptyOUString = new OUString;
     500             : 
     501             :     // The default language for number formats (ScGlobal::eLnge) must
     502             :     // always be LANGUAGE_SYSTEM
     503             :     // FIXME: So remove this variable?
     504          52 :     eLnge = LANGUAGE_SYSTEM;
     505             : 
     506             :     // FIXME: If the sort-order etc. should depend the installed Office version
     507             :     //        use Application::GetSettings().GetUILanguage() here
     508          52 :     pSysLocale = new SvtSysLocale;
     509          52 :     pCharClass = pSysLocale->GetCharClassPtr();
     510          52 :     pLocaleData = pSysLocale->GetLocaleDataPtr();
     511             : 
     512          52 :     ppRscString = new OUString *[ SC_GLOBSTR_STR_COUNT ];
     513          52 :     for( sal_uInt16 nC = 0 ; nC < SC_GLOBSTR_STR_COUNT ; nC++ ) ppRscString[ nC ] = NULL;
     514             : 
     515          52 :     pEmptyBrushItem = new SvxBrushItem( Color( COL_TRANSPARENT ), ATTR_BACKGROUND );
     516          52 :     pButtonBrushItem = new SvxBrushItem( Color(), ATTR_BACKGROUND );
     517          52 :     pEmbeddedBrushItem = new SvxBrushItem( Color( COL_LIGHTCYAN ), ATTR_BACKGROUND );
     518          52 :     pProtectedBrushItem = new SvxBrushItem( Color( COL_LIGHTGRAY ), ATTR_BACKGROUND );
     519             : 
     520          52 :     UpdatePPT(NULL);
     521             :     //ScCompiler::InitSymbolsNative();
     522             :     // ScParameterClassification _after_ Compiler, needs function resources if
     523             :     // arguments are to be merged in, which in turn need strings of function
     524             :     // names from the compiler.
     525          52 :     ScParameterClassification::Init();
     526             : 
     527          52 :     InitAddIns();
     528             : 
     529          52 :     pStrClipDocName = new OUString( ScResId( SCSTR_NONAME ) );
     530          52 :     *pStrClipDocName += "1";
     531             : 
     532             :     //  ScDocumentPool::InitVersionMaps() has been called earlier already
     533          52 : }
     534             : 
     535          78 : void ScGlobal::UpdatePPT( OutputDevice* pDev )
     536             : {
     537          78 :     sal_uInt16 nCurrentZoom = Application::GetSettings().GetStyleSettings().GetScreenZoom();
     538          78 :     if ( nCurrentZoom != nPPTZoom )
     539             :     {
     540             :         // Screen PPT values must be updated when ScreenZoom has changed.
     541             :         // If called from Window::DataChanged, the window is passed as pDev,
     542             :         // to make sure LogicToPixel uses a device which already uses the new zoom.
     543             :         // For the initial settings, NULL is passed and GetDefaultDevice used.
     544             : 
     545          52 :         if ( !pDev )
     546          52 :             pDev = Application::GetDefaultDevice();
     547          52 :         Point aPix1000 = pDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
     548          52 :         nScreenPPTX = aPix1000.X() / 1000.0;
     549          52 :         nScreenPPTY = aPix1000.Y() / 1000.0;
     550          52 :         nPPTZoom = nCurrentZoom;
     551             :     }
     552          78 : }
     553             : 
     554           0 : const OUString& ScGlobal::GetClipDocName()
     555             : {
     556           0 :     return *pStrClipDocName;
     557             : }
     558             : 
     559          11 : void ScGlobal::SetClipDocName( const OUString& rNew )
     560             : {
     561          11 :     *pStrClipDocName = rNew;
     562          11 : }
     563             : 
     564          52 : void ScGlobal::InitTextHeight(SfxItemPool* pPool)
     565             : {
     566          52 :     if (!pPool)
     567             :     {
     568             :         OSL_FAIL("ScGlobal::InitTextHeight: No Pool");
     569           0 :         return;
     570             :     }
     571             : 
     572          52 :     const ScPatternAttr* pPattern = static_cast<const ScPatternAttr*>(&pPool->GetDefaultItem(ATTR_PATTERN));
     573          52 :     if (!pPattern)
     574             :     {
     575             :         OSL_FAIL("ScGlobal::InitTextHeight: No default pattern");
     576           0 :         return;
     577             :     }
     578             : 
     579          52 :     OutputDevice* pDefaultDev = Application::GetDefaultDevice();
     580          52 :     ScopedVclPtrInstance< VirtualDevice > pVirtWindow( *pDefaultDev );
     581          52 :     pVirtWindow->SetMapMode(MAP_PIXEL);
     582         104 :     vcl::Font aDefFont;
     583          52 :     pPattern->GetFont(aDefFont, SC_AUTOCOL_BLACK, pVirtWindow); // Font color doesn't matter here
     584          52 :     pVirtWindow->SetFont(aDefFont);
     585             :     sal_uInt16 nTest = static_cast<sal_uInt16>(
     586          52 :         pVirtWindow->PixelToLogic(Size(0, pVirtWindow->GetTextHeight()), MAP_TWIP).Height());
     587             : 
     588          52 :     if (nTest > nDefFontHeight)
     589           0 :         nDefFontHeight = nTest;
     590             : 
     591          52 :     const SvxMarginItem* pMargin = static_cast<const SvxMarginItem*>(&pPattern->GetItem(ATTR_MARGIN));
     592             : 
     593             :     nTest = static_cast<sal_uInt16>(
     594          52 :         nDefFontHeight + pMargin->GetTopMargin() + pMargin->GetBottomMargin() - STD_ROWHEIGHT_DIFF);
     595             : 
     596          52 :     if (nTest > nStdRowHeight)
     597          52 :         nStdRowHeight = nTest;
     598             : }
     599             : 
     600          16 : void ScGlobal::Clear()
     601             : {
     602             :     // Destroy asyncs _before_ ExitExternalFunc!
     603          16 :     for( ScAddInAsyncs::iterator it = theAddInAsyncTbl.begin(); it != theAddInAsyncTbl.end(); ++it )
     604             :     {
     605           0 :         delete *it;
     606             :     }
     607          16 :     theAddInAsyncTbl.clear();
     608          16 :     ExitExternalFunc();
     609          16 :     DELETEZ(pAutoFormat);
     610          16 :     DELETEZ(pSearchItem);
     611          16 :     DELETEZ(pFuncCollection);
     612          16 :     DELETEZ(pAddInCollection);
     613          16 :     DELETEZ(pUserList);
     614             : 
     615        8592 :     for( sal_uInt16 nC = 0 ; nC < SC_GLOBSTR_STR_COUNT ; nC++ )
     616        8576 :         if( ppRscString ) delete ppRscString[ nC ];
     617          16 :     delete[] ppRscString;
     618          16 :     ppRscString = NULL;
     619             : 
     620          16 :     DELETEZ(pStarCalcFunctionList); // Destroy before ResMgr!
     621          16 :     DELETEZ(pStarCalcFunctionMgr);
     622          16 :     ScParameterClassification::Exit();
     623          16 :     ScCompiler::DeInit();
     624          16 :     ScInterpreter::GlobalExit(); // Delete static Stack
     625             : 
     626          16 :     DELETEZ(pEmptyBrushItem);
     627          16 :     DELETEZ(pButtonBrushItem);
     628          16 :     DELETEZ(pEmbeddedBrushItem);
     629          16 :     DELETEZ(pProtectedBrushItem);
     630          16 :     DELETEZ(pOutlineBitmaps);
     631          16 :     DELETEZ(pEnglishFormatter);
     632          16 :     DELETEZ(pCaseTransliteration);
     633          16 :     DELETEZ(pTransliteration);
     634          16 :     DELETEZ(pCaseCollator);
     635          16 :     DELETEZ(pCollator);
     636          16 :     DELETEZ(pCalendar);
     637             :     // Do NOT delete pCharClass since it is a pointer to the single SvtSysLocale instance !
     638          16 :     pCharClass = NULL;
     639             :     // Do NOT delete pLocaleData since it is a pointer to the single SvtSysLocale instance !
     640          16 :     pLocaleData = NULL;
     641          16 :     DELETEZ(pSysLocale);
     642          16 :     DELETEZ(pLocale);
     643          16 :     DELETEZ(pScIntlWrapper);
     644          16 :     DELETEZ(pStrClipDocName);
     645             : 
     646          16 :     DELETEZ(pUnitConverter);
     647          16 :     DELETEZ(pFieldEditEngine);
     648             : 
     649          16 :     ScDocumentPool::DeleteVersionMaps();
     650             : 
     651          16 :     DELETEZ(pEmptyOUString);
     652          16 : }
     653             : 
     654           6 : rtl_TextEncoding ScGlobal::GetCharsetValue( const OUString& rCharSet )
     655             : {
     656             :     // new TextEncoding values
     657           6 :     if ( CharClass::isAsciiNumeric( rCharSet ) )
     658             :     {
     659           0 :         sal_Int32 nVal = rCharSet.toInt32();
     660           0 :         if ( !nVal || nVal == RTL_TEXTENCODING_DONTKNOW )
     661           0 :             return osl_getThreadTextEncoding();
     662           0 :         return (rtl_TextEncoding) nVal;
     663             :     }
     664             :     // old CharSet values for compatibility
     665           6 :     else if (rCharSet.equalsIgnoreAsciiCase("ANSI")     ) return RTL_TEXTENCODING_MS_1252;
     666           5 :     else if (rCharSet.equalsIgnoreAsciiCase("MAC")      ) return RTL_TEXTENCODING_APPLE_ROMAN;
     667           5 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC")    ) return RTL_TEXTENCODING_IBM_850;
     668           5 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_437")) return RTL_TEXTENCODING_IBM_437;
     669           1 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_850")) return RTL_TEXTENCODING_IBM_850;
     670           0 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_860")) return RTL_TEXTENCODING_IBM_860;
     671           0 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_861")) return RTL_TEXTENCODING_IBM_861;
     672           0 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_863")) return RTL_TEXTENCODING_IBM_863;
     673           0 :     else if (rCharSet.equalsIgnoreAsciiCase("IBMPC_865")) return RTL_TEXTENCODING_IBM_865;
     674           0 :     else return osl_getThreadTextEncoding();
     675             : }
     676             : 
     677           6 : OUString ScGlobal::GetCharsetString( rtl_TextEncoding eVal )
     678             : {
     679             :     const sal_Char* pChar;
     680           6 :     switch ( eVal )
     681             :     {
     682             :         // old CharSet strings for compatibility
     683           1 :         case RTL_TEXTENCODING_MS_1252:      pChar = "ANSI";         break;
     684           0 :         case RTL_TEXTENCODING_APPLE_ROMAN:  pChar = "MAC";          break;
     685             :         // IBMPC == IBMPC_850
     686           4 :         case RTL_TEXTENCODING_IBM_437:      pChar = "IBMPC_437";    break;
     687           1 :         case RTL_TEXTENCODING_IBM_850:      pChar = "IBMPC_850";    break;
     688           0 :         case RTL_TEXTENCODING_IBM_860:      pChar = "IBMPC_860";    break;
     689           0 :         case RTL_TEXTENCODING_IBM_861:      pChar = "IBMPC_861";    break;
     690           0 :         case RTL_TEXTENCODING_IBM_863:      pChar = "IBMPC_863";    break;
     691           0 :         case RTL_TEXTENCODING_IBM_865:      pChar = "IBMPC_865";    break;
     692           0 :         case RTL_TEXTENCODING_DONTKNOW:     pChar = "SYSTEM";       break;
     693             :         // new string of TextEncoding value
     694             :         default:
     695           0 :             return OUString::number( eVal );
     696             :     }
     697           6 :     return OUString::createFromAscii(pChar);
     698             : }
     699             : 
     700           0 : bool ScGlobal::HasStarCalcFunctionList()
     701             : {
     702           0 :     return ( pStarCalcFunctionList != NULL );
     703             : }
     704             : 
     705         980 : ScFunctionList* ScGlobal::GetStarCalcFunctionList()
     706             : {
     707         980 :     if ( !pStarCalcFunctionList )
     708           3 :         pStarCalcFunctionList = new ScFunctionList;
     709             : 
     710         980 :     return pStarCalcFunctionList;
     711             : }
     712             : 
     713           1 : ScFunctionMgr* ScGlobal::GetStarCalcFunctionMgr()
     714             : {
     715           1 :     if ( !pStarCalcFunctionMgr )
     716           1 :         pStarCalcFunctionMgr = new ScFunctionMgr;
     717             : 
     718           1 :     return pStarCalcFunctionMgr;
     719             : }
     720             : 
     721          49 : void ScGlobal::ResetFunctionList()
     722             : {
     723             :     // FunctionMgr has pointers into FunctionList, must also be updated
     724          49 :     DELETEZ( pStarCalcFunctionMgr );
     725          49 :     DELETEZ( pStarCalcFunctionList );
     726          49 : }
     727             : 
     728           9 : ScUnitConverter* ScGlobal::GetUnitConverter()
     729             : {
     730           9 :     if ( !pUnitConverter )
     731           1 :         pUnitConverter = new ScUnitConverter;
     732             : 
     733           9 :     return pUnitConverter;
     734             : }
     735             : 
     736        2651 : const sal_Unicode* ScGlobal::UnicodeStrChr( const sal_Unicode* pStr,
     737             :             sal_Unicode c )
     738             : {
     739        2651 :     if ( !pStr )
     740           0 :         return NULL;
     741        8740 :     while ( *pStr )
     742             :     {
     743        4120 :         if ( *pStr == c )
     744         682 :             return pStr;
     745        3438 :         pStr++;
     746             :     }
     747        1969 :     return NULL;
     748             : }
     749             : 
     750         154 : OUString ScGlobal::addToken(const OUString& rTokenList, const OUString& rToken,
     751             :     sal_Unicode cSep, sal_Int32 nSepCount, bool bForceSep)
     752             : {
     753         154 :     OUStringBuffer aBuf(rTokenList);
     754         154 :     if( bForceSep || (!rToken.isEmpty() && !rTokenList.isEmpty()) )
     755           0 :         comphelper::string::padToLength(aBuf, aBuf.getLength() + nSepCount, cSep);
     756         154 :     aBuf.append(rToken);
     757         154 :     return aBuf.makeStringAndClear();
     758             : }
     759             : 
     760           0 : bool ScGlobal::IsQuoted( const OUString& rString, sal_Unicode cQuote )
     761             : {
     762           0 :     return (rString.getLength() >= 2) && (rString[0] == cQuote) && (rString[ rString.getLength() - 1 ] == cQuote);
     763             : }
     764             : 
     765           0 : void ScGlobal::AddQuotes( OUString& rString, sal_Unicode cQuote, bool bEscapeEmbedded )
     766             : {
     767           0 :     if (bEscapeEmbedded)
     768             :     {
     769             :         sal_Unicode pQ[3];
     770           0 :         pQ[0] = pQ[1] = cQuote;
     771           0 :         pQ[2] = 0;
     772           0 :         OUString aQuotes( pQ );
     773           0 :         rString = rString.replaceAll( OUString(cQuote), aQuotes);
     774             :     }
     775           0 :     rString = OUString( cQuote ) + rString + OUString( cQuote );
     776           0 : }
     777             : 
     778           0 : void ScGlobal::EraseQuotes( OUString& rString, sal_Unicode cQuote, bool bUnescapeEmbedded )
     779             : {
     780           0 :     if ( IsQuoted( rString, cQuote ) )
     781             :     {
     782           0 :         rString = rString.copy( 1, rString.getLength() - 2 );
     783           0 :         if (bUnescapeEmbedded)
     784             :         {
     785             :             sal_Unicode pQ[3];
     786           0 :             pQ[0] = pQ[1] = cQuote;
     787           0 :             pQ[2] = 0;
     788           0 :             OUString aQuotes( pQ );
     789           0 :             rString = rString.replaceAll( aQuotes, OUString(cQuote));
     790             :         }
     791             :     }
     792           0 : }
     793             : 
     794        8973 : sal_Int32 ScGlobal::FindUnquoted( const OUString& rString, sal_Unicode cChar)
     795             : {
     796        8973 :     const sal_Unicode cQuote = '\'';
     797        8973 :     const sal_Unicode* const pStart = rString.getStr();
     798        8973 :     const sal_Unicode* const pStop = pStart + rString.getLength();
     799        8973 :     const sal_Unicode* p = pStart;
     800        8973 :     bool bQuoted = false;
     801       57228 :     while (p < pStop)
     802             :     {
     803       42382 :         if (*p == cChar && !bQuoted)
     804        3100 :             return sal::static_int_cast< sal_Int32 >( p - pStart );
     805       39282 :         else if (*p == cQuote)
     806             :         {
     807         238 :             if (!bQuoted)
     808         119 :                 bQuoted = true;
     809         119 :             else if (p < pStop-1 && *(p+1) == cQuote)
     810           0 :                 ++p;
     811             :             else
     812         119 :                 bQuoted = false;
     813             :         }
     814       39282 :         ++p;
     815             :     }
     816        5873 :     return -1;
     817             : }
     818             : 
     819       10625 : const sal_Unicode* ScGlobal::FindUnquoted( const sal_Unicode* pString, sal_Unicode cChar, sal_Unicode cQuote )
     820             : {
     821       10625 :     const sal_Unicode* p = pString;
     822       10625 :     bool bQuoted = false;
     823       82931 :     while (*p)
     824             :     {
     825       67838 :         if (*p == cChar && !bQuoted)
     826        6157 :             return p;
     827       61681 :         else if (*p == cQuote)
     828             :         {
     829         722 :             if (!bQuoted)
     830         357 :                 bQuoted = true;
     831         365 :             else if (*(p+1) == cQuote)
     832           8 :                 ++p;
     833             :             else
     834         357 :                 bQuoted = false;
     835             :         }
     836       61681 :         ++p;
     837             :     }
     838        4468 :     return NULL;
     839             : }
     840             : 
     841       14924 : bool ScGlobal::EETextObjEqual( const EditTextObject* pObj1,
     842             :                                const EditTextObject* pObj2 )
     843             : {
     844       14924 :     if ( pObj1 == pObj2 ) // Both empty or the same object
     845        2135 :         return true;
     846             : 
     847       12789 :     if ( pObj1 && pObj2 )
     848             :     {
     849             :         // First test for equal text content
     850        5682 :         sal_Int32 nParCount = pObj1->GetParagraphCount();
     851        5682 :         if ( nParCount != pObj2->GetParagraphCount() )
     852        5563 :             return false;
     853        8861 :         for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
     854        5666 :             if ( pObj1->GetText(nPar) != pObj2->GetText(nPar) )
     855        2465 :                 return false;
     856             : 
     857        3195 :         SvMemoryStream  aStream1;
     858        3336 :         SvMemoryStream  aStream2;
     859        3195 :         pObj1->Store( aStream1 );
     860        3195 :         pObj2->Store( aStream2 );
     861        3195 :         sal_uLong nSize = aStream1.Tell();
     862        3195 :         if ( aStream2.Tell() == nSize )
     863        3066 :             if ( !memcmp( aStream1.GetData(), aStream2.GetData(), (sal_uInt16) nSize ) )
     864        3195 :                 return true;
     865             :     }
     866             : 
     867        7248 :     return false;
     868             : }
     869             : 
     870           0 : void ScGlobal::OpenURL(const OUString& rURL, const OUString& rTarget, const SdrModel* pDrawLayer)
     871             : {
     872           0 :     if (pDrawLayer && pDrawLayer->isTiledRendering())
     873             :     {
     874           0 :         pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_HYPERLINK_CLICKED, rURL.toUtf8().getStr());
     875           0 :         return;
     876             :     }
     877             : 
     878             :     // OpenURL is always called in the GridWindow by mouse clicks in some way or another.
     879             :     // That's why pScActiveViewShell and nScClickMouseModifier are correct.
     880             :     // SvtSecurityOptions to access Libreoffice global security parameters
     881           0 :     SvtSecurityOptions aSecOpt;
     882           0 :     bool bCtrlClickHappened = (nScClickMouseModifier & KEY_MOD1);
     883           0 :     bool bCtrlClickSecOption = aSecOpt.IsOptionSet( SvtSecurityOptions::E_CTRLCLICK_HYPERLINK );
     884           0 :     if( bCtrlClickHappened && !( bCtrlClickSecOption ) )
     885             :     {
     886             :         // return since ctrl+click happened when the
     887             :         // ctrl+click security option was disabled, link should not open
     888           0 :         return;
     889             :     }
     890           0 :     else if( !( bCtrlClickHappened ) && bCtrlClickSecOption )
     891             :     {
     892             :         // ctrl+click did not happen; only click happened maybe with some
     893             :         // other key combo. and security option is set, so return
     894           0 :         return;
     895             :     }
     896           0 :     SfxStringItem aUrl( SID_FILE_NAME, rURL );
     897           0 :     SfxStringItem aTarget( SID_TARGETNAME, rTarget );
     898           0 :     aTarget.SetValue(OUString("_blank"));
     899           0 :     SfxViewFrame* pFrame = NULL;
     900           0 :     OUString aReferName;
     901           0 :     if ( pScActiveViewShell )
     902             :     {
     903           0 :         pFrame = pScActiveViewShell->GetViewFrame();
     904           0 :         SfxMedium* pMed = pFrame->GetObjectShell()->GetMedium();
     905           0 :         if (pMed)
     906           0 :             aReferName = pMed->GetName();
     907             :     }
     908             : 
     909           0 :     SfxFrameItem aFrm( SID_DOCFRAME, pFrame );
     910           0 :     SfxStringItem aReferer( SID_REFERER, aReferName );
     911             : 
     912           0 :     SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, false );
     913           0 :     SfxBoolItem aBrowsing( SID_BROWSE, true );
     914             : 
     915             :     // No SID_SILENT anymore
     916           0 :     SfxViewFrame* pViewFrm = SfxViewFrame::Current();
     917           0 :     if (pViewFrm)
     918             :         pViewFrm->GetDispatcher()->Execute( SID_OPENDOC,
     919             :                                     SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
     920             :                                     &aUrl, &aTarget,
     921             :                                     &aFrm, &aReferer,
     922             :                                     &aNewView, &aBrowsing,
     923           0 :                                     0L );
     924             : }
     925             : 
     926        2455 : bool ScGlobal::IsSystemRTL()
     927             : {
     928        2455 :     return MsLangId::isRightToLeft( Application::GetSettings().GetLanguageTag().getLanguageType() );
     929             : }
     930             : 
     931      753254 : SvtScriptType ScGlobal::GetDefaultScriptType()
     932             : {
     933             :     // Used when text contains only WEAK characters.
     934             :     // Script type of office language is used then (same as GetEditDefaultLanguage,
     935             :     // to get consistent behavior of text in simple cells and EditEngine,
     936             :     // also same as GetAppLanguage() in Writer)
     937      753254 :     return SvtLanguageOptions::GetScriptTypeOfLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() );
     938             : }
     939             : 
     940       10928 : LanguageType ScGlobal::GetEditDefaultLanguage()
     941             : {
     942             :     // Used for EditEngine::SetDefaultLanguage
     943       10928 :     return Application::GetSettings().GetLanguageTag().getLanguageType();
     944             : }
     945             : 
     946         306 : sal_uInt16 ScGlobal::GetScriptedWhichID( SvtScriptType nScriptType, sal_uInt16 nWhich )
     947             : {
     948         306 :     switch ( nScriptType )
     949             :     {
     950             :         case SvtScriptType::LATIN:
     951             :         case SvtScriptType::ASIAN:
     952             :         case SvtScriptType::COMPLEX:
     953         306 :         break;      // take exact matches
     954             :         default:    // prefer one, first COMPLEX, then ASIAN
     955           0 :             if ( nScriptType & SvtScriptType::COMPLEX )
     956           0 :                 nScriptType = SvtScriptType::COMPLEX;
     957           0 :             else if ( nScriptType & SvtScriptType::ASIAN )
     958           0 :                 nScriptType = SvtScriptType::ASIAN;
     959             :     }
     960         306 :     switch ( nScriptType )
     961             :     {
     962             :         case SvtScriptType::COMPLEX:
     963             :         {
     964           0 :             switch ( nWhich )
     965             :             {
     966             :                 case ATTR_FONT:
     967             :                 case ATTR_CJK_FONT:
     968           0 :                     nWhich = ATTR_CTL_FONT;
     969           0 :                 break;
     970             :                 case ATTR_FONT_HEIGHT:
     971             :                 case ATTR_CJK_FONT_HEIGHT:
     972           0 :                     nWhich = ATTR_CTL_FONT_HEIGHT;
     973           0 :                 break;
     974             :                 case ATTR_FONT_WEIGHT:
     975             :                 case ATTR_CJK_FONT_WEIGHT:
     976           0 :                     nWhich = ATTR_CTL_FONT_WEIGHT;
     977           0 :                 break;
     978             :                 case ATTR_FONT_POSTURE:
     979             :                 case ATTR_CJK_FONT_POSTURE:
     980           0 :                     nWhich = ATTR_CTL_FONT_POSTURE;
     981           0 :                 break;
     982             :             }
     983             :         }
     984           0 :         break;
     985             :         case SvtScriptType::ASIAN:
     986             :         {
     987           0 :             switch ( nWhich )
     988             :             {
     989             :                 case ATTR_FONT:
     990             :                 case ATTR_CTL_FONT:
     991           0 :                     nWhich = ATTR_CJK_FONT;
     992           0 :                 break;
     993             :                 case ATTR_FONT_HEIGHT:
     994             :                 case ATTR_CTL_FONT_HEIGHT:
     995           0 :                     nWhich = ATTR_CJK_FONT_HEIGHT;
     996           0 :                 break;
     997             :                 case ATTR_FONT_WEIGHT:
     998             :                 case ATTR_CTL_FONT_WEIGHT:
     999           0 :                     nWhich = ATTR_CJK_FONT_WEIGHT;
    1000           0 :                 break;
    1001             :                 case ATTR_FONT_POSTURE:
    1002             :                 case ATTR_CTL_FONT_POSTURE:
    1003           0 :                     nWhich = ATTR_CJK_FONT_POSTURE;
    1004           0 :                 break;
    1005             :             }
    1006             :         }
    1007           0 :         break;
    1008             :         default:
    1009             :         {
    1010         306 :             switch ( nWhich )
    1011             :             {
    1012             :                 case ATTR_CTL_FONT:
    1013             :                 case ATTR_CJK_FONT:
    1014           0 :                     nWhich = ATTR_FONT;
    1015           0 :                 break;
    1016             :                 case ATTR_CTL_FONT_HEIGHT:
    1017             :                 case ATTR_CJK_FONT_HEIGHT:
    1018           0 :                     nWhich = ATTR_FONT_HEIGHT;
    1019           0 :                 break;
    1020             :                 case ATTR_CTL_FONT_WEIGHT:
    1021             :                 case ATTR_CJK_FONT_WEIGHT:
    1022           0 :                     nWhich = ATTR_FONT_WEIGHT;
    1023           0 :                 break;
    1024             :                 case ATTR_CTL_FONT_POSTURE:
    1025             :                 case ATTR_CJK_FONT_POSTURE:
    1026           0 :                     nWhich = ATTR_FONT_POSTURE;
    1027           0 :                 break;
    1028             :             }
    1029             :         }
    1030             :     }
    1031         306 :     return nWhich;
    1032             : }
    1033             : 
    1034         676 : void ScGlobal::AddLanguage( SfxItemSet& rSet, SvNumberFormatter& rFormatter )
    1035             : {
    1036             :     OSL_ENSURE( rSet.GetItemState( ATTR_LANGUAGE_FORMAT, false ) == SfxItemState::DEFAULT,
    1037             :         "ScGlobal::AddLanguage - language already added");
    1038             : 
    1039             :     const SfxPoolItem* pHardItem;
    1040         676 :     if ( rSet.GetItemState( ATTR_VALUE_FORMAT, false, &pHardItem ) == SfxItemState::SET )
    1041             :     {
    1042             :         const SvNumberformat* pHardFormat = rFormatter.GetEntry(
    1043         676 :             static_cast<const SfxUInt32Item*>(pHardItem)->GetValue() );
    1044             : 
    1045         676 :         sal_uLong nParentFmt = 0; // Pool default
    1046         676 :         const SfxItemSet* pParent = rSet.GetParent();
    1047         676 :         if ( pParent )
    1048           0 :             nParentFmt = static_cast<const SfxUInt32Item&>(pParent->Get( ATTR_VALUE_FORMAT )).GetValue();
    1049         676 :         const SvNumberformat* pParFormat = rFormatter.GetEntry( nParentFmt );
    1050             : 
    1051        1352 :         if ( pHardFormat && pParFormat &&
    1052         676 :                 (pHardFormat->GetLanguage() != pParFormat->GetLanguage()) )
    1053          36 :             rSet.Put( SvxLanguageItem( pHardFormat->GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
    1054             :     }
    1055         676 : }
    1056             : 
    1057        3747 : utl::TransliterationWrapper* ScGlobal::GetpTransliteration()
    1058             : {
    1059        3747 :     if ( !pTransliteration )
    1060             :     {
    1061          29 :         const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
    1062             :         pTransliteration = new ::utl::TransliterationWrapper(
    1063          29 :             ::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_IGNORECASE );
    1064          29 :         pTransliteration->loadModuleIfNeeded( eOfficeLanguage );
    1065             :     }
    1066             :     OSL_ENSURE(
    1067             :         pTransliteration,
    1068             :         "ScGlobal::GetpTransliteration() called before ScGlobal::Init()");
    1069        3747 :     return pTransliteration;
    1070             : }
    1071             : 
    1072         935 : const LocaleDataWrapper* ScGlobal::GetpLocaleData()
    1073             : {
    1074             :     OSL_ENSURE(
    1075             :         pLocaleData,
    1076             :         "ScGlobal::GetpLocaleData() called before ScGlobal::Init()");
    1077         935 :     return pLocaleData;
    1078             : }
    1079          32 : CalendarWrapper*     ScGlobal::GetCalendar()
    1080             : {
    1081          32 :     if ( !pCalendar )
    1082             :     {
    1083           2 :         pCalendar = new CalendarWrapper( ::comphelper::getProcessComponentContext() );
    1084           2 :         pCalendar->loadDefaultCalendar( *GetLocale() );
    1085             :     }
    1086          32 :     return pCalendar;
    1087             : }
    1088        3815 : CollatorWrapper*        ScGlobal::GetCollator()
    1089             : {
    1090        3815 :     if ( !pCollator )
    1091             :     {
    1092          14 :         pCollator = new CollatorWrapper( ::comphelper::getProcessComponentContext() );
    1093          14 :         pCollator->loadDefaultCollator( *GetLocale(), SC_COLLATOR_IGNORES );
    1094             :     }
    1095        3815 :     return pCollator;
    1096             : }
    1097        3887 : CollatorWrapper*        ScGlobal::GetCaseCollator()
    1098             : {
    1099        3887 :     if ( !pCaseCollator )
    1100             :     {
    1101           2 :         pCaseCollator = new CollatorWrapper( ::comphelper::getProcessComponentContext() );
    1102           2 :         pCaseCollator->loadDefaultCollator( *GetLocale(), 0 );
    1103             :     }
    1104        3887 :     return pCaseCollator;
    1105             : }
    1106          36 : ::utl::TransliterationWrapper* ScGlobal::GetCaseTransliteration()
    1107             : {
    1108          36 :     if ( !pCaseTransliteration )
    1109             :     {
    1110           1 :         const LanguageType eOfficeLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
    1111           1 :         pCaseTransliteration = new ::utl::TransliterationWrapper(::comphelper::getProcessComponentContext(), SC_TRANSLITERATION_CASESENSE );
    1112           1 :         pCaseTransliteration->loadModuleIfNeeded( eOfficeLanguage );
    1113             :     }
    1114          36 :     return pCaseTransliteration;
    1115             : }
    1116           0 : IntlWrapper*         ScGlobal::GetScIntlWrapper()
    1117             : {
    1118           0 :     if ( !pScIntlWrapper )
    1119             :     {
    1120           0 :         pScIntlWrapper = new IntlWrapper( LanguageTag( *GetLocale()) );
    1121             :     }
    1122           0 :     return pScIntlWrapper;
    1123             : }
    1124         233 : ::com::sun::star::lang::Locale*     ScGlobal::GetLocale()
    1125             : {
    1126         233 :     if ( !pLocale )
    1127             :     {
    1128          49 :         pLocale = new ::com::sun::star::lang::Locale( Application::GetSettings().GetLanguageTag().getLocale());
    1129             :     }
    1130         233 :     return pLocale;
    1131             : }
    1132             : 
    1133           4 : ScFieldEditEngine& ScGlobal::GetStaticFieldEditEngine()
    1134             : {
    1135           4 :     if (!pFieldEditEngine)
    1136             :     {
    1137             :         // Creating a ScFieldEditEngine with pDocument=NULL leads to document
    1138             :         // specific fields not being resolvable! See
    1139             :         // ScFieldEditEngine::CalcFieldValue(). pEnginePool=NULL lets
    1140             :         // EditEngine internally create and delete a default pool.
    1141           1 :         pFieldEditEngine = new ScFieldEditEngine( NULL, NULL);
    1142             :     }
    1143           4 :     return *pFieldEditEngine;
    1144             : }
    1145             : 
    1146           0 : OUString ScGlobal::ReplaceOrAppend( const OUString& rString,
    1147             :         const OUString& rPlaceholder, const OUString& rReplacement )
    1148             : {
    1149           0 :     if (rString.isEmpty())
    1150           0 :         return rReplacement;
    1151           0 :     sal_Int32 nFound = rString.indexOf( rPlaceholder);
    1152           0 :     if (nFound < 0)
    1153             :     {
    1154           0 :         if (rString[rString.getLength()-1] == ' ')
    1155           0 :             return rString + rReplacement;
    1156           0 :         return rString + " " + rReplacement;
    1157             :     }
    1158           0 :     return rString.replaceFirst( rPlaceholder, rReplacement, &nFound);
    1159         156 : }
    1160             : 
    1161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11