summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/app/inputwin.cxx15
-rw-r--r--sc/source/ui/dbgui/pvlaydlg.cxx13
-rw-r--r--sc/source/ui/docshell/dbdocfun.cxx19
-rw-r--r--sc/source/ui/docshell/docfunc.cxx9
-rw-r--r--sc/source/ui/docshell/externalrefmgr.cxx76
-rw-r--r--sc/source/ui/inc/dbdocfun.hxx2
-rw-r--r--sc/source/ui/inc/undoblk.hxx4
-rw-r--r--sc/source/ui/undo/undoblk3.cxx50
-rw-r--r--sc/source/ui/unoobj/datauno.cxx117
-rw-r--r--sc/source/ui/unoobj/docuno.cxx5
-rw-r--r--sc/source/ui/vba/excelvbahelper.cxx43
-rw-r--r--sc/source/ui/vba/excelvbahelper.hxx4
-rw-r--r--sc/source/ui/vba/vbarange.cxx29
-rw-r--r--sc/source/ui/view/viewfunc.cxx9
14 files changed, 269 insertions, 126 deletions
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index c03799aa6ffe..8cb3d6e136e8 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1533,7 +1533,7 @@ ScNameInputType lcl_GetInputType( const String& rText )
sal_Int32 nNumeric;
if ( aRange.Parse( rText, pDoc, eConv ) & SCA_VALID )
- eRet = SC_NAME_INPUT_NAMEDRANGE;
+ eRet = SC_NAME_INPUT_RANGE;
else if ( aAddress.Parse( rText, pDoc, eConv ) & SCA_VALID )
eRet = SC_NAME_INPUT_CELL;
else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_NAMES, eConv ) )
@@ -1697,11 +1697,14 @@ void ScPosWnd::DoEnter()
else
{
// for all selection types, excecute the SID_CURRENTCELL slot.
- // Note that SID_CURRENTCELL always expects address to be
- // in Calc A1 format. Convert the text.
- ScRange aRange;
- aRange.ParseAny(aText, pDoc, pDoc->GetAddressConvention());
- aRange.Format(aText, SCR_ABS_3D, pDoc, ::formula::FormulaGrammar::CONV_OOO);
+ if (eType == SC_NAME_INPUT_CELL || eType == SC_NAME_INPUT_RANGE)
+ {
+ // Note that SID_CURRENTCELL always expects address to
+ // be in Calc A1 format. Convert the text.
+ ScRange aRange;
+ aRange.ParseAny(aText, pDoc, pDoc->GetAddressConvention());
+ aRange.Format(aText, SCR_ABS_3D, pDoc, ::formula::FormulaGrammar::CONV_OOO);
+ }
SfxStringItem aPosItem( SID_CURRENTCELL, aText );
SfxBoolItem aUnmarkItem( FN_PARAM_1, sal_True ); // remove existing selection
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index f280af43f7e0..fa063bcf7ab8 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -1450,11 +1450,24 @@ void ScDPLayoutDlg::UpdateSrcRange()
switch (eSrcType)
{
case SRC_REF:
+ {
// data source is a range reference.
if (inSheet.GetSourceRange() == aNewRange)
// new range is identical to the current range. Nothing to do.
return;
inSheet.SetSourceRange(aNewRange);
+ sal_uLong nError = inSheet.CheckSourceRange();
+ if (nError)
+ {
+ // The error number corresponds with string ID for the error
+ // message. In the future we should display the error message
+ // somewhere in the dialog to let the user know of the reason
+ // for error.
+ aEdInPos.SetRefValid(false);
+ aBtnOk.Disable();
+ return;
+ }
+ }
break;
case SRC_NAME:
// data source is a range name.
diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx
index 8991706293a1..8fde7e29e57a 100644
--- a/sc/source/ui/docshell/dbdocfun.cxx
+++ b/sc/source/ui/docshell/dbdocfun.cxx
@@ -255,7 +255,7 @@ sal_Bool ScDBDocFunc::ModifyDBData( const ScDBData& rNewData, sal_Bool /* bApi *
// -----------------------------------------------------------------
-sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi )
+sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi, bool bIsUnnamed, SCTAB aTab )
{
//! auch fuer ScDBFunc::RepeatDB benutzen!
@@ -263,12 +263,21 @@ sal_Bool ScDBDocFunc::RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Boo
ScDocument* pDoc = rDocShell.GetDocument();
if (bRecord && !pDoc->IsUndoEnabled())
bRecord = false;
- ScDBCollection* pColl = pDoc->GetDBCollection();
- sal_uInt16 nIndex;
- if ( pColl && pColl->SearchName( rDBName, nIndex ) )
+ ScDBData* pDBData = NULL;
+ if (bIsUnnamed)
{
- ScDBData* pDBData = (*pColl)[nIndex];
+ pDBData = pDoc->GetAnonymousDBData( aTab );
+ }
+ else
+ {
+ sal_uInt16 nIndex;
+ ScDBCollection* pColl = pDoc->GetDBCollection();
+ if ( pColl && pColl->SearchName( rDBName, nIndex ) )
+ pDBData = (*pColl)[nIndex];
+ }
+ if ( pDBData )
+ {
ScQueryParam aQueryParam;
pDBData->GetQueryParam( aQueryParam );
sal_Bool bQuery = aQueryParam.GetEntry(0).bDoQuery;
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index c9d600f34d9c..62ced922b01f 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4023,8 +4023,7 @@ sal_Bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMar
{
rDocShell.GetUndoManager()->AddUndoAction(
new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, pUndoDoc, aMark,
- eDir, FILL_SIMPLE, FILL_DAY, MAXDOUBLE, 1.0, 1e307,
- pDoc->GetRangeName()->GetSharedMaxIndex()+1 ) );
+ eDir, FILL_SIMPLE, FILL_DAY, MAXDOUBLE, 1.0, 1e307) );
}
rDocShell.PostPaintGridAll();
@@ -4143,8 +4142,7 @@ sal_Bool ScDocFunc::FillSeries( const ScRange& rRange, const ScMarkData* pTabMar
{
rDocShell.GetUndoManager()->AddUndoAction(
new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, pUndoDoc, aMark,
- eDir, eCmd, eDateCmd, fStart, fStep, fMax,
- pDoc->GetRangeName()->GetSharedMaxIndex()+1 ) );
+ eDir, eCmd, eDateCmd, fStart, fStep, fMax) );
}
bSuccess = sal_True;
@@ -4271,8 +4269,7 @@ sal_Bool ScDocFunc::FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillD
{
rDocShell.GetUndoManager()->AddUndoAction(
new ScUndoAutoFill( &rDocShell, aDestArea, aSourceArea, pUndoDoc, aMark,
- eDir, eCmd, eDateCmd, MAXDOUBLE, fStep, fMax,
- pDoc->GetRangeName()->GetSharedMaxIndex()+1 ) );
+ eDir, eCmd, eDateCmd, MAXDOUBLE, fStep, fMax) );
}
rDocShell.PostPaintGridAll();
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index f9de3e8c0c48..1bfdc8b5b88f 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -74,6 +74,7 @@ using ::rtl::OUString;
using ::std::vector;
using ::std::find;
using ::std::find_if;
+using ::std::remove_if;
using ::std::distance;
using ::std::pair;
using ::std::list;
@@ -85,7 +86,7 @@ using namespace formula;
namespace {
-class TabNameSearchPredicate : public unary_function<bool, ScExternalRefCache::TableName>
+class TabNameSearchPredicate : public unary_function<ScExternalRefCache::TableName, bool>
{
public:
explicit TabNameSearchPredicate(const String& rSearchName) :
@@ -201,6 +202,56 @@ private:
ScDocument* mpDoc;
};
+/**
+ * Check whether a named range contains an external reference to a
+ * particular document.
+ */
+bool hasRefsToSrcDoc(ScRangeData& rData, sal_uInt16 nFileId)
+{
+ ScTokenArray* pArray = rData.GetCode();
+ if (!pArray)
+ return false;
+
+ pArray->Reset();
+ ScToken* p = static_cast<ScToken*>(pArray->GetNextReference());
+ for (; p; p = static_cast<ScToken*>(pArray->GetNextReference()))
+ {
+ if (!p->IsExternalRef())
+ continue;
+
+ if (p->GetIndex() == nFileId)
+ return true;
+ }
+ return false;
+}
+
+class EraseRangeByIterator : unary_function<ScRangeName::iterator, void>
+{
+ ScRangeName& mrRanges;
+public:
+ EraseRangeByIterator(ScRangeName& rRanges) : mrRanges(rRanges) {}
+ void operator() (const ScRangeName::iterator& itr)
+ {
+ mrRanges.erase(itr);
+ }
+};
+
+/**
+ * Remove all named ranges that contain references to specified source
+ * document.
+ */
+void removeRangeNamesBySrcDoc(ScRangeName& rRanges, sal_uInt16 nFileId)
+{
+ ScRangeName::iterator itr = rRanges.begin(), itrEnd = rRanges.end();
+ vector<ScRangeName::iterator> v;
+ for (; itr != itrEnd; ++itr)
+ {
+ if (hasRefsToSrcDoc(*itr, nFileId))
+ v.push_back(itr);
+ }
+ for_each(v.begin(), v.end(), EraseRangeByIterator(rRanges));
+}
+
}
// ============================================================================
@@ -2358,9 +2409,14 @@ void lcl_removeByFileId(sal_uInt16 nFileId, MapContainer& rMap)
{
typename MapContainer::iterator itr = rMap.find(nFileId);
if (itr != rMap.end())
+ {
+ // Close this document shell.
+ itr->second.maShell->DoClose();
rMap.erase(itr);
+ }
}
+
void ScExternalRefManager::refreshNames(sal_uInt16 nFileId)
{
maRefCache.clearCache(nFileId);
@@ -2389,6 +2445,21 @@ void ScExternalRefManager::breakLink(sal_uInt16 nFileId)
maRefCells.erase(nFileId);
}
+ // Remove all named ranges that reference this document.
+
+ // Global named ranges.
+ ScRangeName* pRanges = mpDoc->GetRangeName();
+ if (pRanges)
+ removeRangeNamesBySrcDoc(*pRanges, nFileId);
+
+ // Sheet-local named ranges.
+ for (SCTAB i = 0, n = mpDoc->GetTableCount(); i < n; ++i)
+ {
+ pRanges = mpDoc->GetRangeName(i);
+ if (pRanges)
+ removeRangeNamesBySrcDoc(*pRanges, nFileId);
+ }
+
lcl_removeByFileId(nFileId, maDocShells);
if (maDocShells.empty())
@@ -2528,6 +2599,9 @@ void ScExternalRefManager::purgeStaleSrcDocument(sal_Int32 nTimeOut)
sal_Int32 nSinceLastAccess = (Time() - itr->second.maLastAccess).GetTime();
if (nSinceLastAccess < nTimeOut)
aNewDocShells.insert(*itr);
+ else
+ // Timed out. Let's close this.
+ itr->second.maShell->DoClose();
}
maDocShells.swap(aNewDocShells);
diff --git a/sc/source/ui/inc/dbdocfun.hxx b/sc/source/ui/inc/dbdocfun.hxx
index 132eb9a3750b..11b2ce27ef62 100644
--- a/sc/source/ui/inc/dbdocfun.hxx
+++ b/sc/source/ui/inc/dbdocfun.hxx
@@ -114,7 +114,7 @@ public:
sal_Bool RenameDBRange( const String& rOld, const String& rNew, sal_Bool bApi );
sal_Bool ModifyDBData( const ScDBData& rNewData, sal_Bool bApi ); // Name unveraendert
- sal_Bool RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi );
+ sal_Bool RepeatDB( const String& rDBName, sal_Bool bRecord, sal_Bool bApi, bool bIsUnnamed=false, SCTAB aTab = 0);
sal_Bool DataPilotUpdate( ScDPObject* pOldObj, const ScDPObject* pNewObj,
sal_Bool bRecord, sal_Bool bApi, sal_Bool bAllowMove = false );
diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx
index d8617490219a..16fc7591ac08 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -421,8 +421,7 @@ public:
ScDocument* pNewUndoDoc, const ScMarkData& rMark,
FillDir eNewFillDir,
FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
- double fNewStartValue, double fNewStepValue, double fNewMaxValue,
- sal_uInt16 nMaxShIndex );
+ double fNewStartValue, double fNewStepValue, double fNewMaxValue );
virtual ~ScUndoAutoFill();
virtual void Undo();
@@ -444,7 +443,6 @@ private:
double fMaxValue;
sal_uLong nStartChangeAction;
sal_uLong nEndChangeAction;
- sal_uInt16 nMaxSharedIndex;
void SetChangeTrack();
};
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index 446e3dede1c6..45ea822f2090 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -602,8 +602,7 @@ ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
const ScRange& rRange, const ScRange& rSourceArea,
ScDocument* pNewUndoDoc, const ScMarkData& rMark,
FillDir eNewFillDir, FillCmd eNewFillCmd, FillDateCmd eNewFillDateCmd,
- double fNewStartValue, double fNewStepValue, double fNewMaxValue,
- sal_uInt16 nMaxShIndex )
+ double fNewStartValue, double fNewStepValue, double fNewMaxValue )
//
: ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
//
@@ -615,8 +614,7 @@ ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
eFillDateCmd ( eNewFillDateCmd ),
fStartValue ( fNewStartValue ),
fStepValue ( fNewStepValue ),
- fMaxValue ( fNewMaxValue ),
- nMaxSharedIndex ( nMaxShIndex)
+ fMaxValue ( fNewMaxValue )
{
SetChangeTrack();
}
@@ -626,7 +624,6 @@ ScUndoAutoFill::ScUndoAutoFill( ScDocShell* pNewDocShell,
ScUndoAutoFill::~ScUndoAutoFill()
{
- pDocShell->GetDocument()->EraseNonUsedSharedNames(nMaxSharedIndex);
delete pUndoDoc;
}
@@ -649,26 +646,6 @@ void ScUndoAutoFill::SetChangeTrack()
nStartChangeAction = nEndChangeAction = 0;
}
-namespace {
-
-bool eraseNameContaining(ScRangeName& rNames, const rtl::OUString& rCriteria)
-{
- ScRangeName::iterator itr = rNames.begin(), itrEnd = rNames.end();
- for (; itr != itrEnd; ++itr)
- {
- rtl::OUString aRName = itr->GetName();
- if (aRName.indexOf(rCriteria) >= 0)
- {
- // Criteria found. Erase this.
- rNames.erase(itr);
- return true;
- }
- }
- return false;
-}
-
-}
-
void ScUndoAutoFill::Undo()
{
BeginUndo();
@@ -698,29 +675,6 @@ void ScUndoAutoFill::Undo()
if (pViewShell)
pViewShell->CellContentChanged();
-// Shared-Names loeschen
-// Falls Undo ins Dokument gespeichert
-// => automatisches Loeschen am Ende
-// umarbeiten!!
-
- String aName = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("___SC_"));
- aName += String::CreateFromInt32(nMaxSharedIndex);
- aName += '_';
- ScRangeName* pRangeName = pDoc->GetRangeName();
- bool bHasFound = false;
- // Remove all range names that contain ___SC_...
- while (true)
- {
- bool bErased = eraseNameContaining(*pRangeName, aName);
- if (bErased)
- bHasFound = true;
- else
- break;
- }
-
- if (bHasFound)
- pRangeName->SetSharedMaxIndex(pRangeName->GetSharedMaxIndex()-1);
-
ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
diff --git a/sc/source/ui/unoobj/datauno.cxx b/sc/source/ui/unoobj/datauno.cxx
index f5f2ab6071d0..a1ee63dc8b26 100644
--- a/sc/source/ui/unoobj/datauno.cxx
+++ b/sc/source/ui/unoobj/datauno.cxx
@@ -57,6 +57,7 @@
#include "docsh.hxx"
#include "dbdocfun.hxx"
#include "unonames.hxx"
+#include "globalnames.hxx"
#include "globstr.hrc"
#include "convuno.hxx"
#include "hints.hxx"
@@ -1607,7 +1608,18 @@ void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam )
ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const String& rNm) :
pDocShell( pDocSh ),
aName( rNm ),
- aPropSet( lcl_GetDBRangePropertyMap() )
+ aPropSet( lcl_GetDBRangePropertyMap() ),
+ bIsUnnamed(false)
+{
+ pDocShell->GetDocument()->AddUnoObject(*this);
+}
+
+ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab) :
+ pDocShell( pDocSh ),
+ aName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)),
+ aPropSet( lcl_GetDBRangePropertyMap() ),
+ bIsUnnamed(true),
+ aTab( nTab )
{
pDocShell->GetDocument()->AddUnoObject(*this);
}
@@ -1641,12 +1653,19 @@ ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const
ScDBData* pRet = NULL;
if (pDocShell)
{
- ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
- if (pNames)
+ if (bIsUnnamed)
{
- sal_uInt16 nPos = 0;
- if (pNames->SearchName( aName, nPos ))
- pRet = (*pNames)[nPos];
+ pRet = pDocShell->GetDocument()->GetAnonymousDBData(aTab);
+ }
+ else
+ {
+ ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
+ if (pNames)
+ {
+ sal_uInt16 nPos = 0;
+ if (pNames->SearchName( aName, nPos ))
+ pRet = (*pNames)[nPos];
+ }
}
}
return pRet;
@@ -1889,7 +1908,7 @@ void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException)
// interne Operationen (sort, query, subtotal) nur, wenn kein Fehler
if (bContinue)
- aFunc.RepeatDB( pData->GetName(), sal_True, sal_True );
+ aFunc.RepeatDB( pData->GetName(), true, true, bIsUnnamed, aTab );
}
}
@@ -2079,7 +2098,7 @@ uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const rtl::OUString& aPr
{
// all database ranges except "unnamed" are user defined
ScUnoHelpFunctions::SetBoolInAny( aRet,
- ( pData->GetName() != ScGlobal::GetRscString(STR_DB_NONAME) ) );
+ ( pData->GetName() != String(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME)) ) );
}
else if ( aString.EqualsAscii( SC_UNO_LINKDISPBIT ) )
{
@@ -2354,8 +2373,90 @@ sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const rtl::OUString& aName )
//------------------------------------------------------------------------
+ScUnnamedDatabaseRangesObj::ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh) :
+ pDocShell( pDocSh )
+{
+ pDocShell->GetDocument()->AddUnoObject(*this);
+}
+
+ScUnnamedDatabaseRangesObj::~ScUnnamedDatabaseRangesObj()
+{
+ if (pDocShell)
+ pDocShell->GetDocument()->RemoveUnoObject(*this);
+}
+
+void ScUnnamedDatabaseRangesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
+{
+ // Referenz-Update interessiert hier nicht
+
+ if ( rHint.ISA( SfxSimpleHint ) &&
+ ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
+ {
+ pDocShell = NULL; // ungueltig geworden
+ }
+}
+
+// XUnnamedDatabaseRanges
+
+void ScUnnamedDatabaseRangesObj::setByTable( const table::CellRangeAddress& aRange )
+ throw( uno::RuntimeException,
+ lang::IndexOutOfBoundsException )
+{
+ SolarMutexGuard aGuard;
+ bool bDone = false;
+ if (pDocShell)
+ {
+ if ( pDocShell->GetDocument()->GetTableCount() <= aRange.Sheet )
+ throw lang::IndexOutOfBoundsException();
+ ScDBDocFunc aFunc(*pDocShell);
+ String aString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
+ ScRange aUnnamedRange( (SCCOL)aRange.StartColumn, (SCROW)aRange.StartRow, aRange.Sheet,
+ (SCCOL)aRange.EndColumn, (SCROW)aRange.EndRow, aRange.Sheet );
+ bDone = aFunc.AddDBRange( aString, aUnnamedRange, sal_True );
+ }
+ if (!bDone)
+ throw uno::RuntimeException(); // no other exceptions specified
+}
+uno::Any ScUnnamedDatabaseRangesObj::getByTable( const sal_Int32 nTab )
+ throw(uno::RuntimeException,
+ lang::IndexOutOfBoundsException,
+ container::NoSuchElementException)
+{
+ SolarMutexGuard aGuard;
+ if (pDocShell)
+ {
+ if ( pDocShell->GetDocument()->GetTableCount() <= nTab )
+ throw lang::IndexOutOfBoundsException();
+ uno::Reference<sheet::XDatabaseRange> xRange( new ScDatabaseRangeObj(pDocShell, (SCTAB) nTab) );
+ if (xRange.is())
+ return uno::makeAny(xRange);
+ else
+ throw container::NoSuchElementException();
+ }
+ else
+ throw uno::RuntimeException();
+}
+
+sal_Bool ScUnnamedDatabaseRangesObj::hasByTable( sal_Int32 nTab )
+ throw (uno::RuntimeException,
+ lang::IndexOutOfBoundsException)
+{
+ SolarMutexGuard aGuard;
+ if (pDocShell)
+ {
+ if (pDocShell->GetDocument()->GetTableCount() <= nTab)
+ throw lang::IndexOutOfBoundsException();
+ if (pDocShell->GetDocument()->GetAnonymousDBData((SCTAB) nTab))
+ return true;
+ return false;
+ }
+ else
+ return false;
+}
+
+//------------------------------------------------------------------------
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index e84f6756757e..15673f35c0b8 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -56,6 +56,7 @@
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/sheet/XNamedRanges.hpp>
#include <com/sun/star/sheet/XLabelRanges.hpp>
+#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
#include <com/sun/star/i18n/XForbiddenCharacters.hpp>
#include <com/sun/star/script/XLibraryContainer.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
@@ -1780,6 +1781,10 @@ uno::Any SAL_CALL ScModelObj::getPropertyValue( const rtl::OUString& aPropertyNa
{
aRet <<= uno::Reference<sheet::XDatabaseRanges>(new ScDatabaseRangesObj( pDocShell ));
}
+ else if ( aString.EqualsAscii( SC_UNO_UNNAMEDDBRNG ) )
+ {
+ aRet <<= uno::Reference<sheet::XUnnamedDatabaseRanges>(new ScUnnamedDatabaseRangesObj(pDocShell));
+ }
else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) )
{
aRet <<= uno::Reference<sheet::XLabelRanges>(new ScLabelRangesObj( pDocShell, sal_True ));
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx
index d98f1ac7ee1e..cbf30eba603d 100644
--- a/sc/source/ui/vba/excelvbahelper.cxx
+++ b/sc/source/ui/vba/excelvbahelper.cxx
@@ -66,36 +66,33 @@ GetDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException )
return xDBRanges;
}
+uno::Reference< sheet::XUnnamedDatabaseRanges >
+GetUnnamedDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException )
+{
+ uno::Reference< frame::XModel > xModel;
+ if ( pShell )
+ xModel.set( pShell->GetModel(), uno::UNO_QUERY_THROW );
+ uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnnamedDatabaseRanges") ) ), uno::UNO_QUERY_THROW );
+ return xUnnamedDBRanges;
+}
+
// returns the XDatabaseRange for the autofilter on sheet (nSheet)
// also populates sName with the name of range
uno::Reference< sheet::XDatabaseRange >
-GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( uno::RuntimeException )
+GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet ) throw ( uno::RuntimeException )
{
- uno::Reference< container::XIndexAccess > xIndexAccess( GetDataBaseRanges( pShell ), uno::UNO_QUERY_THROW );
+ uno::Reference< sheet::XUnnamedDatabaseRanges > xUnnamedDBRanges( GetUnnamedDataBaseRanges( pShell ), uno::UNO_QUERY_THROW );
uno::Reference< sheet::XDatabaseRange > xDataBaseRange;
- table::CellRangeAddress dbAddress;
- for ( sal_Int32 index=0; index < xIndexAccess->getCount(); ++index )
+ if (xUnnamedDBRanges->hasByTable( nSheet ) )
{
- uno::Reference< sheet::XDatabaseRange > xDBRange( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
- uno::Reference< container::XNamed > xNamed( xDBRange, uno::UNO_QUERY_THROW );
- // autofilters work weirdly with openoffice, unnamed is the default
- // named range which is used to create an autofilter, but
- // its also possible that another name could be used
- // this also causes problems when an autofilter is created on
- // another sheet
- // ( but.. you can use any named range )
- dbAddress = xDBRange->getDataArea();
- if ( dbAddress.Sheet == nSheet )
+ uno::Reference< sheet::XDatabaseRange > xDBRange( xUnnamedDBRanges->getByTable( nSheet ) , uno::UNO_QUERY_THROW );
+ sal_Bool bHasAuto = false;
+ uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
+ xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto;
+ if ( bHasAuto )
{
- sal_Bool bHasAuto = false;
- uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW );
- xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto;
- if ( bHasAuto )
- {
- sName = xNamed->getName();
- xDataBaseRange=xDBRange;
- break;
- }
+ xDataBaseRange=xDBRange;
}
}
return xDataBaseRange;
diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx
index 9befc1548357..1cc0546a4fd7 100644
--- a/sc/source/ui/vba/excelvbahelper.hxx
+++ b/sc/source/ui/vba/excelvbahelper.hxx
@@ -32,6 +32,7 @@
#include "docsh.hxx"
#include <com/sun/star/sheet/XDatabaseRanges.hpp>
#include <com/sun/star/sheet/XDatabaseRange.hpp>
+#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
#include <com/sun/star/table/XCellRange.hpp>
#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
@@ -65,8 +66,9 @@ formula::FormulaGrammar::Grammar GetFormulaGrammar( ScDocument* pDoc, const ScAd
void CompileExcelFormulaToODF( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula );
void CompileODFFormulaToExcel( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula, const formula::FormulaGrammar::Grammar eGrammar );
css::uno::Reference< css::sheet::XDatabaseRanges > GetDataBaseRanges( ScDocShell* pShell ) throw ( css::uno::RuntimeException );
+css::uno::Reference< css::sheet::XUnnamedDatabaseRanges > GetUnnamedDataBaseRanges( ScDocShell* pShell ) throw ( css::uno::RuntimeException );
-css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( css::uno::RuntimeException );
+css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet ) throw ( css::uno::RuntimeException );
css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet ) throw ( css::uno::RuntimeException );
css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException );
css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::uno::RuntimeException );
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index df750a774ad4..9c199423abd0 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -39,6 +39,7 @@
#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
#include <com/sun/star/sheet/XDatabaseRange.hpp>
#include <com/sun/star/sheet/XDatabaseRanges.hpp>
+#include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
#include <com/sun/star/sheet/XGoalSeek.hpp>
#include <com/sun/star/sheet/XSheetOperation.hpp>
#include <com/sun/star/sheet/CellFlags.hpp>
@@ -4334,20 +4335,10 @@ ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xC
// Helper functions for AutoFilter
ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet )
{
- rtl::OUString sName;
- excel::GetAutoFiltRange( pDocShell, nSheet, sName );
- OSL_TRACE("lcl_GetDBData_Impl got autofilter range %s for sheet %d",
- rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet );
ScDBData* pRet = NULL;
if (pDocShell)
{
- ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection();
- if (pNames)
- {
- sal_uInt16 nPos = 0;
- if (pNames->SearchName( sName , nPos ))
- pRet = (*pNames)[nPos];
- }
+ pRet = pDocShell->GetDocument()->GetAnonymousDBData(nSheet);
}
return pRet;
}
@@ -4501,8 +4492,7 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
sal_Int16 nSheet = thisAddress.Sheet;
ScDocShell* pShell = getScDocShell();
sal_Bool bHasAuto = false;
- rtl::OUString sAutofiltRangeName;
- uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName );
+ uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet );
if ( xDataBaseRange.is() )
bHasAuto = true;
@@ -4549,16 +4539,13 @@ ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const
}
}
- uno::Reference< sheet::XDatabaseRanges > xDBRanges = excel::GetDataBaseRanges( pShell );
+ uno::Reference< sheet::XUnnamedDatabaseRanges > xDBRanges = excel::GetUnnamedDataBaseRanges( pShell );
if ( xDBRanges.is() )
{
- rtl::OUString sGenName( RTL_CONSTASCII_USTRINGPARAM("VBA_Autofilter_") );
- sGenName += rtl::OUString::valueOf( static_cast< sal_Int32 >( nSheet ) );
- OSL_TRACE("Going to add new autofilter range.. name %s",
- rtl::OUStringToOString( sGenName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet );
- if ( !xDBRanges->hasByName( sGenName ) )
- xDBRanges->addNewByName( sGenName, autoFiltAddress );
- xDataBaseRange.set( xDBRanges->getByName( sGenName ), uno::UNO_QUERY_THROW );
+ OSL_TRACE("Going to add new autofilter range.. sheet %i", nSheet );
+ if ( !xDBRanges->hasByTable( nSheet ) )
+ xDBRanges->setByTable( autoFiltAddress );
+ xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW );
}
if ( !xDataBaseRange.is() )
throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() );
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 2918410d0923..cc85ef7b7137 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -97,10 +97,13 @@ static void lcl_PostRepaintCondFormat( const ScConditionalFormat *pCondFmt, ScDo
{
if( pCondFmt )
{
- const ScRangeListRef& aRanges = pCondFmt->GetRangeInfo();
- size_t nCount = aRanges->size();
+ const ScRangeListRef& xRanges = pCondFmt->GetRangeInfo();
+ if (!xRanges)
+ return;
+
+ size_t nCount = xRanges->size();
for( size_t n = 0 ; n < nCount; n++ )
- pDocSh->PostPaint( *((*aRanges)[n]), PAINT_ALL );
+ pDocSh->PostPaint( *((*xRanges)[n]), PAINT_ALL );
}
}