[Libreoffice-commits] core.git: 2 commits - svtools/source
Noel Grandin
noel at peralex.com
Thu Aug 22 02:56:17 PDT 2013
svtools/source/contnr/templwin.cxx | 12 ++++++------
svtools/source/misc/imagemgr.cxx | 33 +++++++++++++--------------------
2 files changed, 19 insertions(+), 26 deletions(-)
New commits:
commit 9f54d3847dd424d0e144ada64758772e14f12c1b
Author: Noel Grandin <noel at peralex.com>
Date: Thu Aug 22 11:54:04 2013 +0200
fix dodgy NO_INDEX code
The comparison of NO_INDEX to getLength() makes no sense, and makes
even less sense now that the code is using OUString, after my recent
change
Change return type to sal_Int32, and change NO_INDEX to -1, so that
it can't possibly conflict with a valid index.
Change-Id: I65cb945096b4b9cb80f61d896177c2562a0d2c76
diff --git a/svtools/source/misc/imagemgr.cxx b/svtools/source/misc/imagemgr.cxx
index 57ec736..b9f78c1 100644
--- a/svtools/source/misc/imagemgr.cxx
+++ b/svtools/source/misc/imagemgr.cxx
@@ -43,7 +43,7 @@
// globals *******************************************************************
-#define NO_INDEX ((sal_uInt16)0xFFFF)
+#define NO_INDEX (-1)
#define CONTENT_HELPER ::utl::UCBContentHelper
struct SvtExtensionResIdMapping_Impl
@@ -261,12 +261,12 @@ static OUString GetImageExtensionByFactory_Impl( const OUString& rURL )
return aExtension;
}
-static sal_uInt16 GetIndexOfExtension_Impl( const OUString& rExtension )
+static sal_Int32 GetIndexOfExtension_Impl( const OUString& rExtension )
{
- sal_uInt16 nRet = NO_INDEX;
+ sal_Int32 nRet = NO_INDEX;
if ( !rExtension.isEmpty() )
{
- sal_uInt16 nIndex = 0;
+ sal_Int32 nIndex = 0;
OUString aExt = rExtension.toAsciiLowerCase();
while ( ExtensionMap_Impl[ nIndex ]._pExt )
{
@@ -285,15 +285,12 @@ static sal_uInt16 GetIndexOfExtension_Impl( const OUString& rExtension )
static sal_uInt16 GetImageId_Impl( const OUString& rExtension )
{
sal_uInt16 nImage = IMG_FILE;
- if ( rExtension.getLength() != NO_INDEX )
+ sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
+ if ( nIndex != NO_INDEX )
{
- sal_uInt16 nIndex = GetIndexOfExtension_Impl( rExtension );
- if ( nIndex != NO_INDEX )
- {
- nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
- if ( !nImage )
- nImage = IMG_FILE;
- }
+ nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
+ if ( !nImage )
+ nImage = IMG_FILE;
}
return nImage;
@@ -411,15 +408,11 @@ static sal_uInt16 GetImageId_Impl( const INetURLObject& rObject, sal_Bool bDetec
static sal_uInt16 GetDescriptionId_Impl( const OUString& rExtension, sal_Bool& rbShowExt )
{
sal_uInt16 nId = 0;
-
- if ( rExtension.getLength() != NO_INDEX )
+ sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
+ if ( nIndex != NO_INDEX )
{
- sal_uInt16 nIndex = GetIndexOfExtension_Impl( rExtension );
- if ( nIndex != NO_INDEX )
- {
- nId = ExtensionMap_Impl[ nIndex ]._nStrId;
- rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
- }
+ nId = ExtensionMap_Impl[ nIndex ]._nStrId;
+ rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
}
return nId;
commit 453fe67d74ace81cd1b85fb24bb84b292492e6f7
Author: Noel Grandin <noel at peralex.com>
Date: Thu Aug 22 11:50:17 2013 +0200
fix use of dynamically allocated OUString
after my change in ea5cba1f88a4e183b135ee8df72fae9c0ee32aa6, the
code is passing in the address of a local OUString member, then
later delete'ing that pointer.
Change it to pass in new instance of OUString
Change-Id: I9ae5876464fc0dcb74fbd152fd3f96cf856688c8
diff --git a/svtools/source/contnr/templwin.cxx b/svtools/source/contnr/templwin.cxx
index 8acdca1..c9f8604 100644
--- a/svtools/source/contnr/templwin.cxx
+++ b/svtools/source/contnr/templwin.cxx
@@ -186,7 +186,7 @@ SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
OUString aEntryStr = SVT_RESSTR(STR_SVT_NEWDOC);
SvxIconChoiceCtrlEntry* pEntry =
aIconCtrl.InsertEntry( aEntryStr, aImage, ICON_POS_NEWDOC );
- pEntry->SetUserData( &aNewDocumentRootURL );
+ pEntry->SetUserData( new OUString(aNewDocumentRootURL) );
pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_NEWDOC_HELP) );
DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
long nTemp = pEntry->GetBoundRect().GetSize().Width();
@@ -199,7 +199,7 @@ SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
aEntryStr = SVT_RESSTR(STR_SVT_TEMPLATES);
pEntry = aIconCtrl.InsertEntry(
aEntryStr, Image( SvtResId( IMG_SVT_TEMPLATES ) ), ICON_POS_TEMPLATES );
- pEntry->SetUserData( &aTemplateRootURL );
+ pEntry->SetUserData( new OUString(aTemplateRootURL) );
pEntry->SetQuickHelpText(SVT_RESSTR(STR_SVT_TEMPLATES_HELP));
DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
nTemp = pEntry->GetBoundRect().GetSize().Width();
@@ -211,7 +211,7 @@ SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
aEntryStr = SVT_RESSTR(STR_SVT_MYDOCS);
pEntry = aIconCtrl.InsertEntry(
aEntryStr, Image( SvtResId( IMG_SVT_MYDOCS ) ), ICON_POS_MYDOCS );
- pEntry->SetUserData( &aMyDocumentsRootURL );
+ pEntry->SetUserData( new OUString(aMyDocumentsRootURL) );
pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_MYDOCS_HELP) );
DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
nTemp = pEntry->GetBoundRect().GetSize().Width();
@@ -222,7 +222,7 @@ SvtIconWindow_Impl::SvtIconWindow_Impl( Window* pParent ) :
aEntryStr = SVT_RESSTR(STR_SVT_SAMPLES);
pEntry = aIconCtrl.InsertEntry(
aEntryStr, Image( SvtResId( IMG_SVT_SAMPLES ) ), ICON_POS_SAMPLES );
- pEntry->SetUserData( &aSamplesFolderRootURL );
+ pEntry->SetUserData( new OUString(aSamplesFolderRootURL) );
pEntry->SetQuickHelpText( SVT_RESSTR(STR_SVT_SAMPLES_HELP));
DBG_ASSERT( !pEntry->GetBoundRect().IsEmpty(), "empty rectangle" );
nTemp = pEntry->GetBoundRect().GetSize().Width();
@@ -247,8 +247,8 @@ SvxIconChoiceCtrlEntry* SvtIconWindow_Impl::GetEntry( const OUString& rURL ) con
for ( sal_uLong i = 0; i < aIconCtrl.GetEntryCount(); ++i )
{
SvxIconChoiceCtrlEntry* pTemp = aIconCtrl.GetEntry( i );
- OUString aURL( *( (OUString*)pTemp->GetUserData() ) );
- if ( aURL == rURL )
+ OUString *pURL = (OUString*)pTemp->GetUserData();
+ if ( (*pURL) == rURL )
{
pEntry = pTemp;
break;
More information about the Libreoffice-commits
mailing list