summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Rabi <prabi@caesar.elte.hu>2011-09-19 14:21:20 +0200
committerAndras Timar <atimar@suse.com>2011-09-22 11:50:54 +0200
commitdf59068902b294b7b344af0c20da196cc64aaced (patch)
treea61202a255bdeda1f58d325d3b2358e29f4f3ef3
parent46292bdf296a0da689f6a0fe5072916cd8414cd2 (diff)
Fix of localized template name problems in Impress part 2
Template entries now appear in the correct word order in their representation in SfxDocumentTemplates. That makes template listboxes in a few dialogs work as expected. Contributed under license LGPLv3+/MPL.
-rw-r--r--sfx2/inc/sfx2/doctempl.hxx3
-rw-r--r--sfx2/source/doc/doctdlg.cxx3
-rw-r--r--sfx2/source/doc/doctempl.cxx199
-rw-r--r--sfx2/source/doc/docvor.cxx2
-rw-r--r--sfx2/source/doc/new.cxx2
5 files changed, 135 insertions, 74 deletions
diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx
index df1d9f0c71bf..b60ac9581792 100644
--- a/sfx2/inc/sfx2/doctempl.hxx
+++ b/sfx2/inc/sfx2/doctempl.hxx
@@ -93,6 +93,9 @@ public:
int nCount,
const ::rtl::OUString& rString);
+ void EnableRegionSorting(bool isRegionSortingEnabled = true);
+ void EnableTemplateSorting(bool isTemplateSortingEnabled = true);
+
sal_Bool Copy(sal_uInt16 nTargetRegion,
sal_uInt16 nTargetIdx,
sal_uInt16 nSourceRegion,
diff --git a/sfx2/source/doc/doctdlg.cxx b/sfx2/source/doc/doctdlg.cxx
index 36cd638a39a2..d99ef9a49327 100644
--- a/sfx2/source/doc/doctdlg.cxx
+++ b/sfx2/source/doc/doctdlg.cxx
@@ -111,6 +111,9 @@ void SfxDocumentTemplateDlg::Init()
if(!pTemplates->IsConstructed())
pTemplates->Construct();
+ pTemplates->EnableRegionSorting();
+ pTemplates->EnableTemplateSorting();
+
const sal_uInt16 nCount = pTemplates->GetRegionCount();
for(sal_uInt16 i = 0; i < nCount; ++i)
aRegionLb.InsertEntry(pTemplates->GetFullRegionName(i));
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index 378d489906dc..22ed882d7b5d 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -103,6 +103,7 @@ using namespace ::ucbhelper;
#include <unotools/ucbhelper.hxx>
#include <vector>
+#include <algorithm>
using ::std::vector;
using ::std::advance;
@@ -171,6 +172,13 @@ public:
sal_Bool DeleteObjectShell();
};
+class TemplateEntryCompare
+{
+public:
+ bool operator()( DocTempl_EntryData_Impl* pA, DocTempl_EntryData_Impl* pB ) const
+ { return 0 > pA->Compare( pB->GetTitle() ); }
+};
+
}
using namespace ::DocTempl;
@@ -184,6 +192,7 @@ class RegionData_Impl
OUString maTitle;
OUString maOwnURL;
OUString maTargetURL;
+ bool mbSortingEnabled;
private:
size_t GetEntryPos( const OUString& rTitle,
@@ -214,11 +223,20 @@ public:
size_t *pPos = NULL );
void DeleteEntry( size_t nIndex );
+ void EnableSorting( bool isSortingEnabled = true );
+
int Compare( const OUString& rTitle ) const
{ return maTitle.compareTo( rTitle ); }
int Compare( RegionData_Impl* pCompareWith ) const;
};
+class RegionCompare
+{
+public:
+ bool operator()( RegionData_Impl* pA, RegionData_Impl* pB ) const
+ { return 0 > pA->Compare( pB ); }
+};
+
typedef vector< RegionData_Impl* > RegionList_Impl;
// ------------------------------------------------------------------------
@@ -230,9 +248,10 @@ class SfxDocTemplate_Impl : public SvRefBase
::osl::Mutex maMutex;
OUString maRootURL;
- OUString maStandardGroup;
RegionList_Impl maRegions;
sal_Bool mbConstructed;
+ bool mbRegionSortingEnabled;
+ bool mbTemplateSortingEnabled;
uno::Reference< XAnyCompareFactory > m_rCompareFactory;
@@ -258,6 +277,13 @@ public:
void Rescan();
+ void EnableRegionSorting( bool isRegionSortingEnabled = true );
+ void EnableTemplateSorting( bool isTemplateSortingEnabled = true )
+ { mbTemplateSortingEnabled = isTemplateSortingEnabled; }
+
+ bool IsRegionSortingEnabled() const { return mbRegionSortingEnabled; }
+ bool IsTemplateSortingEnabled() const { return mbTemplateSortingEnabled; }
+
void DeleteRegion( size_t nIndex );
size_t GetRegionCount() const
@@ -621,6 +647,28 @@ OUString SfxDocumentTemplates::ConvertResourceString (
//------------------------------------------------------------------------
+/** Enables or disables the sorting of regions.
+ @param isRegionSortingEnabled
+ Whether to sort regions or not.
+*/
+void SfxDocumentTemplates::EnableRegionSorting( bool isRegionSortingEnabled )
+{
+ pImp->EnableRegionSorting( isRegionSortingEnabled );
+}
+
+//------------------------------------------------------------------------
+
+/** Enables or disables the sorting of templates inside regions.
+ @param isTemplateSortingEnabled
+ Whether to sort templates or not.
+*/
+void SfxDocumentTemplates::EnableTemplateSorting( bool isTemplateSortingEnabled )
+{
+ pImp->EnableTemplateSorting( isTemplateSortingEnabled );
+}
+
+//------------------------------------------------------------------------
+
sal_Bool SfxDocumentTemplates::CopyOrMove
(
sal_uInt16 nTargetRegion, // Target Region Index
@@ -1109,6 +1157,7 @@ sal_Bool SfxDocumentTemplates::InsertDir
if ( xTemplates->addGroup( rText ) )
{
RegionData_Impl* pNewRegion = new RegionData_Impl( pImp, rText );
+ pNewRegion->EnableSorting( pImp->IsTemplateSortingEnabled() );
if ( ! pImp->InsertRegion( pNewRegion, nRegion ) )
{
@@ -1168,6 +1217,10 @@ sal_Bool SfxDocumentTemplates::SetName
pRegion->SetTitle( rName );
pRegion->SetTargetURL( aEmpty );
pRegion->SetHierarchyURL( aEmpty );
+
+ // force resorting if needed
+ pImp->EnableRegionSorting( pImp->IsRegionSortingEnabled() );
+
return sal_True;
}
}
@@ -1188,6 +1241,10 @@ sal_Bool SfxDocumentTemplates::SetName
pEntry->SetTitle( rName );
pEntry->SetTargetURL( aEmpty );
pEntry->SetHierarchyURL( aEmpty );
+
+ // force resorting if needed
+ pRegion->EnableSorting( pImp->IsTemplateSortingEnabled() );
+
return sal_True;
}
}
@@ -1707,8 +1764,9 @@ const OUString& DocTempl_EntryData_Impl::GetTargetURL()
RegionData_Impl::RegionData_Impl( const SfxDocTemplate_Impl* pParent,
const OUString& rTitle )
{
- maTitle = rTitle;
- mpParent = pParent;
+ maTitle = rTitle;
+ mpParent = pParent;
+ mbSortingEnabled = false;
}
// -----------------------------------------------------------------------
@@ -1722,62 +1780,37 @@ RegionData_Impl::~RegionData_Impl()
// -----------------------------------------------------------------------
size_t RegionData_Impl::GetEntryPos( const OUString& rTitle, sal_Bool& rFound ) const
{
-#if 1 // Don't use binary search today
- size_t i;
- size_t nCount = maEntries.size();
-
- for ( i=0; i<nCount; i++ )
+ if ( mbSortingEnabled )
{
- DocTempl_EntryData_Impl *pData = maEntries[ i ];
+ DocTempl_EntryData_Impl aToFind( NULL, rTitle );
+ vector< DocTempl_EntryData_Impl* >::const_iterator aPlaceToInsert =
+ ::std::lower_bound( maEntries.begin(), maEntries.end(),
+ &aToFind, TemplateEntryCompare() );
- if ( pData->Compare( rTitle ) == 0 )
- {
- rFound = sal_True;
- return i;
- }
- }
-
- rFound = sal_False;
- return i;
-
-#else
- // use binary search to find the correct position
- // in the maEntries list
-
- int nCompVal = 1;
- size_t nStart = 0;
- size_t nEnd = maEntries.size() - 1;
- size_t nMid;
+ rFound = aPlaceToInsert != maEntries.end() &&
+ 0 == (*aPlaceToInsert)->Compare( rTitle );
- DocTempl_EntryData_Impl* pMid;
-
- rFound = sal_False;
-
- while ( nCompVal && ( nStart <= nEnd ) )
+ return ::std::distance( maEntries.begin(), aPlaceToInsert );
+ }
+ else
{
- nMid = ( nEnd - nStart ) / 2 + nStart;
- pMid = maEntries[ nMid ];
+ size_t i;
+ size_t nCount = maEntries.size();
- nCompVal = pMid->Compare( rTitle );
+ for ( i=0; i<nCount; i++ )
+ {
+ DocTempl_EntryData_Impl *pData = maEntries[ i ];
- if ( nCompVal < 0 ) // pMid < pData
- nStart = nMid + 1;
- else
- nEnd = nMid - 1;
- }
+ if ( pData->Compare( rTitle ) == 0 )
+ {
+ rFound = sal_True;
+ return i;
+ }
+ }
- if ( nCompVal == 0 )
- {
- rFound = sal_True;
- }
- else
- {
- if ( nCompVal < 0 ) // pMid < pData
- nMid++;
+ rFound = sal_False;
+ return i;
}
-
- return nMid;
-#endif
}
// -----------------------------------------------------------------------
@@ -1791,23 +1824,20 @@ void RegionData_Impl::AddEntry( const OUString& rTitle,
INetURLObject::ENCODE_ALL );
OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
- DocTempl_EntryData_Impl* pEntry;
sal_Bool bFound = sal_False;
size_t nPos = GetEntryPos( rTitle, bFound );
- if ( bFound )
+ if ( !bFound )
{
- pEntry = maEntries[ nPos ];
- }
- else
- {
- if ( pPos )
+ if ( !mbSortingEnabled && pPos )
nPos = *pPos;
- pEntry = new DocTempl_EntryData_Impl( this, rTitle );
+ DocTempl_EntryData_Impl* pEntry = new DocTempl_EntryData_Impl( this, rTitle );
pEntry->SetTargetURL( rTargetURL );
pEntry->SetHierarchyURL( aLinkURL );
- if ( nPos < maEntries.size() ) {
+
+ if ( nPos < maEntries.size() )
+ {
vector< DocTempl_EntryData_Impl* >::iterator it = maEntries.begin();
advance( it, nPos );
maEntries.insert( it, pEntry );
@@ -1899,6 +1929,15 @@ void RegionData_Impl::DeleteEntry( size_t nIndex )
}
// -----------------------------------------------------------------------
+void RegionData_Impl::EnableSorting( bool isSortingEnabled )
+{
+ mbSortingEnabled = isSortingEnabled;
+
+ if ( mbSortingEnabled )
+ ::std::sort( maEntries.begin(), maEntries.end(), TemplateEntryCompare() );
+}
+
+// -----------------------------------------------------------------------
int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
{
int nCompare = maTitle.compareTo( pCompare->maTitle );
@@ -1910,6 +1949,8 @@ int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
SfxDocTemplate_Impl::SfxDocTemplate_Impl()
: mbConstructed( sal_False )
+, mbRegionSortingEnabled( false )
+, mbTemplateSortingEnabled( false )
, mnLockCounter( 0 )
{
}
@@ -1978,6 +2019,7 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
{
RegionData_Impl* pRegion;
pRegion = new RegionData_Impl( this, rTitle );
+ pRegion->EnableSorting( mbTemplateSortingEnabled );
if ( ! InsertRegion( pRegion ) )
{
@@ -2100,11 +2142,6 @@ sal_Bool SfxDocTemplate_Impl::Construct( )
mbConstructed = sal_True;
maRootURL = aRootContent->getIdentifier()->getContentIdentifier();
- ResStringArray aLongNames( SfxResId( TEMPLATE_LONG_NAMES_ARY ) );
-
- if ( aLongNames.Count() )
- maStandardGroup = aLongNames.GetString( 0 );
-
Content aTemplRoot( aRootContent, aCmdEnv );
CreateFromHierarchy( aTemplRoot );
@@ -2135,18 +2172,23 @@ sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew, size_t nPos )
if ( maRegions[ i ]->Compare( pNew ) == 0 )
return sal_False;
- size_t newPos = nPos;
- if ( pNew->GetTitle() == maStandardGroup )
- newPos = 0;
-
- if ( newPos < maRegions.size() )
+ if ( mbRegionSortingEnabled )
{
- RegionList_Impl::iterator it = maRegions.begin();
- advance( it, newPos );
- maRegions.insert( it, pNew );
+ RegionList_Impl::iterator aPlaceToInsert =
+ ::std::upper_bound( maRegions.begin(), maRegions.end(), pNew, RegionCompare() );
+ maRegions.insert( aPlaceToInsert, pNew );
}
else
- maRegions.push_back( pNew );
+ {
+ if ( nPos < maRegions.size() )
+ {
+ RegionList_Impl::iterator it = maRegions.begin();
+ advance( it, nPos );
+ maRegions.insert( it, pNew );
+ }
+ else
+ maRegions.push_back( pNew );
+ }
return sal_True;
}
@@ -2178,6 +2220,15 @@ void SfxDocTemplate_Impl::Rescan()
}
// -----------------------------------------------------------------------
+void SfxDocTemplate_Impl::EnableRegionSorting( bool isRegionSortingEnabled )
+{
+ mbRegionSortingEnabled = isRegionSortingEnabled;
+
+ if ( mbRegionSortingEnabled )
+ ::std::sort( maRegions.begin(), maRegions.end(), RegionCompare() );
+}
+
+// -----------------------------------------------------------------------
sal_Bool SfxDocTemplate_Impl::GetTitleFromURL( const OUString& rURL,
OUString& aTitle )
{
diff --git a/sfx2/source/doc/docvor.cxx b/sfx2/source/doc/docvor.cxx
index 9ac8ba767468..0f9609f1c420 100644
--- a/sfx2/source/doc/docvor.cxx
+++ b/sfx2/source/doc/docvor.cxx
@@ -234,6 +234,8 @@ SfxOrganizeDlg_Impl::SfxOrganizeDlg_Impl( SfxTemplateOrganizeDlg* pParent,
pWaitObjectRange = pDialog;
WaitObject aWaitCursor( pWaitObjectRange );
+ const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->EnableRegionSorting();
+ const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->EnableTemplateSorting();
const_cast< SfxDocumentTemplates* >( aMgr.GetTemplates() )->Update( sal_True /* be smart */ );
// this const_cast is a hack - but the alternative would be to
// * have a method which returns the templates non-const
diff --git a/sfx2/source/doc/new.cxx b/sfx2/source/doc/new.cxx
index cc7c0040f328..95f6f6db9753 100644
--- a/sfx2/source/doc/new.cxx
+++ b/sfx2/source/doc/new.cxx
@@ -567,6 +567,8 @@ SfxNewFileDialog_Impl::SfxNewFileDialog_Impl(
// update the template configuration if necessary
{
WaitObject aWaitCursor( pAntiImplP->GetParent() );
+ aTemplates.EnableRegionSorting();
+ aTemplates.EnableTemplateSorting();
aTemplates.Update( sal_True /* be smart */ );
}
// fill the list boxes