[Libreoffice-commits] .: 2 commits - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Mon Apr 25 13:25:22 PDT 2011


 sc/inc/document.hxx                |    6 +--
 sc/source/filter/excel/excimp8.cxx |   64 ++++++++++++-------------------------
 sc/source/filter/excel/xiname.cxx  |    2 -
 sc/source/filter/inc/excimp8.hxx   |   15 ++------
 sc/source/ui/vba/vbaworksheet.cxx  |   55 ++++++++++++++++---------------
 sc/source/ui/vba/vbaworksheet.hxx  |    2 -
 6 files changed, 58 insertions(+), 86 deletions(-)

New commits:
commit c2661125f8086273199173bbdb682a22ffe325ca
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Apr 25 17:28:03 2011 +0200

    make excel binary import use anonymous db data

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index ddcebe1..2879b73 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -526,7 +526,7 @@ public:
     SC_DLLPUBLIC sal_Bool                   SetCodeName( SCTAB nTab, const String& rName );
     SC_DLLPUBLIC sal_Bool			GetTable( const String& rName, SCTAB& rTab ) const;
 
-    void            SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData);
+    SC_DLLPUBLIC void            SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData);
     SC_DLLPUBLIC ScDBData*       GetAnonymousDBData(SCTAB nTab);
 
     SC_DLLPUBLIC inline SCTAB	GetTableCount() const { return nMaxTableNumber; }
diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx
index 40b47cd..cf4abda 100644
--- a/sc/source/filter/excel/excimp8.cxx
+++ b/sc/source/filter/excel/excimp8.cxx
@@ -82,6 +82,7 @@
 #include "attrib.hxx"
 #include "conditio.hxx"
 #include "dbcolect.hxx"
+#include "globalnames.hxx"
 #include "editutil.hxx"
 #include "markdata.hxx"
 #include "rangenam.hxx"
@@ -468,8 +469,6 @@ void ImportExcel8::FilterMode( void )
     // then the latter is true..
     if( !pExcRoot->pAutoFilterBuffer ) return;
 
-    pExcRoot->pAutoFilterBuffer->IncrementActiveAF();
-
     XclImpAutoFilterData* pData = pExcRoot->pAutoFilterBuffer->GetByTab( GetCurrScTab() );
     if( pData )
         pData->SetAutoOrAdvanced();
@@ -498,15 +497,14 @@ void ImportExcel8::AutoFilter( void )
 
 
 
-XclImpAutoFilterData::XclImpAutoFilterData( RootData* pRoot, const ScRange& rRange, const String& rName ) :
+XclImpAutoFilterData::XclImpAutoFilterData( RootData* pRoot, const ScRange& rRange ) :
         ExcRoot( pRoot ),
         pCurrDBData(NULL),
         nFirstEmpty( 0 ),
         bActive( false ),
         bHasConflict( false ),
         bCriteria( false ),
-        bAutoOrAdvanced(false),
-        aFilterName(rName)
+        bAutoOrAdvanced(false)
 {
     aParam.nCol1 = rRange.aStart.Col();
     aParam.nRow1 = rRange.aStart.Row();
@@ -750,9 +748,9 @@ void XclImpAutoFilterData::SetExtractPos( const ScAddress& rAddr )
     aParam.bDestPers = sal_True;
 }
 
-void XclImpAutoFilterData::Apply( const sal_Bool bUseUnNamed )
+void XclImpAutoFilterData::Apply()
 {
-    CreateScDBData(bUseUnNamed);
+    CreateScDBData();
 
     if( bActive )
     {
@@ -774,35 +772,27 @@ void XclImpAutoFilterData::Apply( const sal_Bool bUseUnNamed )
     }
 }
 
