1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include "stylehelper.hxx"
24 #include "globstr.hrc"
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!
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"
38 struct ScDisplayNameMap
44 static const ScDisplayNameMap
* lcl_GetStyleNameMap( sal_uInt16 nType
)
46 if ( nType
== SFX_STYLE_FAMILY_PARA
)
48 static bool bCellMapFilled
= false;
49 static ScDisplayNameMap aCellMap
[6];
50 if ( !bCellMapFilled
)
52 aCellMap
[0].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_STANDARD
);
53 aCellMap
[0].aProgName
= OUString( SC_STYLE_PROG_STANDARD
);
55 aCellMap
[1].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_RESULT
);
56 aCellMap
[1].aProgName
= OUString( SC_STYLE_PROG_RESULT
);
58 aCellMap
[2].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_RESULT1
);
59 aCellMap
[2].aProgName
= OUString( SC_STYLE_PROG_RESULT1
);
61 aCellMap
[3].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_HEADLINE
);
62 aCellMap
[3].aProgName
= OUString( SC_STYLE_PROG_HEADLINE
);
64 aCellMap
[4].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_HEADLINE1
);
65 aCellMap
[4].aProgName
= OUString( SC_STYLE_PROG_HEADLINE1
);
67 // last entry remains empty
69 bCellMapFilled
= true;
73 else if ( nType
== SFX_STYLE_FAMILY_PAGE
)
75 static bool bPageMapFilled
= false;
76 static ScDisplayNameMap aPageMap
[3];
77 if ( !bPageMapFilled
)
79 aPageMap
[0].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_STANDARD
);
80 aPageMap
[0].aProgName
= OUString( SC_STYLE_PROG_STANDARD
);
82 aPageMap
[1].aDispName
= ScGlobal::GetRscString( STR_STYLENAME_REPORT
);
83 aPageMap
[1].aProgName
= OUString( SC_STYLE_PROG_REPORT
);
85 // last entry remains empty
87 bPageMapFilled
= true;
91 OSL_FAIL("invalid family");
95 // programmatic name suffix for display names that match other programmatic names
96 // is " (user)" including a space
98 #define SC_SUFFIX_USER " (user)"
99 #define SC_SUFFIX_USER_LEN 7
101 static bool lcl_EndsWithUser( const OUString
& rString
)
103 return rString
.endsWith(SC_SUFFIX_USER
);
106 OUString
ScStyleNameConversion::DisplayToProgrammaticName( const OUString
& rDispName
, sal_uInt16 nType
)
108 bool bDisplayIsProgrammatic
= false;
110 const ScDisplayNameMap
* pNames
= lcl_GetStyleNameMap( nType
);
115 if (pNames
->aDispName
== rDispName
)
116 return pNames
->aProgName
;
117 else if (pNames
->aProgName
== rDispName
)
118 bDisplayIsProgrammatic
= true; // display name matches any programmatic name
120 while( !(++pNames
)->aDispName
.isEmpty() );
123 if ( bDisplayIsProgrammatic
|| lcl_EndsWithUser( rDispName
) )
125 // add the (user) suffix if the display name matches any style's programmatic name
126 // or if it already contains the suffix
127 return rDispName
+ SC_SUFFIX_USER
;
133 OUString
ScStyleNameConversion::ProgrammaticToDisplayName( const OUString
& rProgName
, sal_uInt16 nType
)
135 if ( lcl_EndsWithUser( rProgName
) )
137 // remove the (user) suffix, don't compare to map entries
138 return rProgName
.copy( 0, rProgName
.getLength() - SC_SUFFIX_USER_LEN
);
141 const ScDisplayNameMap
* pNames
= lcl_GetStyleNameMap( nType
);
146 if (pNames
->aProgName
== rProgName
)
147 return pNames
->aDispName
;
149 while( !(++pNames
)->aDispName
.isEmpty() );
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */