diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-04 14:30:13 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-05 11:10:17 -0400 |
commit | d789d1a1966b4385343db6b9c5a4d855147817e2 (patch) | |
tree | 0265f0dedf92893ce60d7a2b893dd579e8936875 /editeng | |
parent | Nobody uses this. (diff) | |
download | core-d789d1a1966b4385343db6b9c5a4d855147817e2.tar.gz core-d789d1a1966b4385343db6b9c5a4d855147817e2.zip |
Avoid the ID of unknown field being the highest number of all field IDs.
Change-Id: Ifcc62cd15dcfe0cb37f7c851930ff103384f3827
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/inc/editeng/unofield.hxx | 1 | ||||
-rw-r--r-- | editeng/source/uno/unofield.cxx | 29 |
2 files changed, 19 insertions, 11 deletions
diff --git a/editeng/inc/editeng/unofield.hxx b/editeng/inc/editeng/unofield.hxx index 2c53fb7db499..13e8e70d3c23 100644 --- a/editeng/inc/editeng/unofield.hxx +++ b/editeng/inc/editeng/unofield.hxx @@ -57,7 +57,6 @@ #define ID_HEADERFIELD 12 #define ID_FOOTERFIELD 13 #define ID_DATETIMEFIELD 14 -#define ID_UNKNOWN 15 // this must be the last entry class SvxUnoFieldData_Impl; class SfxItemPropertySet; diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx index 10380668c053..aa90bfe04ea8 100644 --- a/editeng/source/uno/unofield.cxx +++ b/editeng/source/uno/unofield.cxx @@ -59,6 +59,13 @@ using namespace ::com::sun::star; #define WID_STRING2 6 #define WID_STRING3 7 +const sal_Int32 UNKNOWN_FIELD = -1; + +inline bool isValidFieldId(sal_Int32 nId) +{ + return nId >= 0; +} + class SvxUnoFieldData_Impl { public: @@ -181,8 +188,7 @@ static sal_Char const* aFieldItemNameMap_Impl[] = "ExtDate", "Header", "Footer", - "DateTime", - "Unknown" + "DateTime" }; /* conversion routines */ @@ -314,7 +320,7 @@ SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, co : OComponentHelper( getMutex() ) , mxAnchor( xAnchor ) , mpPropSet(NULL) -, mnServiceId(ID_UNKNOWN) +, mnServiceId(UNKNOWN_FIELD) , mpImpl( new SvxUnoFieldData_Impl ) { DBG_ASSERT(pData, "pFieldData == NULL! [CL]" ); @@ -324,8 +330,8 @@ SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, co if(pData) { mnServiceId = GetFieldId(pData); - DBG_ASSERT(mnServiceId != ID_UNKNOWN, "unknown SvxFieldData! [CL]"); - if(mnServiceId != ID_UNKNOWN) + DBG_ASSERT(mnServiceId != UNKNOWN_FIELD, "unknown SvxFieldData! [CL]"); + if(mnServiceId != UNKNOWN_FIELD) { // extract field properties from data class switch( mnServiceId ) @@ -603,8 +609,11 @@ OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand ) if(bShowCommand) { - DBG_ASSERT( ((sal_uInt32)mnServiceId) < ID_UNKNOWN, "Unknown field type" ); - return OUString::createFromAscii( aFieldItemNameMap_Impl[(((sal_uInt32)mnServiceId) > ID_UNKNOWN)? ID_UNKNOWN : mnServiceId ] ); + DBG_ASSERT(mnServiceId >= 0, "Unknown field type"); + if (isValidFieldId(mnServiceId)) + return OUString::createFromAscii(aFieldItemNameMap_Impl[mnServiceId]); + else + return OUString("Unknown"); } else { @@ -1045,7 +1054,7 @@ sal_Int32 SvxUnoTextField::GetFieldId( const SvxFieldData* pFieldData ) const th else if( pFieldData->ISA( SvxDateTimeField ) ) return ID_DATETIMEFIELD; - return ID_UNKNOWN; + return UNKNOWN_FIELD; } // lang::XServiceInfo @@ -1125,7 +1134,7 @@ uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rt { OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) ); - sal_Int32 nId = ID_UNKNOWN; + sal_Int32 nId = UNKNOWN_FIELD; if ( aFieldType == "DateTime" ) { @@ -1167,7 +1176,7 @@ uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rt nId = ID_MEASUREFIELD; } - if( nId != ID_UNKNOWN ) + if (nId != UNKNOWN_FIELD) xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId ); } |