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

Generated by: LCOV version 1.10