LCOV - code coverage report
Current view: top level - sc/source/core/tool - stylehelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 49 53 92.5 %
Date: 2015-06-13 12:38:46 Functions: 10 10 100.0 %
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 <rsc/rscsfx.hxx>
      21             : #include <osl/diagnose.h>
      22             : 
      23             : #include "stylehelper.hxx"
      24             : #include "global.hxx"
      25             : #include "globstr.hrc"
      26             : 
      27             : //  conversion programmatic <-> display (visible) name
      28             : //  currently, the core always has the visible names
      29             : //  the api is required to use programmatic names for default styles
      30             : //  these programmatic names must never change!
      31             : 
      32             : #define SC_STYLE_PROG_STANDARD      "Default"
      33             : #define SC_STYLE_PROG_RESULT        "Result"
      34             : #define SC_STYLE_PROG_RESULT1       "Result2"
      35             : #define SC_STYLE_PROG_HEADLINE      "Heading"
      36             : #define SC_STYLE_PROG_HEADLINE1     "Heading1"
      37             : #define SC_STYLE_PROG_REPORT        "Report"
      38             : 
      39         750 : struct ScDisplayNameMap
      40             : {
      41             :     OUString  aDispName;
      42             :     OUString  aProgName;
      43             : };
      44             : 
      45       13391 : static const ScDisplayNameMap* lcl_GetStyleNameMap( sal_uInt16 nType )
      46             : {
      47       13391 :     if ( nType == SFX_STYLE_FAMILY_PARA )
      48             :     {
      49             :         static bool bCellMapFilled = false;
      50       10529 :         static ScDisplayNameMap aCellMap[6];
      51       10486 :         if ( !bCellMapFilled )
      52             :         {
      53          43 :             aCellMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
      54          43 :             aCellMap[0].aProgName = SC_STYLE_PROG_STANDARD;
      55             : 
      56          43 :             aCellMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT );
      57          43 :             aCellMap[1].aProgName = SC_STYLE_PROG_RESULT;
      58             : 
      59          43 :             aCellMap[2].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT1 );
      60          43 :             aCellMap[2].aProgName = SC_STYLE_PROG_RESULT1;
      61             : 
      62          43 :             aCellMap[3].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE );
      63          43 :             aCellMap[3].aProgName = SC_STYLE_PROG_HEADLINE;
      64             : 
      65          43 :             aCellMap[4].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE1 );
      66          43 :             aCellMap[4].aProgName = SC_STYLE_PROG_HEADLINE1;
      67             : 
      68             :             //  last entry remains empty
      69             : 
      70          43 :             bCellMapFilled = true;
      71             :         }
      72       10486 :         return aCellMap;
      73             :     }
      74        2905 :     else if ( nType == SFX_STYLE_FAMILY_PAGE )
      75             :     {
      76             :         static bool bPageMapFilled = false;
      77        2944 :         static ScDisplayNameMap aPageMap[3];
      78        2905 :         if ( !bPageMapFilled )
      79             :         {
      80          39 :             aPageMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
      81          39 :             aPageMap[0].aProgName = SC_STYLE_PROG_STANDARD;
      82             : 
      83          39 :             aPageMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_REPORT );
      84          39 :             aPageMap[1].aProgName = SC_STYLE_PROG_REPORT;
      85             : 
      86             :             //  last entry remains empty
      87             : 
      88          39 :             bPageMapFilled = true;
      89             :         }
      90        2905 :         return aPageMap;
      91             :     }
      92             :     OSL_FAIL("invalid family");
      93           0 :     return NULL;
      94             : }
      95             : 
      96             : //  programmatic name suffix for display names that match other programmatic names
      97             : //  is " (user)" including a space
      98             : 
      99             : #define SC_SUFFIX_USER      " (user)"
     100             : #define SC_SUFFIX_USER_LEN  7
     101             : 
     102       10075 : static bool lcl_EndsWithUser( const OUString& rString )
     103             : {
     104       10075 :     return rString.endsWith(SC_SUFFIX_USER);
     105             : }
     106             : 
     107        3790 : OUString ScStyleNameConversion::DisplayToProgrammaticName( const OUString& rDispName, sal_uInt16 nType )
     108             : {
     109        3790 :     bool bDisplayIsProgrammatic = false;
     110             : 
     111        3790 :     const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
     112        3790 :     if (pNames)
     113             :     {
     114       12932 :         do
     115             :         {
     116        9782 :             if (pNames->aDispName == rDispName)
     117        3316 :                 return pNames->aProgName;
     118        6466 :             else if (pNames->aProgName == rDispName)
     119           0 :                 bDisplayIsProgrammatic = true;          // display name matches any programmatic name
     120             :         }
     121        6466 :         while( !(++pNames)->aDispName.isEmpty() );
     122             :     }
     123             : 
     124         474 :     if ( bDisplayIsProgrammatic || lcl_EndsWithUser( rDispName ) )
     125             :     {
     126             :         //  add the (user) suffix if the display name matches any style's programmatic name
     127             :         //  or if it already contains the suffix
     128           0 :         return rDispName + SC_SUFFIX_USER;
     129             :     }
     130             : 
     131         474 :     return rDispName;
     132             : }
     133             : 
     134        9601 : OUString ScStyleNameConversion::ProgrammaticToDisplayName( const OUString& rProgName, sal_uInt16 nType )
     135             : {
     136        9601 :     if ( lcl_EndsWithUser( rProgName ) )
     137             :     {
     138             :         //  remove the (user) suffix, don't compare to map entries
     139           0 :         return rProgName.copy( 0, rProgName.getLength() - SC_SUFFIX_USER_LEN );
     140             :     }
     141             : 
     142        9601 :     const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
     143        9601 :     if (pNames)
     144             :     {
     145       38684 :         do
     146             :         {
     147       25921 :             if (pNames->aProgName == rProgName)
     148        6579 :                 return pNames->aDispName;
     149             :         }
     150       19342 :         while( !(++pNames)->aDispName.isEmpty() );
     151             :     }
     152        3022 :     return rProgName;
     153         156 : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11