-void XclImpAutoFilterData::CreateScDBData( const sal_Bool bUseUnNamed )
+void XclImpAutoFilterData::CreateScDBData()
 {
 
     // Create the ScDBData() object if the AutoFilter is activated
     // or if we need to create the Advanced Filter.
     if( bActive || bCriteria)
     {
-        ScDBCollection& rColl = pExcRoot->pIR->GetDatabaseRanges();
-        pCurrDBData	= rColl.GetDBAtArea( Tab(), StartCol(), StartRow(), EndCol(), EndRow() );
-        if( !pCurrDBData )
+        ScDocument* pDoc = pExcRoot->pIR->GetDocPtr();
+        String aNewName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
+        pCurrDBData = new ScDBData(aNewName , Tab(),
+                                StartCol(),StartRow(), EndCol(),EndRow() );
+        if(bCriteria)
         {
-            AmendAFName(bUseUnNamed);
-
-            pCurrDBData = new ScDBData( aFilterName, Tab(), StartCol(), StartRow(), EndCol(), EndRow() );
-
-            if( pCurrDBData )
-            {
-                if(bCriteria)
-                {
-                    EnableRemoveFilter();
+            EnableRemoveFilter();
 
-                    pCurrDBData->SetQueryParam( aParam );
-                    pCurrDBData->SetAdvancedQuerySource(&aCriteriaRange);
-                }
-                else
-                    pCurrDBData->SetAdvancedQuerySource(NULL);
-                rColl.Insert( pCurrDBData );
-            }
+            pCurrDBData->SetQueryParam( aParam );
+            pCurrDBData->SetAdvancedQuerySource(&aCriteriaRange);
         }
+        else
+            pCurrDBData->SetAdvancedQuerySource(NULL);
+        pDoc->SetAnonymousDBData(Tab(), pCurrDBData);
     }
 
 }
@@ -822,18 +812,7 @@ void XclImpAutoFilterData::EnableRemoveFilter()
     // inside the advanced range
 }
 
-void XclImpAutoFilterData::AmendAFName(const sal_Bool bUseUnNamed)
-{
-    // If-and-only-if we have one AF filter then
-    // use the Calc "unnamed" range name. Calc
-    // only supports one in total while Excel
-    // supports one per sheet.
-    if( bUseUnNamed && bAutoOrAdvanced )
-        aFilterName = ScGlobal::GetRscString(STR_DB_NONAME);
-}
-
-XclImpAutoFilterBuffer::XclImpAutoFilterBuffer() :
-    nAFActiveCount( 0 )
+XclImpAutoFilterBuffer::XclImpAutoFilterBuffer()
 {
 }
 
@@ -843,11 +822,10 @@ XclImpAutoFilterBuffer::~XclImpAutoFilterBuffer()
         delete pData;
 }
 
-void XclImpAutoFilterBuffer::Insert( RootData* pRoot, const ScRange& rRange,
-                                    const String& rName )
+void XclImpAutoFilterBuffer::Insert( RootData* pRoot, const ScRange& rRange)
 {
     if( !GetByTab( rRange.aStart.Tab() ) )
-        Append( new XclImpAutoFilterData( pRoot, rRange, rName ) );
+        Append( new XclImpAutoFilterData( pRoot, rRange) );
 }
 
 void XclImpAutoFilterBuffer::AddAdvancedRange( const ScRange& rRange )
@@ -867,7 +845,7 @@ void XclImpAutoFilterBuffer::AddExtractPos( const ScRange& rRange )
 void XclImpAutoFilterBuffer::Apply()
 {
     for( XclImpAutoFilterData* pData = _First(); pData; pData = _Next() )
-        pData->Apply(UseUnNamed());
+        pData->Apply();
 }
 
 XclImpAutoFilterData* XclImpAutoFilterBuffer::GetByTab( SCTAB nTab )
diff --git a/sc/source/filter/excel/xiname.cxx b/sc/source/filter/excel/xiname.cxx
index eeba8e3..15bf618 100644
--- a/sc/source/filter/excel/xiname.cxx
+++ b/sc/source/filter/excel/xiname.cxx
@@ -186,7 +186,7 @@ XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
                 switch( mcBuiltIn )
                 {
                     case EXC_BUILTIN_FILTERDATABASE:
-                        GetFilterManager().Insert( &GetOldRoot(), aRange, maScName );
+                        GetFilterManager().Insert( &GetOldRoot(), aRange);
                     break;
                     case EXC_BUILTIN_CRITERIA:
                         GetFilterManager().AddAdvancedRange( aRange );
diff --git a/sc/source/filter/inc/excimp8.hxx b/sc/source/filter/inc/excimp8.hxx
index a3a721e..274ef95 100644
--- a/sc/source/filter/inc/excimp8.hxx
+++ b/sc/source/filter/inc/excimp8.hxx
@@ -103,7 +103,6 @@ private:
     sal_Bool                        bCriteria;
     sal_Bool                        bAutoOrAdvanced;
     ScRange                     aCriteriaRange;
-    String                      aFilterName;
 
     void						CreateFromDouble( String& rStr, double fVal );
     void						SetCellAttribs();
@@ -114,8 +113,7 @@ protected:
 public:
                                 XclImpAutoFilterData(
                                     RootData* pRoot,
-                                    const ScRange& rRange,
-                                    const String& rName );
+                                    const ScRange& rRange);
 
     inline bool                 IsActive() const    { return bActive; }
     inline bool                 IsFiltered() const  { return bAutoOrAdvanced; }
@@ -131,8 +129,8 @@ public:
     void                        SetAdvancedRange( const ScRange* pRange );
     void						SetExtractPos( const ScAddress& rAddr );
     inline void                 SetAutoOrAdvanced()  { bAutoOrAdvanced = sal_True; }
-    void						Apply( const sal_Bool bUseUnNamed = false );
-    void                        CreateScDBData( const sal_Bool bUseUnNamed );
+    void						Apply();
+    void                        CreateScDBData();
     void                        EnableRemoveFilter();
 };
 
@@ -142,8 +140,6 @@ class XclImpAutoFilterBuffer : private List
 private:
     using                       List::Insert;
 
-    sal_uInt16                      nAFActiveCount;
-
     inline XclImpAutoFilterData* _First()	{ return (XclImpAutoFilterData*) List::First(); }
     inline XclImpAutoFilterData* _Next()	{ return (XclImpAutoFilterData*) List::Next(); }
 
@@ -154,15 +150,12 @@ public:
                                 XclImpAutoFilterBuffer();
     virtual						~XclImpAutoFilterBuffer();
 
-    void						Insert( RootData* pRoot, const ScRange& rRange,
-                                                const String& rName );
+    void						Insert( RootData* pRoot, const ScRange& rRange);
     void						AddAdvancedRange( const ScRange& rRange );
     void						AddExtractPos( const ScRange& rRange );
     void						Apply();
 
     XclImpAutoFilterData*		GetByTab( SCTAB nTab );
-    inline void                 IncrementActiveAF() { nAFActiveCount++; }
-    inline sal_Bool                 UseUnNamed() { return nAFActiveCount == 1; }
 };
 
 #endif
commit e01da223f647e26479a2b58b0baa2b56fead7a41
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Apr 21 22:01:59 2011 +0200

    make VbaWorksheet Autofilter work with sheet local DBData

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8f793e8..ddcebe1 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -527,7 +527,7 @@ public:
     SC_DLLPUBLIC sal_Bool			GetTable( const String& rName, SCTAB& rTab ) const;
 
     void            SetAnonymousDBData(SCTAB nTab, ScDBData* pDBData);
-    ScDBData*       GetAnonymousDBData(SCTAB nTab);
+    SC_DLLPUBLIC ScDBData*       GetAnonymousDBData(SCTAB nTab);
 
     SC_DLLPUBLIC inline SCTAB	GetTableCount() const { return nMaxTableNumber; }
     SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }
@@ -1236,7 +1236,7 @@ public:
     SC_DLLPUBLIC sal_Bool			ApplyFlagsTab( SCCOL nStartCol, SCROW nStartRow,
                                             SCCOL nEndCol, SCROW nEndRow,
                                             SCTAB nTab, sal_Int16 nFlags );
-    sal_Bool			RemoveFlagsTab( SCCOL nStartCol, SCROW nStartRow,
+    SC_DLLPUBLIC sal_Bool			RemoveFlagsTab( SCCOL nStartCol, SCROW nStartRow,
                                             SCCOL nEndCol, SCROW nEndRow,
                                             SCTAB nTab, sal_Int16 nFlags );
 
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index 94f197d..e953d56 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -101,6 +101,8 @@
 #include "vbasheetobjects.hxx"
 #include "viewuno.hxx"
 
+#include "attrib.hxx"
+
 #define STANDARDWIDTH 2267
 #define STANDARDHEIGHT 427
 #define DOESNOTEXIST -1
@@ -352,38 +354,39 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) throw (uno::RuntimeEx
 
 }
 
-uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties() throw (uno::RuntimeException)
-{
-    uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW );
-    uno::Reference< container::XIndexAccess > xDBRangesIA( xModelProps->getPropertyValue(
-        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DatabaseRanges" ) ) ), uno::UNO_QUERY_THROW );
-
-    for( sal_Int32 nIndex = 0, nCount = xDBRangesIA->getCount(); nIndex < nCount; ++nIndex )
-    {
-        uno::Reference< sheet::XCellRangeReferrer > xDBRange( xDBRangesIA->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
-        // check if the database area is on this sheet
-        uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( xDBRange->getReferredCells(), uno::UNO_QUERY_THROW );
-        if( getSheetID() == xRangeAddr->getRangeAddress().Sheet )
-            return uno::Reference< beans::XPropertySet >( xDBRange, uno::UNO_QUERY_THROW );
-    }
-    return uno::Reference< beans::XPropertySet >();
-}
-
 sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() throw (uno::RuntimeException)
 {
-    uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
-    sal_Bool bAutoFilterMode = false;
-    return
-        xDBRangeProps.is() &&
-        (xDBRangeProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ) ) >>= bAutoFilterMode) &&
-        bAutoFilterMode;
+    uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
+    ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
+    ScDBData* pDBData = pDoc->GetAnonymousDBData(getSheetID());
+    if (pDBData)
+        return pDBData->HasAutoFilter();
+    return false;
 }
 
 void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (uno::RuntimeException)
 {
-    uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
-    if( xDBRangeProps.is() )
-        xDBRangeProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ), uno::Any( bAutoFilterMode ) );
+    uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
+    ScDocShell* pDocShell = excel::getDocShell( xModel );
+    ScDocument* pDoc = pDocShell->GetDocument();
+    ScDBData* pDBData = pDoc->GetAnonymousDBData(getSheetID());
+    if (pDBData)
+    {
+        pDBData->SetAutoFilter(bAutoFilterMode);
+        ScRange aRange;
+        pDBData->GetArea(aRange);
+        if (bAutoFilterMode && pDoc)
+            pDoc->ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
+                                    aRange.aEnd.Col(), aRange.aStart.Row(),
+                                    aRange.aStart.Tab(), SC_MF_AUTO );
+        else  if (!bAutoFilterMode && pDoc)
+            pDoc->RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
+                                    aRange.aEnd.Col(), aRange.aStart.Row(),
+                                    aRange.aStart.Tab(), SC_MF_AUTO );
+        ScRange aPaintRange(aRange.aStart, aRange.aEnd);
+        aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
+        pDocShell->PostPaint(aPaintRange, PAINT_GRID);
+    }
 }
 
 uno::Reference< excel::XRange >
diff --git a/sc/source/ui/vba/vbaworksheet.hxx b/sc/source/ui/vba/vbaworksheet.hxx
index 6ad6baf..58e45bb 100644
--- a/sc/source/ui/vba/vbaworksheet.hxx
+++ b/sc/source/ui/vba/vbaworksheet.hxx
@@ -72,8 +72,6 @@ class ScVbaWorksheet : public WorksheetImpl_BASE
     css::uno::Reference< css::container::XNameAccess > getFormControls();
     css::uno::Any getControlShape( const rtl::OUString& sName );
     
-    css::uno::Reference< css::beans::XPropertySet > getFirstDBRangeProperties() throw (css::uno::RuntimeException);
-    
 protected:
 
     ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent,  const css::uno::Reference< css::uno::XComponentContext >& xContext );


More information about the Libreoffice-commits mailing list