update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / source / core / tool / stylehelper.cxx
blob364c070c3fde4a28a841e20e8d581b3d9c17dd43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <rsc/rscsfx.hxx>
21 #include <osl/diagnose.h>
23 #include "stylehelper.hxx"
24 #include "global.hxx"
25 #include "globstr.hrc"
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!
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"
39 struct ScDisplayNameMap
41 OUString aDispName;
42 OUString aProgName;
45 static const ScDisplayNameMap* lcl_GetStyleNameMap( sal_uInt16 nType )
47 if ( nType == SFX_STYLE_FAMILY_PARA )
49 static bool bCellMapFilled = false;
50 static ScDisplayNameMap aCellMap[6];
51 if ( !bCellMapFilled )
53 aCellMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
54 aCellMap[0].aProgName = SC_STYLE_PROG_STANDARD;
56 aCellMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT );
57 aCellMap[1].aProgName = SC_STYLE_PROG_RESULT;
59 aCellMap[2].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT1 );
60 aCellMap[2].aProgName = SC_STYLE_PROG_RESULT1;
62 aCellMap[3].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE );
63 aCellMap[3].aProgName = SC_STYLE_PROG_HEADLINE;
65 aCellMap[4].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE1 );
66 aCellMap[4].aProgName = SC_STYLE_PROG_HEADLINE1;
68 // last entry remains empty
70 bCellMapFilled = true;
72 return aCellMap;
74 else if ( nType == SFX_STYLE_FAMILY_PAGE )
76 static bool bPageMapFilled = false;
77 static ScDisplayNameMap aPageMap[3];
78 if ( !bPageMapFilled )
80 aPageMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
81 aPageMap[0].aProgName = SC_STYLE_PROG_STANDARD;
83 aPageMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_REPORT );
84 aPageMap[1].aProgName = SC_STYLE_PROG_REPORT;
86 // last entry remains empty
88 bPageMapFilled = true;
90 return aPageMap;
92 OSL_FAIL("invalid family");
93 return NULL;
96 // programmatic name suffix for display names that match other programmatic names
97 // is " (user)" including a space
99 #define SC_SUFFIX_USER " (user)"
100 #define SC_SUFFIX_USER_LEN 7
102 static bool lcl_EndsWithUser( const OUString& rString )
104 return rString.endsWith(SC_SUFFIX_USER);
107 OUString ScStyleNameConversion::DisplayToProgrammaticName( const OUString& rDispName, sal_uInt16 nType )
109 bool bDisplayIsProgrammatic = false;
111 const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
112 if (pNames)
116 if (pNames->aDispName == rDispName)
117 return pNames->aProgName;
118 else if (pNames->aProgName == rDispName)
119 bDisplayIsProgrammatic = true; // display name matches any programmatic name
121 while( !(++pNames)->aDispName.isEmpty() );
124 if ( bDisplayIsProgrammatic || lcl_EndsWithUser( rDispName ) )
126 // add the (user) suffix if the display name matches any style's programmatic name
127 // or if it already contains the suffix
128 return rDispName + SC_SUFFIX_USER;
131 return rDispName;
134 OUString ScStyleNameConversion::ProgrammaticToDisplayName( const OUString& rProgName, sal_uInt16 nType )
136 if ( lcl_EndsWithUser( rProgName ) )
138 // remove the (user) suffix, don't compare to map entries
139 return rProgName.copy( 0, rProgName.getLength() - SC_SUFFIX_USER_LEN );
142 const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
143 if (pNames)
147 if (pNames->aProgName == rProgName)
148 return pNames->aDispName;
150 while( !(++pNames)->aDispName.isEmpty() );
152 return rProgName;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */