#90968# Add two new methods to allow for disambiguation of user defined styles which clash with programmatic names

This commit is contained in:
Martin Gallwey
2001-08-16 11:10:24 +00:00
parent dc5953ec14
commit 4fbc9dd48b
2 changed files with 102 additions and 5 deletions
+24 -3
View File
@@ -2,9 +2,9 @@
*
* $RCSfile: SwStyleNameMapper.hxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: mtg $ $Date: 2001-07-24 17:21:11 $
* last change: $Author: mtg $ $Date: 2001-08-16 12:07:45 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -101,6 +101,22 @@
* 5. Numbering Rule contains the NumRule name array.
*/
/*
* There is a further complication that came to light later. If someone enters
* a user-defined style name which is the same as a programmatic name, this
* name clash must be handled.
*
* Therefore, when there is a danger of a nameclash, the boolean bDisambiguate
* must be set to true in the SwStyleNameMapper call (it defaults to false).
* This will cause the following to happen:
*
* If the UI style name either equals a programmatic name or already ends
* with " (user)", then it must append " (user)" to the end.
*
* When a programmatic name is being converted to a UI name, if it ends in
* " (user)", we simply remove it.
*/
class SvStringsDtor;
class String;
struct SwTableEntry;
@@ -211,11 +227,16 @@ protected:
static void fillNameFromId ( sal_uInt16 nId, String &rName, sal_Bool bProgName );
static const String& getNameFromId ( sal_uInt16 nId, const String &rName, sal_Bool bProgName );
static const NameToIdHash& getHashTable ( SwGetPoolIdFromName, sal_Bool bProgName );
static sal_Bool SuffixIsUser ( const String & rString );
static void CheckSuffixAndDelete ( String & rString );
public:
// This gets the UI Name from the programmatic name
static const String& GetUIName ( const String& rName, SwGetPoolIdFromName );
static void FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
// Get the programmatic Name from the UI name
static const String& GetProgName( const String& rName, SwGetPoolIdFromName );
static const String& GetProgName ( const String& rName, SwGetPoolIdFromName );
static void FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName, sal_Bool bDisambiguate = sal_False );
// This gets the UI Name from the Pool ID
static void FillUIName ( sal_uInt16 nId, String& rFillName );
+78 -2
View File
@@ -2,9 +2,9 @@
*
* $RCSfile: SwStyleNameMapper.cxx,v $
*
* $Revision: 1.5 $
* $Revision: 1.6 $
*
* last change: $Author: mtg $ $Date: 2001-07-24 18:16:00 $
* last change: $Author: mtg $ $Date: 2001-08-16 12:10:24 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -359,6 +359,35 @@ const struct SwTableEntry NumRuleProgNameTable [] =
};
#undef ENTRY
sal_Bool SwStyleNameMapper::SuffixIsUser ( const String & rString )
{
const sal_Unicode *pChar = rString.GetBuffer();
sal_Int32 nLen = rString.Len();
return nLen <= 8 ? sal_False :
pChar[nLen-7] == ' ' &&
pChar[nLen-6] == '(' &&
pChar[nLen-5] == 'u' &&
pChar[nLen-4] == 's' &&
pChar[nLen-3] == 'e' &&
pChar[nLen-2] == 'r' &&
pChar[nLen-1] == ')';
}
void SwStyleNameMapper::CheckSuffixAndDelete ( String & rString )
{
const sal_Unicode *pChar = rString.GetBuffer();
sal_Int32 nLen = rString.Len();
if (nLen > 8 &&
pChar[nLen-7] == ' ' &&
pChar[nLen-6] == '(' &&
pChar[nLen-5] == 'u' &&
pChar[nLen-4] == 's' &&
pChar[nLen-3] == 'e' &&
pChar[nLen-2] == 'r' &&
pChar[nLen-1] == ')')
{
rString.Erase ( nLen - 7, 7 );
}
}
const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlags, sal_Bool bProgName )
{
NameToIdHash *pHash;
@@ -630,6 +659,7 @@ const String& SwStyleNameMapper::GetUIName ( const String& rName, SwGetPoolIdFro
return nId != USHRT_MAX ? GetUIName( nId, rName ) : rName;
}
// Get the programmatic Name from the UI name
const String& SwStyleNameMapper::GetProgName( const String& rName, SwGetPoolIdFromName eFlags )
{
@@ -637,6 +667,52 @@ const String& SwStyleNameMapper::GetProgName( const String& rName, SwGetPoolIdFr
return nId != USHRT_MAX ? GetProgName( nId, rName ) : rName;
}
// Get the programmatic name from the UI name in rName and put it into rFillName
void SwStyleNameMapper::FillProgName ( const String& rName, String& rFillName, SwGetPoolIdFromName eFlags, sal_Bool bDisambiguate )
{
sal_uInt16 nId = GetPoolIdFromUIName ( rName, eFlags );
if ( bDisambiguate && nId == USHRT_MAX )
{
// rName isn't in our UI name table...check if it's in the programmatic one
nId = GetPoolIdFromProgName ( rName, eFlags );
rFillName = rName;
if (nId == USHRT_MAX )
{
// It isn't ...make sure the suffix isn't already " (user)"...if it is,
// we need to add another one
if ( SuffixIsUser ( rFillName ) )
rFillName.AppendAscii ( RTL_CONSTASCII_STRINGPARAM ( " (user)" ) );
}
else
{
// It's in the programmatic name table...append suffix
rFillName.AppendAscii ( RTL_CONSTASCII_STRINGPARAM ( " (user)" ) );
}
}
else
{
// If we aren't trying to disambiguate, then just do a normal fill
fillNameFromId ( nId, rFillName, sal_True);
}
}
// Get the UI name from the programmatic name in rName and put it into rFillName
void SwStyleNameMapper::FillUIName ( const String& rName, String& rFillName, SwGetPoolIdFromName eFlags, sal_Bool bDisambiguate )
{
sal_uInt16 nId = GetPoolIdFromProgName ( rName, eFlags );
if ( bDisambiguate && nId == USHRT_MAX )
{
rFillName = rName;
// rName isn't in our Prog name table...check if it has a " (user)" suffix, if so remove it
CheckSuffixAndDelete ( rFillName );
}
else
{
// If we aren't trying to disambiguate, then just do a normal fill
fillNameFromId ( nId, rFillName, sal_False);
}
}
const String& SwStyleNameMapper::getNameFromId( sal_uInt16 nId, const String& rFillName, sal_Bool bProgName )
{
sal_uInt16 nStt = 0;