summaryrefslogtreecommitdiff
path: root/sfx2/source/doc/doctempl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sfx2/source/doc/doctempl.cxx')
-rw-r--r--sfx2/source/doc/doctempl.cxx244
1 files changed, 111 insertions, 133 deletions
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index f92eabd321..8ffc459e12 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -30,12 +31,10 @@
#include <limits.h>
#include <com/sun/star/uno/Any.h>
-#include <vos/mutex.hxx>
-#include <vos/thread.hxx>
+#include <osl/mutex.hxx>
+#include <osl/thread.hxx>
-#ifndef _SV_RESARY_HXX
#include <tools/resary.hxx>
-#endif
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <unotools/localedatawrapper.hxx>
@@ -102,6 +101,10 @@ using namespace ::ucbhelper;
#include <comphelper/storagehelper.hxx>
#include <unotools/ucbhelper.hxx>
+#include <vector>
+using ::std::vector;
+using ::std::advance;
+
//========================================================================
// #define DONT_USE_HIERARCHY
@@ -122,8 +125,6 @@ using namespace ::ucbhelper;
#define SERVICENAME_TYPEDETECTION "com.sun.star.document.TypeDetection"
#define TYPEDETECTION_PARAMETER "FileName"
-//#define SERVICENAME_OLD_TYPEDETECTION "com.sun.star.frame.FrameLoaderFactory"
-//#define PARAMETER_OLD_TYPEDETECTION "DeepDetection"
#define SERVICENAME_DOCINFO "com.sun.star.document.DocumentProperties"
#define SERVICENAME_DOCTEMPLATES "com.sun.star.frame.DocumentTemplates"
#define SERVICENAME_DESKTOP "com.sun.star.frame.Desktop"
@@ -177,15 +178,14 @@ using namespace ::DocTempl;
class RegionData_Impl
{
- DECLARE_LIST( EntryList_Impl, DocTempl_EntryData_Impl* )
const SfxDocTemplate_Impl* mpParent;
- EntryList_Impl maEntries;
+ vector< DocTempl_EntryData_Impl* > maEntries;
OUString maTitle;
OUString maOwnURL;
OUString maTargetURL;
private:
- long GetEntryPos( const OUString& rTitle,
+ size_t GetEntryPos( const OUString& rTitle,
sal_Bool& rFound ) const;
const SfxDocTemplate_Impl* GetParent() const { return mpParent; }
@@ -197,7 +197,7 @@ public:
void SetTargetURL( const OUString& rURL ) { maTargetURL = rURL; }
void SetHierarchyURL( const OUString& rURL) { maOwnURL = rURL; }
- DocTempl_EntryData_Impl* GetEntry( ULONG nIndex ) const;
+ DocTempl_EntryData_Impl* GetEntry( size_t nIndex ) const;
DocTempl_EntryData_Impl* GetEntry( const OUString& rName ) const;
DocTempl_EntryData_Impl* GetByTargetURL( const OUString& rName ) const;
@@ -205,21 +205,21 @@ public:
const OUString& GetTargetURL();
const OUString& GetHierarchyURL();
- ULONG GetCount() const;
+ size_t GetCount() const;
void SetTitle( const OUString& rTitle ) { maTitle = rTitle; }
void AddEntry( const OUString& rTitle,
const OUString& rTargetURL,
- USHORT *pPos = NULL );
- void DeleteEntry( ULONG nIndex );
+ size_t *pPos = NULL );
+ void DeleteEntry( size_t nIndex );
int Compare( const OUString& rTitle ) const
{ return maTitle.compareTo( rTitle ); }
int Compare( RegionData_Impl* pCompareWith ) const;
};
-DECLARE_LIST( RegionList_Impl, RegionData_Impl* )
+typedef vector< RegionData_Impl* > RegionList_Impl;
// ------------------------------------------------------------------------
@@ -258,21 +258,20 @@ public:
void Rescan();
- void DeleteRegion( ULONG nIndex );
+ void DeleteRegion( size_t nIndex );
- ULONG GetRegionCount() const
- { return maRegions.Count(); }
+ size_t GetRegionCount() const
+ { return maRegions.size(); }
RegionData_Impl* GetRegion( const OUString& rName ) const;
- RegionData_Impl* GetRegion( ULONG nIndex ) const;
+ RegionData_Impl* GetRegion( size_t nIndex ) const;
void GetTemplates( Content& rTargetFolder,
Content& rParentFolder,
RegionData_Impl* pRegion );
- long GetRegionPos( const OUString& rTitle,
- sal_Bool& rFound ) const;
+ size_t GetRegionPos( const OUString& rTitle, sal_Bool& rFound ) const;
sal_Bool GetTitleFromURL( const OUString& rURL, OUString& aTitle );
- sal_Bool InsertRegion( RegionData_Impl *pData, ULONG nPos = LIST_APPEND );
+ sal_Bool InsertRegion( RegionData_Impl *pData, size_t nPos = size_t(-1) );
OUString GetRootURL() const { return maRootURL; }
uno::Reference< XDocumentTemplates > getDocTemplates() { return mxTemplates; }
@@ -416,7 +415,7 @@ USHORT SfxDocumentTemplates::GetRegionNo
return USHRT_MAX;
sal_Bool bFound;
- ULONG nIndex = pImp->GetRegionPos( rRegion, bFound );
+ size_t nIndex = pImp->GetRegionPos( rRegion, bFound );
if ( bFound )
return (USHORT) nIndex;
@@ -937,21 +936,6 @@ sal_Bool SfxDocumentTemplates::CopyOrMove
{
DBG_ERRORFILE( "Don't know, what to do!" );
return sal_False;
-#if 0
- // Verschieben einer Vorlage innerhalb eines Bereiches
- // --> nur Verwaltungsdaten aktualisieren
- if ( bMove && nTargetRegion == nSourceRegion )
- {
- if(nTargetIdx == USHRT_MAX)
- nTargetIdx = 0;
- const SfxTemplateDirEntryPtr pEntry = rTargetDir[nSourceIdx];
- rTargetDir.Insert(pEntry, nTargetIdx);
- if(nTargetIdx < nSourceIdx)
- ++nSourceIdx;
- rTargetDir.Remove(nSourceIdx);
- return SaveDir(rTargetDir);
- }
-#endif
}
RegionData_Impl *pSourceRgn = pImp->GetRegion( nSourceRegion );
@@ -999,7 +983,9 @@ sal_Bool SfxDocumentTemplates::CopyOrMove
}
}
- pTargetRgn->AddEntry( aTitle, aNewTargetURL, &nTargetIdx );
+ // todo: fix SfxDocumentTemplates to handle size_t instead of USHORT
+ size_t temp_nTargetIdx = nTargetIdx;
+ pTargetRgn->AddEntry( aTitle, aNewTargetURL, &temp_nTargetIdx );
return sal_True;
}
@@ -1220,7 +1206,7 @@ sal_Bool SfxDocumentTemplates::CopyFrom
UNO_QUERY );
Sequence< PropertyValue > aArgs( 1 );
- aArgs[0].Name = ::rtl::OUString::createFromAscii("Hidden");
+ aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
aArgs[0].Value <<= sal_True;
INetURLObject aTemplURL( rName );
@@ -1230,7 +1216,7 @@ sal_Bool SfxDocumentTemplates::CopyFrom
{
xStorable = uno::Reference< XStorable >(
xDesktop->loadComponentFromURL( aTemplURL.GetMainURL(INetURLObject::NO_DECODE),
- OUString::createFromAscii( "_blank" ),
+ OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")),
0,
aArgs ),
UNO_QUERY );
@@ -1291,7 +1277,9 @@ sal_Bool SfxDocumentTemplates::CopyFrom
else
nIdx += 1;
- pTargetRgn->AddEntry( aTitle, aTemplName, &nIdx );
+ // todo: fix SfxDocumentTemplates to handle size_t instead of USHORT
+ size_t temp_nIdx = nIdx;
+ pTargetRgn->AddEntry( aTitle, aTemplName, &temp_nIdx );
rName = aTitle;
return sal_True;
}
@@ -2058,26 +2046,21 @@ RegionData_Impl::RegionData_Impl( const SfxDocTemplate_Impl* pParent,
// -----------------------------------------------------------------------
RegionData_Impl::~RegionData_Impl()
{
- DocTempl_EntryData_Impl *pData = maEntries.First();
-
- while ( pData )
- {
- delete pData;
- pData = maEntries.Next();
- }
+ for ( size_t i = 0, n = maEntries.size(); i < n; ++i )
+ delete maEntries[ i ];
+ maEntries.clear();
}
// -----------------------------------------------------------------------
-long RegionData_Impl::GetEntryPos( const OUString& rTitle,
- sal_Bool& rFound ) const
+size_t RegionData_Impl::GetEntryPos( const OUString& rTitle, sal_Bool& rFound ) const
{
#if 1 // Don't use binary search today
- ULONG i;
- ULONG nCount = maEntries.Count();
+ size_t i;
+ size_t nCount = maEntries.size();
for ( i=0; i<nCount; i++ )
{
- DocTempl_EntryData_Impl *pData = maEntries.GetObject( i );
+ DocTempl_EntryData_Impl *pData = maEntries[ i ];
if ( pData->Compare( rTitle ) == 0 )
{
@@ -2094,9 +2077,9 @@ long RegionData_Impl::GetEntryPos( const OUString& rTitle,
// in the maEntries list
int nCompVal = 1;
- long nStart = 0;
- long nEnd = maEntries.Count() - 1;
- long nMid;
+ size_t nStart = 0;
+ size_t nEnd = maEntries.size() - 1;
+ size_t nMid;
DocTempl_EntryData_Impl* pMid;
@@ -2105,7 +2088,7 @@ long RegionData_Impl::GetEntryPos( const OUString& rTitle,
while ( nCompVal && ( nStart <= nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart;
- pMid = maEntries.GetObject( nMid );
+ pMid = maEntries[ nMid ];
nCompVal = pMid->Compare( rTitle );
@@ -2132,7 +2115,7 @@ long RegionData_Impl::GetEntryPos( const OUString& rTitle,
// -----------------------------------------------------------------------
void RegionData_Impl::AddEntry( const OUString& rTitle,
const OUString& rTargetURL,
- USHORT *pPos )
+ size_t *pPos )
{
INetURLObject aLinkObj( GetHierarchyURL() );
aLinkObj.insertName( rTitle, false,
@@ -2140,13 +2123,13 @@ void RegionData_Impl::AddEntry( const OUString& rTitle,
INetURLObject::ENCODE_ALL );
OUString aLinkURL = aLinkObj.GetMainURL( INetURLObject::NO_DECODE );
- DocTempl_EntryData_Impl *pEntry;
+ DocTempl_EntryData_Impl* pEntry;
sal_Bool bFound = sal_False;
- long nPos = GetEntryPos( rTitle, bFound );
+ size_t nPos = GetEntryPos( rTitle, bFound );
if ( bFound )
{
- pEntry = maEntries.GetObject( nPos );
+ pEntry = maEntries[ nPos ];
}
else
{
@@ -2156,14 +2139,20 @@ void RegionData_Impl::AddEntry( const OUString& rTitle,
pEntry = new DocTempl_EntryData_Impl( this, rTitle );
pEntry->SetTargetURL( rTargetURL );
pEntry->SetHierarchyURL( aLinkURL );
- maEntries.Insert( pEntry, nPos );
+ if ( nPos < maEntries.size() ) {
+ vector< DocTempl_EntryData_Impl* >::iterator it = maEntries.begin();
+ advance( it, nPos );
+ maEntries.insert( it, pEntry );
+ }
+ else
+ maEntries.push_back( pEntry );
}
}
// -----------------------------------------------------------------------
-ULONG RegionData_Impl::GetCount() const
+size_t RegionData_Impl::GetCount() const
{
- return maEntries.Count();
+ return maEntries.size();
}
// -----------------------------------------------------------------------
@@ -2197,9 +2186,8 @@ const OUString& RegionData_Impl::GetTargetURL()
OUString aPropName( RTL_CONSTASCII_USTRINGPARAM( TARGET_DIR_URL ) );
getTextProperty_Impl( aRegion, aPropName, maTargetURL );
- // --> PB 2004-10-27 #i32656# - the targeturl must be substituted: $(baseinsturl)
+ // The targeturl must be substituted: $(baseinsturl) (#i32656#)
maTargetURL = SvtPathOptions().SubstituteVariable( maTargetURL );
- // <--
}
else
{
@@ -2217,7 +2205,7 @@ DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( const OUString& rName ) cons
long nPos = GetEntryPos( rName, bFound );
if ( bFound )
- return maEntries.GetObject( nPos );
+ return maEntries[ nPos ];
else
return NULL;
}
@@ -2225,35 +2213,32 @@ DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( const OUString& rName ) cons
// -----------------------------------------------------------------------
DocTempl_EntryData_Impl* RegionData_Impl::GetByTargetURL( const OUString& rName ) const
{
- DocTempl_EntryData_Impl *pEntry;
-
- ULONG nCount = maEntries.Count();
-
- for ( ULONG i=0; i<nCount; i++ )
+ for ( size_t i = 0, n = maEntries.size(); i < n; ++i )
{
- pEntry = maEntries.GetObject( i );
- if ( pEntry && ( pEntry->GetTargetURL() == rName ) )
+ DocTempl_EntryData_Impl *pEntry = maEntries[ i ];
+ if ( pEntry->GetTargetURL() == rName )
return pEntry;
}
-
return NULL;
}
// -----------------------------------------------------------------------
-DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( ULONG nIndex ) const
+DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( size_t nIndex ) const
{
- return maEntries.GetObject( nIndex );
+ if ( nIndex < maEntries.size() )
+ return maEntries[ nIndex ];
+ return NULL;
}
// -----------------------------------------------------------------------
-void RegionData_Impl::DeleteEntry( ULONG nIndex )
+void RegionData_Impl::DeleteEntry( size_t nIndex )
{
- DocTempl_EntryData_Impl *pEntry = maEntries.GetObject( nIndex );
-
- if ( pEntry )
+ if ( nIndex < maEntries.size() )
{
- delete pEntry;
- maEntries.Remove( (ULONG) nIndex );
+ delete maEntries[ nIndex ];
+ vector< DocTempl_EntryData_Impl*>::iterator it = maEntries.begin();
+ advance( it, nIndex );
+ maEntries.erase( it );
}
}
@@ -2299,38 +2284,35 @@ void SfxDocTemplate_Impl::DecrementLock()
}
// -----------------------------------------------------------------------
-RegionData_Impl* SfxDocTemplate_Impl::GetRegion( ULONG nIndex ) const
+RegionData_Impl* SfxDocTemplate_Impl::GetRegion( size_t nIndex ) const
{
- return maRegions.GetObject( nIndex );
+ if ( nIndex < maRegions.size() )
+ return maRegions[ nIndex ];
+ return NULL;
}
// -----------------------------------------------------------------------
RegionData_Impl* SfxDocTemplate_Impl::GetRegion( const OUString& rName )
const
{
- ULONG nCount = maRegions.Count();
- RegionData_Impl *pData;
-
- for ( ULONG i=0; i<nCount; i++ )
+ for ( size_t i = 0, n = maRegions.size(); i < n; ++i )
{
- pData = maRegions.GetObject( i );
-
- if ( pData->GetTitle() == rName )
+ RegionData_Impl* pData = maRegions[ i ];
+ if( pData->GetTitle() == rName )
return pData;
}
-
return NULL;
}
// -----------------------------------------------------------------------
-void SfxDocTemplate_Impl::DeleteRegion( ULONG nIndex )
+void SfxDocTemplate_Impl::DeleteRegion( size_t nIndex )
{
- RegionData_Impl* pRegion = maRegions.GetObject( nIndex );
-
- if ( pRegion )
+ if ( nIndex < maRegions.size() )
{
- delete pRegion;
- maRegions.Remove( (ULONG) nIndex );
+ delete maRegions[ nIndex ];
+ RegionList_Impl::iterator it = maRegions.begin();
+ advance( it, nIndex );
+ maRegions.erase( it );
}
}
@@ -2352,8 +2334,8 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
// now get the content of the region
uno::Reference< XResultSet > xResultSet;
Sequence< OUString > aProps(2);
- aProps[0] = OUString::createFromAscii( TITLE );
- aProps[1] = OUString::createFromAscii( TARGET_URL );
+ aProps[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( TITLE ));
+ aProps[1] = OUString(RTL_CONSTASCII_USTRINGPARAM( TARGET_URL ));
try
{
@@ -2389,7 +2371,7 @@ void SfxDocTemplate_Impl::CreateFromHierarchy( Content &rTemplRoot )
{
uno::Reference< XResultSet > xResultSet;
Sequence< OUString > aProps(1);
- aProps[0] = OUString::createFromAscii( TITLE );
+ aProps[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( TITLE ));
try
{
@@ -2451,7 +2433,7 @@ sal_Bool SfxDocTemplate_Impl::Construct( )
Sequence< Any > aCompareArg(1);
*(aCompareArg.getArray()) <<= xLocalizable->getLocale();;
m_rCompareFactory = uno::Reference< XAnyCompareFactory >(
- xFactory->createInstanceWithArguments( OUString::createFromAscii( "com.sun.star.ucb.AnyCompareFactory" ),
+ xFactory->createInstanceWithArguments( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.AnyCompareFactory")),
aCompareArg ),
UNO_QUERY );
@@ -2497,7 +2479,7 @@ void SfxDocTemplate_Impl::GetTemplates( Content& rTargetFolder,
uno::Reference< XResultSet > xResultSet;
Sequence< OUString > aProps(1);
- aProps[0] = OUString::createFromAscii( TITLE );
+ aProps[0] = OUString(RTL_CONSTASCII_USTRINGPARAM( TITLE ));
try
{
@@ -2549,20 +2531,19 @@ void SfxDocTemplate_Impl::GetTemplates( Content& rTargetFolder,
// -----------------------------------------------------------------------
-long SfxDocTemplate_Impl::GetRegionPos( const OUString& rTitle,
- sal_Bool& rFound ) const
+size_t SfxDocTemplate_Impl::GetRegionPos( const OUString& rTitle, sal_Bool& rFound ) const
{
int nCompVal = 1;
- long nStart = 0;
- long nEnd = maRegions.Count() - 1;
- long nMid = 0;
+ size_t nStart = 0;
+ size_t nEnd = maRegions.size() - 1;
+ size_t nMid = 0;
RegionData_Impl* pMid;
while ( nCompVal && ( nStart <= nEnd ) )
{
nMid = ( nEnd - nStart ) / 2 + nStart;
- pMid = maRegions.GetObject( nMid );
+ pMid = maRegions[ nMid ];
nCompVal = pMid->Compare( rTitle );
@@ -2586,27 +2567,29 @@ long SfxDocTemplate_Impl::GetRegionPos( const OUString& rTitle,
}
// -----------------------------------------------------------------------
-sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew,
- ULONG nPos )
+sal_Bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew, size_t nPos )
{
::osl::MutexGuard aGuard( maMutex );
- RegionData_Impl *pData = maRegions.First();
- while ( pData && ( pData->Compare( pNew ) != 0 ) )
- pData = maRegions.Next();
+ // return false (not inserted) if the entry already exists
+ for ( size_t i = 0, n = maRegions.size(); i < n; ++i )
+ if ( maRegions[ i ]->Compare( pNew ) == 0 )
+ return sal_False;
- if ( ! pData )
- {
- // compare with the name of the standard group here to insert it
- // first
+ size_t newPos = nPos;
+ if ( pNew->GetTitle() == maStandardGroup )
+ newPos = 0;
- if ( pNew->GetTitle() == maStandardGroup )
- maRegions.Insert( pNew, (ULONG) 0 );
- else
- maRegions.Insert( pNew, nPos );
+ if ( newPos < maRegions.size() )
+ {
+ RegionList_Impl::iterator it = maRegions.begin();
+ advance( it, newPos );
+ maRegions.insert( it, pNew );
}
+ else
+ maRegions.push_back( pNew );
- return ( pData == NULL );
+ return sal_True;
}
// -----------------------------------------------------------------------
@@ -2686,15 +2669,9 @@ void SfxDocTemplate_Impl::Clear()
if ( mnLockCounter )
return;
- RegionData_Impl *pRegData = maRegions.First();
-
- while ( pRegData )
- {
- delete pRegData;
- pRegData = maRegions.Next();
- }
-
- maRegions.Clear();
+ for ( size_t i = 0, n = maRegions.size(); i < n; ++i )
+ delete maRegions[ i ];
+ maRegions.clear();
}
// -----------------------------------------------------------------------
@@ -2737,3 +2714,4 @@ sal_Bool getTextProperty_Impl( Content& rContent,
return bGotProperty;
}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */