2013-06-29 02:06:25 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rsc/rscsfx.hxx>
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
#include "stylehelper.hxx"
|
|
|
|
#include "global.hxx"
|
|
|
|
#include "globstr.hrc"
|
|
|
|
|
|
|
|
// conversion programmatic <-> display (visible) name
|
|
|
|
// currently, the core always has the visible names
|
|
|
|
// the api is required to use programmatic names for default styles
|
|
|
|
// these programmatic names must never change!
|
|
|
|
|
|
|
|
#define SC_STYLE_PROG_STANDARD "Default"
|
|
|
|
#define SC_STYLE_PROG_RESULT "Result"
|
|
|
|
#define SC_STYLE_PROG_RESULT1 "Result2"
|
|
|
|
#define SC_STYLE_PROG_HEADLINE "Heading"
|
|
|
|
#define SC_STYLE_PROG_HEADLINE1 "Heading1"
|
|
|
|
#define SC_STYLE_PROG_REPORT "Report"
|
|
|
|
|
|
|
|
struct ScDisplayNameMap
|
|
|
|
{
|
|
|
|
OUString aDispName;
|
|
|
|
OUString aProgName;
|
|
|
|
};
|
|
|
|
|
2016-05-04 11:31:33 +02:00
|
|
|
static const ScDisplayNameMap* lcl_GetStyleNameMap( SfxStyleFamily nType )
|
2013-06-29 02:06:25 +02:00
|
|
|
{
|
2016-05-04 11:31:33 +02:00
|
|
|
if ( nType == SfxStyleFamily::Para )
|
2013-06-29 02:06:25 +02:00
|
|
|
{
|
|
|
|
static bool bCellMapFilled = false;
|
|
|
|
static ScDisplayNameMap aCellMap[6];
|
|
|
|
if ( !bCellMapFilled )
|
|
|
|
{
|
|
|
|
aCellMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
|
2014-12-18 13:29:00 +01:00
|
|
|
aCellMap[0].aProgName = SC_STYLE_PROG_STANDARD;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
aCellMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT );
|
2014-12-18 13:29:00 +01:00
|
|
|
aCellMap[1].aProgName = SC_STYLE_PROG_RESULT;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
aCellMap[2].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT1 );
|
2014-12-18 13:29:00 +01:00
|
|
|
aCellMap[2].aProgName = SC_STYLE_PROG_RESULT1;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
aCellMap[3].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE );
|
2014-12-18 13:29:00 +01:00
|
|
|
aCellMap[3].aProgName = SC_STYLE_PROG_HEADLINE;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
aCellMap[4].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE1 );
|
2014-12-18 13:29:00 +01:00
|
|
|
aCellMap[4].aProgName = SC_STYLE_PROG_HEADLINE1;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
// last entry remains empty
|
|
|
|
|
|
|
|
bCellMapFilled = true;
|
|
|
|
}
|
|
|
|
return aCellMap;
|
|
|
|
}
|
2016-05-04 11:31:33 +02:00
|
|
|
else if ( nType == SfxStyleFamily::Page )
|
2013-06-29 02:06:25 +02:00
|
|
|
{
|
|
|
|
static bool bPageMapFilled = false;
|
|
|
|
static ScDisplayNameMap aPageMap[3];
|
|
|
|
if ( !bPageMapFilled )
|
|
|
|
{
|
|
|
|
aPageMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD );
|
2014-12-18 13:29:00 +01:00
|
|
|
aPageMap[0].aProgName = SC_STYLE_PROG_STANDARD;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
aPageMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_REPORT );
|
2014-12-18 13:29:00 +01:00
|
|
|
aPageMap[1].aProgName = SC_STYLE_PROG_REPORT;
|
2013-06-29 02:06:25 +02:00
|
|
|
|
|
|
|
// last entry remains empty
|
|
|
|
|
|
|
|
bPageMapFilled = true;
|
|
|
|
}
|
|
|
|
return aPageMap;
|
|
|
|
}
|
|
|
|
OSL_FAIL("invalid family");
|
2015-11-10 10:22:39 +01:00
|
|
|
return nullptr;
|
2013-06-29 02:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// programmatic name suffix for display names that match other programmatic names
|
|
|
|
// is " (user)" including a space
|
|
|
|
|
|
|
|
#define SC_SUFFIX_USER " (user)"
|
|
|
|
#define SC_SUFFIX_USER_LEN 7
|
|
|
|
|
|
|
|
static bool lcl_EndsWithUser( const OUString& rString )
|
|
|
|
{
|
|
|
|
return rString.endsWith(SC_SUFFIX_USER);
|
|
|
|
}
|
|
|
|
|
2016-05-04 11:31:33 +02:00
|
|
|
OUString ScStyleNameConversion::DisplayToProgrammaticName( const OUString& rDispName, SfxStyleFamily nType )
|
2013-06-29 02:06:25 +02:00
|
|
|
{
|
|
|
|
bool bDisplayIsProgrammatic = false;
|
|
|
|
|
|
|
|
const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
|
|
|
|
if (pNames)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (pNames->aDispName == rDispName)
|
|
|
|
return pNames->aProgName;
|
|
|
|
else if (pNames->aProgName == rDispName)
|
|
|
|
bDisplayIsProgrammatic = true; // display name matches any programmatic name
|
|
|
|
}
|
|
|
|
while( !(++pNames)->aDispName.isEmpty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( bDisplayIsProgrammatic || lcl_EndsWithUser( rDispName ) )
|
|
|
|
{
|
|
|
|
// add the (user) suffix if the display name matches any style's programmatic name
|
|
|
|
// or if it already contains the suffix
|
2013-09-10 23:03:56 +00:00
|
|
|
return rDispName + SC_SUFFIX_USER;
|
2013-06-29 02:06:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rDispName;
|
|
|
|
}
|
|
|
|
|
2016-05-04 11:31:33 +02:00
|
|
|
OUString ScStyleNameConversion::ProgrammaticToDisplayName( const OUString& rProgName, SfxStyleFamily nType )
|
2013-06-29 02:06:25 +02:00
|
|
|
{
|
|
|
|
if ( lcl_EndsWithUser( rProgName ) )
|
|
|
|
{
|
|
|
|
// remove the (user) suffix, don't compare to map entries
|
|
|
|
return rProgName.copy( 0, rProgName.getLength() - SC_SUFFIX_USER_LEN );
|
|
|
|
}
|
|
|
|
|
|
|
|
const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType );
|
|
|
|
if (pNames)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (pNames->aProgName == rProgName)
|
|
|
|
return pNames->aDispName;
|
|
|
|
}
|
|
|
|
while( !(++pNames)->aDispName.isEmpty() );
|
|
|
|
}
|
|
|
|
return rProgName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|