[Libreoffice-commits] .: 15 commits - sc/inc sc/qa sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Mon Aug 13 03:34:38 PDT 2012


 sc/inc/colorscale.hxx                      |   29 +--
 sc/qa/unit/data/ods/colorScale.ods         |binary
 sc/qa/unit/subsequent_filters-test.cxx     |   47 ++++++
 sc/source/core/data/colorscale.cxx         |  221 +++++++++++++----------------
 sc/source/filter/excel/xecontent.cxx       |   23 +--
 sc/source/filter/inc/condformatbuffer.hxx  |    3 
 sc/source/filter/inc/condformatcontext.hxx |    3 
 sc/source/filter/inc/extlstcontext.hxx     |    6 
 sc/source/filter/oox/condformatbuffer.cxx  |   16 --
 sc/source/filter/oox/condformatcontext.cxx |   27 ++-
 sc/source/filter/oox/extlstcontext.cxx     |   46 ++++--
 sc/source/filter/oox/worksheethelper.cxx   |    1 
 sc/source/filter/xml/xmlcondformat.cxx     |   13 +
 sc/source/filter/xml/xmlexprt.cxx          |   38 +++-
 sc/source/ui/condformat/colorformat.cxx    |   71 ++++++---
 sc/source/ui/condformat/condformatdlg.cxx  |  123 +++++++++-------
 sc/source/ui/src/colorformat.src           |    2 
 sc/source/ui/src/condformatdlg.src         |    2 
 18 files changed, 400 insertions(+), 271 deletions(-)

New commits:
commit 462907d48f18c8dab4f705203c840dee3253d268
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:49:14 2012 +0200

    add simple test for ods color scale import
    
    Change-Id: I539c6bfec17febbdd97c724fbde55b75da7700f6

diff --git a/sc/qa/unit/data/ods/colorScale.ods b/sc/qa/unit/data/ods/colorScale.ods
new file mode 100644
index 0000000..1c3fe6e
Binary files /dev/null and b/sc/qa/unit/data/ods/colorScale.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 23b298f..5667348 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -130,6 +130,10 @@ public:
     void testRepeatedColumnsODS();
     void testDataValidityODS();
 
+    void testColorScale();
+    void testDataBar();
+    void testCondFormat();
+
     //change this test file only in excel and not in calc
     void testSharedFormulaXLSX();
     void testCellValueXLSX();
@@ -170,6 +174,10 @@ public:
     CPPUNIT_TEST(testCellValueXLSX);
     CPPUNIT_TEST(testControlImport);
 
+    CPPUNIT_TEST(testColorScale);
+    CPPUNIT_TEST(testDataBar);
+    CPPUNIT_TEST(testCondFormat);
+
     //disable testPassword on MacOSX due to problems with libsqlite3
     //also crashes on DragonFly due to problems with nss/nspr headers
 #if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
@@ -1172,6 +1180,45 @@ void ScFiltersTest::testControlImport()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testColorScale()
+{
+    const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("colorScale."));
+    rtl::OUString aFileExtension(aFileFormats[ODS].pName, strlen(aFileFormats[ODS].pName), RTL_TEXTENCODING_UTF8 );
+    rtl::OUString aFilterName(aFileFormats[ODS].pFilterName, strlen(aFileFormats[ODS].pFilterName), RTL_TEXTENCODING_UTF8) ;
+    rtl::OUString aFileName;
+    createFileURL(aFileNameBase, aFileExtension, aFileName);
+    rtl::OUString aFilterType(aFileFormats[ODS].pTypeName, strlen(aFileFormats[ODS].pTypeName), RTL_TEXTENCODING_UTF8);
+    std::cout << aFileFormats[ODS].pName << " Test" << std::endl;
+    ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[ODS].nFormatType);
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load colorScale.ods", xDocSh.Is());
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    const ScPatternAttr* pPattern = pDoc->GetPattern(1,1,0);
+    sal_uLong nIndex = static_cast<const SfxUInt32Item&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetValue();
+    CPPUNIT_ASSERT(nIndex);
+    ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(0);
+    const ScConditionalFormat* pFormat = pCondFormatList->GetFormat(nIndex);
+    CPPUNIT_ASSERT(pFormat);
+
+    pPattern = pDoc->GetPattern(1,5,0);
+    nIndex = static_cast<const SfxUInt32Item&>(pPattern->GetItem(ATTR_CONDITIONAL)).GetValue();
+    CPPUNIT_ASSERT(nIndex);
+    pFormat = pCondFormatList->GetFormat(nIndex);
+    CPPUNIT_ASSERT(pFormat);
+}
+
+void ScFiltersTest::testDataBar()
+{
+
+}
+
+void ScFiltersTest::testCondFormat()
+{
+
+}
+
 ScFiltersTest::ScFiltersTest()
       : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
 {
commit b2e6a5717db9cbe6d9fa59ceaf860697b925ba76
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:34:07 2012 +0200

    also write the value for COLORSCALE_VALUE into the model
    
    Change-Id: I4e34f8d5c3eb3880e2ef3e7d65736057689b50bf

diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 387fb3e..a84103c 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -727,6 +727,7 @@ void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const
             break;
         case 3:
             pEntry->SetType(COLORSCALE_VALUE);
+            pEntry->SetValue(nVal);
             break;
         case 4:
             pEntry->SetType(COLORSCALE_PERCENT);
commit 5134d1acafd64b214f03078186d6c76be1f72c6d
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:26:37 2012 +0200

    this method is no longer used
    
    Change-Id: I7d9b75e79e2741be4013e6fbf3ac70d11f754aa4

diff --git a/sc/source/filter/inc/condformatbuffer.hxx b/sc/source/filter/inc/condformatbuffer.hxx
index 8bb94f4..188a0af 100644
--- a/sc/source/filter/inc/condformatbuffer.hxx
+++ b/sc/source/filter/inc/condformatbuffer.hxx
@@ -235,9 +235,6 @@ public:
     /** Imports settings from the CONDFORMATTING record. */
     CondFormatRef       importCondFormatting( SequenceInputStream& rStrm );
 
-    /** Creates all conditional formatting in the Calc document. */
-    void                finalizeImport();
-
     /** Converts an OOXML condition operator token to the API constant. */
     static sal_Int32    convertToApiOperator( sal_Int32 nToken );
 
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index 03d9ba1..702dffb 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -946,11 +946,6 @@ CondFormatRef CondFormatBuffer::importCondFormatting( SequenceInputStream& rStrm
     return xCondFmt;
 }
 
-void CondFormatBuffer::finalizeImport()
-{
-    maCondFormats.forEachMem( &CondFormat::finalizeImport );
-}
-
 sal_Int32 CondFormatBuffer::convertToApiOperator( sal_Int32 nToken )
 {
     switch( nToken )
commit 54869e337b8061471805cb3d3f59346dd6abf867
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:22:05 2012 +0200

    remove some empty methods from cond format oox import code
    
    Change-Id: I357d8361c9d23b47f5f554a1be97dcc369258323

diff --git a/sc/source/filter/inc/condformatcontext.hxx b/sc/source/filter/inc/condformatcontext.hxx
index deb3195..f5ebd8c 100644
--- a/sc/source/filter/inc/condformatcontext.hxx
+++ b/sc/source/filter/inc/condformatcontext.hxx
@@ -46,7 +46,6 @@ public:
 
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
     virtual void        onStartElement( const AttributeList& rAttribs );
-    virtual void        onCharacters( const ::rtl::OUString& rChars );
 
 private:
     CondFormatRuleRef mxRule;
diff --git a/sc/source/filter/inc/extlstcontext.hxx b/sc/source/filter/inc/extlstcontext.hxx
index 0984fb6..9663cfa 100644
--- a/sc/source/filter/inc/extlstcontext.hxx
+++ b/sc/source/filter/inc/extlstcontext.hxx
@@ -100,8 +100,6 @@ public:
 
 protected:
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
-    virtual void        onStartElement( const AttributeList& rAttribs );
-    virtual void        onCharacters( const ::rtl::OUString& rChars );
 };
 
 } //namespace xls
diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx
index 72a91cb..85f4da5 100644
--- a/sc/source/filter/oox/condformatcontext.cxx
+++ b/sc/source/filter/oox/condformatcontext.cxx
@@ -75,11 +75,6 @@ void ColorScaleContext::onStartElement( const AttributeList& rAttribs )
     }
 }
 
-void ColorScaleContext::onCharacters( const OUString&  )
-{
-
-}
-
 // ============================================================================
 
 DataBarContext::DataBarContext( CondFormatContext& rFragment, CondFormatRuleRef xRule ) :
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index 17ce45d..c1949e8 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -238,14 +238,6 @@ ContextHandlerRef ExtLstGlobalContext::onCreateContext( sal_Int32 nElement, cons
     return this;
 }
 
-void ExtLstGlobalContext::onStartElement( const AttributeList& )
-{
-}
-
-void ExtLstGlobalContext::onCharacters( const rtl::OUString&)
-{
-}
-
 } //namespace oox
 } //namespace xls
 
commit e5348c5f2dca19915036e365c50dd593709ef3cd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:19:45 2012 +0200

    add autoMin/autoMax oox import
    
    Change-Id: I5094cba7237245539448babdebee532ade6f674a

diff --git a/sc/source/filter/inc/extlstcontext.hxx b/sc/source/filter/inc/extlstcontext.hxx
index a76109c..0984fb6 100644
--- a/sc/source/filter/inc/extlstcontext.hxx
+++ b/sc/source/filter/inc/extlstcontext.hxx
@@ -40,12 +40,16 @@ public:
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
     virtual void        onStartElement( const AttributeList& rAttribs );
 
+    void finalizeImport();
+
 private:
     void importDataBar( const AttributeList& rAttribs );
     void importNegativeFillColor( const AttributeList& rAttribs );
     void importAxisColor( const AttributeList& rAttribs );
+    void importCfvo( const AttributeList& rAttribs );
     void* mpTarget;
 
+    bool mbFirstEntry;
 };
 
 /**
diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index a71332f..17ce45d 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -38,7 +38,8 @@ namespace xls {
 
 ExtCfRuleContext::ExtCfRuleContext( WorksheetContextBase& rFragment, void* pTarget ):
     WorksheetContextBase( rFragment ),
-    mpTarget( pTarget )
+    mpTarget( pTarget ),
+    mbFirstEntry(true)
 {
 }
 
@@ -60,6 +61,9 @@ void ExtCfRuleContext::onStartElement( const AttributeList& rAttribs )
         case XLS_EXT_TOKEN( axisColor ):
             importAxisColor( rAttribs );
             break;
+        case XLS_EXT_TOKEN( cfvo ):
+            importCfvo( rAttribs );
+            break;
 
         default:
             break;
@@ -112,6 +116,34 @@ void ExtCfRuleContext::importNegativeFillColor( const AttributeList& rAttribs )
     static_cast<ScDataBarFormatData*>(mpTarget)->mpNegativeColor.reset(pColor);
 }
 
+void ExtCfRuleContext::importCfvo( const AttributeList& rAttribs )
+{
+    ScDataBarFormatData* pDataBar = static_cast<ScDataBarFormatData*>(mpTarget);
+    ScColorScaleEntry* pEntry = NULL;
+    if(mbFirstEntry)
+        pEntry = pDataBar->mpLowerLimit.get();
+    else
+        pEntry = pDataBar->mpUpperLimit.get();
+
+    rtl::OUString aColorScaleType = rAttribs.getString( XML_type, rtl::OUString() );
+    if(aColorScaleType == "min")
+        pEntry->SetType(COLORSCALE_MIN);
+    else if (aColorScaleType == "max")
+        pEntry->SetType(COLORSCALE_MAX);
+    else if (aColorScaleType == "autoMin")
+        pEntry->SetType(COLORSCALE_AUTOMIN);
+    else if (aColorScaleType == "autoMax")
+        pEntry->SetType(COLORSCALE_AUTOMAX);
+    else if (aColorScaleType == "percentile")
+        pEntry->SetType(COLORSCALE_PERCENTILE);
+    else if (aColorScaleType == "percent")
+        pEntry->SetType(COLORSCALE_PERCENT);
+    else if (aColorScaleType == "formula")
+        pEntry->SetType(COLORSCALE_FORMULA);
+
+    mbFirstEntry = false;
+}
+
 ExtLstLocalContext::ExtLstLocalContext( WorksheetContextBase& rFragment, void* pTarget ):
     WorksheetContextBase(rFragment),
     mpTarget(pTarget)
commit 87b4a1438dfa62ab76587d77e1b57a8d080e0d0b
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Aug 13 00:12:56 2012 +0200

    write the conditional formatting earlier into the model
    
    The conditional formatting can be written into calc's model already at
    the end of the conditionalFormatting element and we don't need to wait
    till the end of the worksheet.
    
    This allows to modify the data through the ExtLst parser and allow
    correct import of Excel2010 data bars.
    
    Change-Id: Icb582931c6f89cbdb2b8b3dbe24af640ca8076ba

diff --git a/sc/source/filter/inc/condformatcontext.hxx b/sc/source/filter/inc/condformatcontext.hxx
index 08f5341..deb3195 100644
--- a/sc/source/filter/inc/condformatcontext.hxx
+++ b/sc/source/filter/inc/condformatcontext.hxx
@@ -73,9 +73,11 @@ protected:
     virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs );
     virtual void        onStartElement( const AttributeList& rAttribs );
     virtual void        onCharacters( const ::rtl::OUString& rChars );
+    virtual void        onEndElement();
 
     virtual ::oox::core::ContextHandlerRef onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm );
     virtual void        onStartRecord( SequenceInputStream& rStrm );
+    virtual void        onEndRecord();
 
 private:
     CondFormatRef       mxCondFmt;
diff --git a/sc/source/filter/oox/condformatcontext.cxx b/sc/source/filter/oox/condformatcontext.cxx
index 4e01d47..72a91cb 100644
--- a/sc/source/filter/oox/condformatcontext.cxx
+++ b/sc/source/filter/oox/condformatcontext.cxx
@@ -149,6 +149,17 @@ ContextHandlerRef CondFormatContext::onCreateContext( sal_Int32 nElement, const
     return 0;
 }
 
+void CondFormatContext::onEndElement()
+{
+    switch( getCurrentElement() )
+    {
+        case XLS_TOKEN( conditionalFormatting ):
+            if(mxCondFmt.get())
+                mxCondFmt->finalizeImport();
+            break;
+    }
+}
+
 void CondFormatContext::onStartElement( const AttributeList& rAttribs )
 {
     switch( getCurrentElement() )
@@ -191,6 +202,17 @@ void CondFormatContext::onStartRecord( SequenceInputStream& rStrm )
     }
 }
 
+void CondFormatContext::onEndRecord()
+{
+    switch( getCurrentElement() )
+    {
+        case BIFF12_ID_CONDFORMATTING:
+            if( mxCondFmt.get() )
+                mxCondFmt->finalizeImport();
+            break;
+    }
+}
+
 // ============================================================================
 
 } // namespace xls
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index cc2eb63..8094e0e 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -954,7 +954,6 @@ void WorksheetGlobals::finalizeWorksheetImport()
     finalizeHyperlinkRanges();
     finalizeValidationRanges();
     maAutoFilters.finalizeImport( getSheetIndex() );
-    maCondFormats.finalizeImport();
     maQueryTables.finalizeImport();
     maSheetSett.finalizeImport();
     maPageSett.finalizeImport();
commit e6c07ad2ed0e8b4d8ac140e369d0428c733f7662
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 20:50:00 2012 +0200

    copied color scale formulas also need to listen to the new document
    
    Change-Id: I2d642ba40454822e67a9c2c70f99d15459826f3b

diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index dd34efa..dda1b63 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -63,6 +63,7 @@ ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry&
     if(rEntry.mpCell)
     {
         mpCell.reset(static_cast<ScFormulaCell*>(rEntry.mpCell->Clone(*pDoc, SC_CLONECELL_NOMAKEABS_EXTERNAL)));
+        mpCell->StartListeningTo( pDoc );
     }
 }
 
commit 87956cb7154bd73ff30fc1169a656a4bc0fd78d3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 20:43:30 2012 +0200

    percent and percentile also are relative to the area values
    
    Change-Id: Ia4382cba061905cd7d2d029a26e28ec2b8ee884e

diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 1e5bfe0..dd34efa 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -298,7 +298,7 @@ double ScColorScaleFormat::GetMinValue() const
 {
     const_iterator itr = maColorScales.begin();
 
-    if(itr->GetType() != COLORSCALE_MIN && itr->GetType() != COLORSCALE_AUTOMIN)
+    if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
         return itr->GetValue();
     else
     {
@@ -310,7 +310,7 @@ double ScColorScaleFormat::GetMaxValue() const
 {
     ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
 
-    if(itr->GetType() != COLORSCALE_MAX && itr->GetType() != COLORSCALE_AUTOMAX)
+    if(itr->GetType() == COLORSCALE_VALUE || itr->GetType() == COLORSCALE_FORMULA)
         return itr->GetValue();
     else
     {
commit f6fdfc36bab69379970c39a596ba5cabf26e3744
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 13:16:25 2012 +0200

    don't use a reference parameter here
    
    Change-Id: Ia504de6fdc4a2ff6e764b13b5946e6e87ced3217

diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index 819b86a..a71332f 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -84,7 +84,7 @@ void ExtCfRuleContext::importDataBar( const AttributeList& rAttribs )
 
 namespace {
 
-::Color RgbToRgbComponents( sal_Int32& nRgb )
+::Color RgbToRgbComponents( sal_Int32 nRgb )
 {
     sal_Int32 ornR = (nRgb >> 16) & 0xFF;
     sal_Int32 ornG = (nRgb >> 8) & 0xFF;
commit 73a309c7fe9fa43a7fc5f23fb14b8fc97121b320
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 13:12:01 2012 +0200

    remove unused include
    
    Change-Id: Ib878c68066c40e3da9f1c90240649ea126d89d30

diff --git a/sc/source/filter/oox/extlstcontext.cxx b/sc/source/filter/oox/extlstcontext.cxx
index 740a841..819b86a 100644
--- a/sc/source/filter/oox/extlstcontext.cxx
+++ b/sc/source/filter/oox/extlstcontext.cxx
@@ -31,8 +31,6 @@
 #include <oox/core/contexthandler.hxx>
 #include "colorscale.hxx"
 
-#include <iostream>
-
 using ::oox::core::ContextHandlerRef;
 
 namespace oox {
commit e7aa05a50dbef1f93507ea0c725ad190d7adfe85
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 01:45:27 2012 +0200

    implement ODF import for AutoMin and AutoMax
    
    Change-Id: Idab366d7b3c800e7872bb64274215026bde27386

diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index d9b2fb9..5fc9051 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -443,6 +443,10 @@ void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry, co
         //position does not matter, only table is important
         pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
     }
+    else if(rType == "auto-minimum")
+        pEntry->SetType(COLORSCALE_AUTOMIN);
+    else if(rType == "auto-maximum")
+        pEntry->SetType(COLORSCALE_AUTOMAX);
 
     //TODO: add formulas
 }
commit 23b0e840364dc839642491663613a12f30ff6df0
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Aug 12 01:45:00 2012 +0200

    calculate percentile for upper data bar limit correctly
    
    Change-Id: Ie3faf8b15cfeb5a1a2e5df980e9ffbd8a3fcf756

diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 0cecc9f..1e5bfe0 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -701,7 +701,7 @@ double ScDataBarFormat::getMax(double nMin, double nMax) const
             return nMin + (nMax-nMin)/100*mpFormatData->mpUpperLimit->GetValue();
         case COLORSCALE_PERCENTILE:
         {
-            double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
+            double fPercentile = mpFormatData->mpUpperLimit->GetValue()/100.0;
             std::vector<double> aValues;
             getValues(aValues);
             return GetPercentile(aValues, fPercentile);
commit c467aa6f29a004b03c072bb89fa36b687daca9f3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 11 14:17:22 2012 +0200

    implement the ui part for AutoMin and AutoMax, related fdo#50462
    
    Change-Id: Ib7ad4801e56b879539e2b8446a58e011e0ea978c

diff --git a/sc/source/ui/condformat/colorformat.cxx b/sc/source/ui/condformat/colorformat.cxx
index 71f3bc7..77acc7d 100644
--- a/sc/source/ui/condformat/colorformat.cxx
+++ b/sc/source/ui/condformat/colorformat.cxx
@@ -91,6 +91,12 @@ void SetType(const ScColorScaleEntry* pEntry, ListBox& aLstBox)
         case COLORSCALE_VALUE:
             aLstBox.SelectEntryPos(4);
             break;
+        case COLORSCALE_AUTOMIN:
+            aLstBox.SelectEntryPos(6);
+            break;
+        case COLORSCALE_AUTOMAX:
+            aLstBox.SelectEntryPos(7);
+            break;
     }
 }
 
@@ -122,6 +128,13 @@ void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry,
             pEntry->SetValue(nVal);
             break;
         case 5:
+            //TODO: moggi
+            break;
+        case 6:
+            pEntry->SetType(COLORSCALE_AUTOMIN);
+            break;
+        case 7:
+            pEntry->SetType(COLORSCALE_AUTOMAX);
             break;
     }
 }
@@ -257,7 +270,6 @@ void GetAxesPosition(ScDataBarFormatData* pData, const ListBox& rLbox)
     }
 }
 
-
 }
 
 ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
@@ -281,9 +293,11 @@ IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
 {
     //check that min < max
     bool bWarn = false;
-    if(maLbTypeMin.GetSelectEntryPos() == 1)
+    sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
+    if( nSelectMin == 1 || nSelectMin == 7)
         bWarn = true;
-    if(maLbTypeMax.GetSelectEntryPos() == 0)
+    sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
+    if( nSelectMax == 0 || nSelectMax == 6 )
         bWarn = true;
 
     if(!bWarn && maLbTypeMin.GetSelectEntryPos() == maLbTypeMax.GetSelectEntryPos())
@@ -319,7 +333,7 @@ IMPL_LINK_NOARG( ScDataBarSettingsDlg, OkBtnHdl )
 IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
 {
     sal_Int32 nSelectMin = maLbTypeMin.GetSelectEntryPos();
-    if( nSelectMin == 0 || nSelectMin == 1)
+    if( nSelectMin == 0 || nSelectMin == 1 || nSelectMin == 6 || nSelectMin == 7)
         maEdMin.Disable();
     else
     {
@@ -334,7 +348,7 @@ IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
     }
 
     sal_Int32 nSelectMax = maLbTypeMax.GetSelectEntryPos();
-    if(nSelectMax == 0 || nSelectMax == 1)
+    if(nSelectMax == 0 || nSelectMax == 1 || nSelectMax == 6 || nSelectMax == 7)
         maEdMax.Disable();
     else
     {
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 21f33c8..387fb3e 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -81,8 +81,10 @@ void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType,
             rLbType.SelectEntryPos(3);
             break;
         case COLORSCALE_AUTOMIN:
+            rLbType.SelectEntryPos(6);
             break;
         case COLORSCALE_AUTOMAX:
+            rLbType.SelectEntryPos(7);
             break;
     }
     rLbCol.SelectEntry(rEntry.GetColor());
@@ -97,6 +99,7 @@ void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Ed
             break;
         case COLORSCALE_MAX:
             rLbType.SelectEntryPos(1);
+            break;
         case COLORSCALE_PERCENTILE:
             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
             rLbType.SelectEntryPos(2);
@@ -114,8 +117,10 @@ void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Ed
             rLbType.SelectEntryPos(3);
             break;
         case COLORSCALE_AUTOMIN:
+            rLbType.SelectEntryPos(6);
             break;
         case COLORSCALE_AUTOMAX:
+            rLbType.SelectEntryPos(7);
             break;
     }
 }
@@ -731,6 +736,12 @@ void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const
             pEntry->SetType(COLORSCALE_FORMULA);
             pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
             break;
+        case 6:
+            pEntry->SetType(COLORSCALE_AUTOMIN);
+            break;
+        case 7:
+            pEntry->SetType(COLORSCALE_AUTOMAX);
+            break;
         default:
             break;
     }
diff --git a/sc/source/ui/src/colorformat.src b/sc/source/ui/src/colorformat.src
index 58867c6..ce07fcb 100644
--- a/sc/source/ui/src/colorformat.src
+++ b/sc/source/ui/src/colorformat.src
@@ -140,6 +140,8 @@ ModalDialog RID_SCDLG_DATABAR
             "Percent";
             "Value";
             "Formula";
+            "AutoMin";
+            "AutoMax";
         };
     };
     ListBox LB_AXIS_POSITION
diff --git a/sc/source/ui/src/condformatdlg.src b/sc/source/ui/src/condformatdlg.src
index 12d4ef9..2800724 100644
--- a/sc/source/ui/src/condformatdlg.src
+++ b/sc/source/ui/src/condformatdlg.src
@@ -181,6 +181,8 @@ Control RID_COND_ENTRY
             "Value";
             "Percent";
             "Formula";
+            "AutoMin";
+            "AutoMax";
         };
     };
     Window WD_PREVIEW
commit 06aeaad3d1ec55dafe985642ef2b34beef384012
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 11 13:28:22 2012 +0200

    implement AutoMin and AutoMax, fdo#50462
    
    Change-Id: I73b2eb069bbb06d9b366b68d0ad85728df4d6a3a

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index f1b8d41..8e79385 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -49,7 +49,9 @@ enum ScColorScaleEntryType
     COLORSCALE_MAX,
     COLORSCALE_PERCENT,
     COLORSCALE_PERCENTILE,
-    COLORSCALE_FORMULA
+    COLORSCALE_FORMULA,
+    COLORSCALE_AUTOMIN,
+    COLORSCALE_AUTOMAX
 };
 
 class SC_DLLPUBLIC ScColorScaleEntry
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index e429068..0cecc9f 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -298,7 +298,7 @@ double ScColorScaleFormat::GetMinValue() const
 {
     const_iterator itr = maColorScales.begin();
 
-    if(itr->GetType() != COLORSCALE_MIN)
+    if(itr->GetType() != COLORSCALE_MIN && itr->GetType() != COLORSCALE_AUTOMIN)
         return itr->GetValue();
     else
     {
@@ -310,7 +310,7 @@ double ScColorScaleFormat::GetMaxValue() const
 {
     ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
 
-    if(itr->GetType() != COLORSCALE_MAX)
+    if(itr->GetType() != COLORSCALE_MAX && itr->GetType() != COLORSCALE_AUTOMAX)
         return itr->GetValue();
     else
     {
@@ -412,8 +412,12 @@ double ScColorScaleFormat::CalcValue(double nMin, double nMax, ScColorScaleForma
             return nMin + (nMax-nMin)*(itr->GetValue()/100);
         case COLORSCALE_MIN:
             return nMin;
+        case COLORSCALE_AUTOMIN:
+            return std::min<double>(0, nMin);
         case COLORSCALE_MAX:
             return nMax;
+        case COLORSCALE_AUTOMAX:
+            return std::max<double>(0, nMax);
         case COLORSCALE_PERCENTILE:
         {
             std::vector<double> aValues;
@@ -510,6 +514,8 @@ bool ScColorScaleFormat::CheckEntriesForRel(const ScRange& rRange) const
         {
             case COLORSCALE_MIN:
             case COLORSCALE_MAX:
+            case COLORSCALE_AUTOMIN:
+            case COLORSCALE_AUTOMAX:
                 bNeedUpdate = true;
                 break;
             case COLORSCALE_FORMULA:
@@ -616,6 +622,8 @@ bool NeedUpdate(ScColorScaleEntry* pEntry)
         case COLORSCALE_MIN:
         case COLORSCALE_MAX:
         case COLORSCALE_FORMULA:
+        case COLORSCALE_AUTOMIN:
+        case COLORSCALE_AUTOMAX:
             return true;
         default:
             return false;
@@ -660,6 +668,9 @@ double ScDataBarFormat::getMin(double nMin, double nMax) const
         case COLORSCALE_MIN:
             return nMin;
 
+        case COLORSCALE_AUTOMIN:
+            return std::min<double>(0, nMin);
+
         case COLORSCALE_PERCENT:
             return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
 
@@ -684,6 +695,8 @@ double ScDataBarFormat::getMax(double nMin, double nMax) const
     {
         case COLORSCALE_MAX:
             return nMax;
+        case COLORSCALE_AUTOMAX:
+            return std::max<double>(0, nMax);
         case COLORSCALE_PERCENT:
             return nMin + (nMax-nMin)/100*mpFormatData->mpUpperLimit->GetValue();
         case COLORSCALE_PERCENTILE:
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index e97829a..a9eaf1b 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3800,6 +3800,10 @@ rtl::OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry)
             return rtl::OUString("formula");
         case COLORSCALE_VALUE:
             return rtl::OUString("number");
+        case COLORSCALE_AUTOMIN:
+            return rtl::OUString("auto-minimum");
+        case COLORSCALE_AUTOMAX:
+            return rtl::OUString("auto-maximum");
     }
     return rtl::OUString();
 }
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index 6b4270a..21f33c8 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -80,6 +80,10 @@ void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType,
             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
             rLbType.SelectEntryPos(3);
             break;
+        case COLORSCALE_AUTOMIN:
+            break;
+        case COLORSCALE_AUTOMAX:
+            break;
     }
     rLbCol.SelectEntry(rEntry.GetColor());
 }
@@ -109,6 +113,10 @@ void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Ed
             rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
             rLbType.SelectEntryPos(3);
             break;
+        case COLORSCALE_AUTOMIN:
+            break;
+        case COLORSCALE_AUTOMAX:
+            break;
     }
 }
 
commit c6a8eb06027765640a5d1113866903454892d134
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sat Aug 11 13:02:48 2012 +0200

    use an enum instead of several flags
    
    Change-Id: I93c7483c6ba91671515025cc3b365a68c45a395c

diff --git a/sc/inc/colorscale.hxx b/sc/inc/colorscale.hxx
index 24aa2ea..f1b8d41 100644
--- a/sc/inc/colorscale.hxx
+++ b/sc/inc/colorscale.hxx
@@ -42,17 +42,24 @@ class ScFormulaCell;
 class ScTokenArray;
 struct ScDataBarInfo;
 
+enum ScColorScaleEntryType
+{
+    COLORSCALE_VALUE,
+    COLORSCALE_MIN,
+    COLORSCALE_MAX,
+    COLORSCALE_PERCENT,
+    COLORSCALE_PERCENTILE,
+    COLORSCALE_FORMULA
+};
+
 class SC_DLLPUBLIC ScColorScaleEntry
 {
 private:
     double mnVal;
     Color maColor;
     boost::scoped_ptr<ScFormulaCell> mpCell;
+    ScColorScaleEntryType meType;
 
-    bool mbMin;
-    bool mbMax;
-    bool mbPercent;
-    bool mbPercentile;
 public:
     ScColorScaleEntry(double nVal, const Color& rCol);
     ScColorScaleEntry();
@@ -69,19 +76,11 @@ public:
     void UpdateReference( UpdateRefMode eUpdateRefMode,
             const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
 
-    bool GetMin() const;
-    bool GetMax() const;
-    bool GetPercent() const;
-    bool GetPercentile() const;
-    bool HasFormula() const;
     const ScTokenArray* GetFormula() const;
     rtl::OUString GetFormula( formula::FormulaGrammar::Grammar eGrammar ) const;
-    void SetMin(bool bMin);
-    void SetMax(bool bMax);
-    void SetPercent(bool bPercent);
-    void SetPercentile(bool bPercentile);
 
-    void SetHasValue();
+    ScColorScaleEntryType GetType() const;
+    void SetType( ScColorScaleEntryType eType );
 };
 
 namespace databar
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx
index 38f061a..e429068 100644
--- a/sc/source/core/data/colorscale.cxx
+++ b/sc/source/core/data/colorscale.cxx
@@ -34,10 +34,7 @@
 ScColorScaleEntry::ScColorScaleEntry():
     mnVal(0),
     mpCell(NULL),
-    mbMin(false),
-    mbMax(false),
-    mbPercent(false),
-    mbPercentile(false)
+    meType(COLORSCALE_VALUE)
 {
 }
 
@@ -45,10 +42,7 @@ ScColorScaleEntry::ScColorScaleEntry(double nVal, const Color& rCol):
     mnVal(nVal),
     maColor(rCol),
     mpCell(NULL),
-    mbMin(false),
-    mbMax(false),
-    mbPercent(false),
-    mbPercentile(false)
+    meType(COLORSCALE_VALUE)
 {
 }
 
@@ -56,10 +50,7 @@ ScColorScaleEntry::ScColorScaleEntry(const ScColorScaleEntry& rEntry):
     mnVal(rEntry.mnVal),
     maColor(rEntry.maColor),
     mpCell(),
-    mbMin(rEntry.mbMin),
-    mbMax(rEntry.mbMax),
-    mbPercent(rEntry.mbPercent),
-    mbPercentile(rEntry.mbPercentile)
+    meType(rEntry.meType)
 {
 }
 
@@ -67,10 +58,7 @@ ScColorScaleEntry::ScColorScaleEntry(ScDocument* pDoc, const ScColorScaleEntry&
     mnVal(rEntry.mnVal),
     maColor(rEntry.maColor),
     mpCell(),
-    mbMin(rEntry.mbMin),
-    mbMax(rEntry.mbMax),
-    mbPercent(rEntry.mbPercent),
-    mbPercentile(rEntry.mbPercentile)
+    meType(rEntry.meType)
 {
     if(rEntry.mpCell)
     {
@@ -197,58 +185,16 @@ void ScColorScaleFormat::AddEntry( ScColorScaleEntry* pEntry )
     maColorScales.push_back( pEntry );
 }
 
-bool ScColorScaleEntry::GetMin() const
+void ScColorScaleEntry::SetType( ScColorScaleEntryType eType )
 {
-    return mbMin;
+    meType = eType;
+    if(eType != COLORSCALE_FORMULA)
+        mpCell.reset();
 }
 
-bool ScColorScaleEntry::GetMax() const
+ScColorScaleEntryType ScColorScaleEntry::GetType() const
 {
-    return mbMax;
-}
-
-bool ScColorScaleEntry::GetPercent() const
-{
-    return mbPercent;
-}
-
-bool ScColorScaleEntry::GetPercentile() const
-{
-    return mbPercentile;
-}
-
-bool ScColorScaleEntry::HasFormula() const
-{
-    return mpCell;
-}
-
-void ScColorScaleEntry::SetMin(bool bMin)
-{
-    mbMin = bMin;
-}
-
-void ScColorScaleEntry::SetMax(bool bMax)
-{
-    mbMax = bMax;
-}
-
-void ScColorScaleEntry::SetPercent(bool bPercent)
-{
-    mbPercent = bPercent;
-}
-
-void ScColorScaleEntry::SetPercentile(bool bPercentile)
-{
-    mbPercentile = bPercentile;
-}
-
-void ScColorScaleEntry::SetHasValue()
-{
-    mbPercentile = false;
-    mbPercent = false;
-    mbMin = false;
-    mbMax = false;
-    mpCell.reset();
+    return meType;
 }
 
 namespace {
@@ -352,7 +298,7 @@ double ScColorScaleFormat::GetMinValue() const
 {
     const_iterator itr = maColorScales.begin();
 
-    if(!itr->GetMin())
+    if(itr->GetType() != COLORSCALE_MIN)
         return itr->GetValue();
     else
     {
@@ -364,7 +310,7 @@ double ScColorScaleFormat::GetMaxValue() const
 {
     ColorScaleEntries::const_reverse_iterator itr = maColorScales.rbegin();
 
-    if(!itr->GetMax())
+    if(itr->GetType() != COLORSCALE_MAX)
         return itr->GetValue();
     else
     {
@@ -460,29 +406,29 @@ double GetPercentile( std::vector<double>& rArray, double fPercentile )
 
 double ScColorScaleFormat::CalcValue(double nMin, double nMax, ScColorScaleFormat::const_iterator& itr) const
 {
-    if(itr->GetPercent())
-    {
-        return nMin + (nMax-nMin)*(itr->GetValue()/100);
-    }
-    else if(itr->GetMin())
-    {
-        return nMin;
-    }
-    else if(itr->GetMax())
+    switch(itr->GetType())
     {
-        return nMax;
-    }
-    else if(itr->GetPercentile())
-    {
-        std::vector<double> aValues;
-        getValues(aValues);
-        if(aValues.size() == 1)
-            return aValues[0];
-        else
+        case COLORSCALE_PERCENT:
+            return nMin + (nMax-nMin)*(itr->GetValue()/100);
+        case COLORSCALE_MIN:
+            return nMin;
+        case COLORSCALE_MAX:
+            return nMax;
+        case COLORSCALE_PERCENTILE:
         {
-            double fPercentile = itr->GetValue()/100.0;
-            return GetPercentile(aValues, fPercentile);
+            std::vector<double> aValues;
+            getValues(aValues);
+            if(aValues.size() == 1)
+                return aValues[0];
+            else
+            {
+                double fPercentile = itr->GetValue()/100.0;
+                return GetPercentile(aValues, fPercentile);
+            }
         }
+
+        default:
+        break;
     }
 
     return itr->GetValue();
@@ -559,14 +505,18 @@ bool ScColorScaleFormat::CheckEntriesForRel(const ScRange& rRange) const
     bool bNeedUpdate = false;
     for(const_iterator itr = begin(); itr != end(); ++itr)
     {
-        if(itr->GetMin() || itr->GetMax())
+        ScColorScaleEntryType eType = itr->GetType();
+        switch(eType)
         {
-            bNeedUpdate = true;
-            break;
+            case COLORSCALE_MIN:
+            case COLORSCALE_MAX:
+                bNeedUpdate = true;
+                break;
+            case COLORSCALE_FORMULA:
+                return true;
+            default:
+                break;
         }
-
-        if(itr->HasFormula())
-            return true;
     }
 
     // TODO: check also if the changed value is the new min/max
@@ -661,14 +611,15 @@ namespace {
 
 bool NeedUpdate(ScColorScaleEntry* pEntry)
 {
-    if(pEntry->GetMin())
-        return true;
-
-    if(pEntry->GetMax())
-        return true;
-
-    if(pEntry->GetFormula())
-        return true;
+    switch(pEntry->GetType())
+    {
+        case COLORSCALE_MIN:
+        case COLORSCALE_MAX:
+        case COLORSCALE_FORMULA:
+            return true;
+        default:
+            return false;
+    }
 
     return false;
 }
@@ -704,16 +655,24 @@ void ScDataBarFormat::UpdateMoveTab(SCTAB nOldTab, SCTAB nNewTab)
 
 double ScDataBarFormat::getMin(double nMin, double nMax) const
 {
-    if(mpFormatData->mpLowerLimit->GetMin())
-        return nMin;
-    else if(mpFormatData->mpLowerLimit->GetPercent())
-        return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
-    else if(mpFormatData->mpLowerLimit->GetPercentile())
+    switch(mpFormatData->mpLowerLimit->GetType())
     {
-        double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
-        std::vector<double> aValues;
-        getValues(aValues);
-        return GetPercentile(aValues, fPercentile);
+        case COLORSCALE_MIN:
+            return nMin;
+
+        case COLORSCALE_PERCENT:
+            return nMin + (nMax-nMin)/100*mpFormatData->mpLowerLimit->GetValue();
+
+        case COLORSCALE_PERCENTILE:
+        {
+            double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
+            std::vector<double> aValues;
+            getValues(aValues);
+            return GetPercentile(aValues, fPercentile);
+        }
+
+        default:
+        break;
     }
 
     return mpFormatData->mpLowerLimit->GetValue();
@@ -721,16 +680,22 @@ double ScDataBarFormat::getMin(double nMin, double nMax) const
 
 double ScDataBarFormat::getMax(double nMin, double nMax) const
 {
-    if(mpFormatData->mpUpperLimit->GetMax())
-        return nMax;
-    else if(mpFormatData->mpUpperLimit->GetPercent())
-        return nMin + (nMax-nMin)/100*mpFormatData->mpUpperLimit->GetValue();
-    else if(mpFormatData->mpLowerLimit->GetPercentile())
+    switch(mpFormatData->mpUpperLimit->GetType())
     {
-        double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
-        std::vector<double> aValues;
-        getValues(aValues);
-        return GetPercentile(aValues, fPercentile);
+        case COLORSCALE_MAX:
+            return nMax;
+        case COLORSCALE_PERCENT:
+            return nMin + (nMax-nMin)/100*mpFormatData->mpUpperLimit->GetValue();
+        case COLORSCALE_PERCENTILE:
+        {
+            double fPercentile = mpFormatData->mpLowerLimit->GetValue()/100.0;
+            std::vector<double> aValues;
+            getValues(aValues);
+            return GetPercentile(aValues, fPercentile);
+        }
+
+        default:
+            break;
     }
 
     return mpFormatData->mpUpperLimit->GetValue();
@@ -797,9 +762,9 @@ ScDataBarInfo* ScDataBarFormat::GetDataBarInfo(const ScAddress& rAddr) const
 
             // if max or min is used we may need to adjust it
             // for the length calculation
-            if (mpFormatData->mpLowerLimit->GetMin() && nMin > 0)
+            if (mpFormatData->mpLowerLimit->GetType() == COLORSCALE_MIN && nMin > 0)
                 nMinPositive = nMin;
-            if (mpFormatData->mpUpperLimit->GetMax() && nMax < 0)
+            if (mpFormatData->mpUpperLimit->GetType() == COLORSCALE_MAX && nMax < 0)
                 nMaxNegative = nMax;
         }
         else if( mpFormatData->meAxisPosition == databar::MIDDLE)
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index bc7445b..0c28a59 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -898,14 +898,19 @@ namespace {
 
 rtl::OString getColorScaleType( const ScColorScaleEntry& rEntry )
 {
-    if (rEntry.GetMin())
-        return "min";
-    if(rEntry.GetMax())
-        return "max";
-    if(rEntry.GetPercent())
-        return "percent";
-    if(rEntry.HasFormula())
-        return "formula";
+    switch(rEntry.GetType())
+    {
+        case COLORSCALE_MIN:
+            return "min";
+        case COLORSCALE_MAX:
+            return "max";
+        case COLORSCALE_PERCENT:
+            return "percent";
+        case COLORSCALE_FORMULA:
+            return "formula";
+        default:
+            break;
+    }
 
     return "num";
 }
@@ -917,7 +922,7 @@ void XclExpCfvo::SaveXml( XclExpXmlStream& rStrm )
     sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
 
     rtl::OString aValue;
-    if(mrEntry.HasFormula())
+    if(mrEntry.GetType() == COLORSCALE_FORMULA)
     {
         rtl::OUString aFormula = XclXmlUtils::ToOUString( GetRoot().GetDoc(), maSrcPos, mrEntry.GetFormula()->Clone() );
         aValue = rtl::OUStringToOString(aFormula, RTL_TEXTENCODING_UTF8 );
diff --git a/sc/source/filter/oox/condformatbuffer.cxx b/sc/source/filter/oox/condformatbuffer.cxx
index b110df2..03d9ba1 100644
--- a/sc/source/filter/oox/condformatbuffer.cxx
+++ b/sc/source/filter/oox/condformatbuffer.cxx
@@ -232,16 +232,19 @@ ScColorScaleEntry* ConvertToModel( const ColorScaleRuleModelEntry& rEntry, ScDoc
         ScColorScaleEntry* pEntry = new ScColorScaleEntry(rEntry.mnVal, rEntry.maColor);
 
         if(rEntry.mbMin)
-            pEntry->SetMin(true);
+            pEntry->SetType(COLORSCALE_MIN);
         if(rEntry.mbMax)
-            pEntry->SetMax(true);
+            pEntry->SetType(COLORSCALE_MAX);
         if(rEntry.mbPercent)
-            pEntry->SetPercent(true);
+            pEntry->SetType(COLORSCALE_PERCENT);
         if(rEntry.mbPercentile)
-            pEntry->SetPercentile(true);
+            pEntry->SetType(COLORSCALE_PERCENTILE);
 
         if(!rEntry.maFormula.isEmpty())
+        {
+            pEntry->SetType(COLORSCALE_FORMULA);
             pEntry->SetFormula(rEntry.maFormula, pDoc, rAddr, formula::FormulaGrammar::GRAM_ENGLISH_XL_A1);
+        }
 
         return pEntry;
 }
diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx
index 636e76a..d9b2fb9 100644
--- a/sc/source/filter/xml/xmlcondformat.cxx
+++ b/sc/source/filter/xml/xmlcondformat.cxx
@@ -430,15 +430,16 @@ void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry, co
         ScXMLImport& rImport)
 {
     if(rType == "minimum")
-        pEntry->SetMin(true);
+        pEntry->SetType(COLORSCALE_MIN);
     else if(rType == "maximum")
-        pEntry->SetMax(true);
+        pEntry->SetType(COLORSCALE_MAX);
     else if(rType == "percentile")
-        pEntry->SetPercentile(true);
+        pEntry->SetType(COLORSCALE_PERCENTILE);
     else if(rType == "percent")
-        pEntry->SetPercent(true);
+        pEntry->SetType(COLORSCALE_PERCENT);
     else if(rType == "formula")
     {
+        pEntry->SetType(COLORSCALE_FORMULA);
         //position does not matter, only table is important
         pEntry->SetFormula(rFormula, rImport.GetDocument(), ScAddress(0,0,rImport.GetTables().GetCurrentSheet()), formula::FormulaGrammar::GRAM_ODFF);
     }
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index a3c769d..e97829a 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3786,18 +3786,22 @@ namespace {
 
 rtl::OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry)
 {
-    if(rEntry.GetMin())
-        return rtl::OUString("minimum");
-    else if(rEntry.GetMax())
-        return rtl::OUString("maximum");
-    else if(rEntry.GetPercent())
-        return rtl::OUString("percent");
-    else if(rEntry.GetPercentile())
-        return rtl::OUString("percentile");
-    else if(rEntry.GetFormula())
-        return rtl::OUString("formula");
-    else
-        return rtl::OUString("number");
+    switch(rEntry.GetType())
+    {
+        case COLORSCALE_MIN:
+            return rtl::OUString("minimum");
+        case COLORSCALE_MAX:
+            return rtl::OUString("maximum");
+        case COLORSCALE_PERCENT:
+            return rtl::OUString("percent");
+        case COLORSCALE_PERCENTILE:
+            return rtl::OUString("percentile");
+        case COLORSCALE_FORMULA:
+            return rtl::OUString("formula");
+        case COLORSCALE_VALUE:
+            return rtl::OUString("number");
+    }
+    return rtl::OUString();
 }
 
 }
@@ -3901,7 +3905,7 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
                         for(ScColorScaleFormat::const_iterator it = mrColorScale.begin();
                                 it != mrColorScale.end(); ++it)
                         {
-                            if(it->HasFormula())
+                            if(it->GetType() == COLORSCALE_FORMULA)
                             {
                                 rtl::OUString sFormula = it->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
                                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
@@ -3962,7 +3966,7 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
                         SvXMLElementExport aElementDataBar(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_BAR, true, true);
 
                         {
-                            if(pFormatData->mpLowerLimit->HasFormula())
+                            if(pFormatData->mpLowerLimit->GetType() == COLORSCALE_FORMULA)
                             {
                                 rtl::OUString sFormula = pFormatData->mpLowerLimit->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
                                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
@@ -3974,7 +3978,7 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab)
                         }
 
                         {
-                            if(pFormatData->mpUpperLimit->HasFormula())
+                            if(pFormatData->mpUpperLimit->GetType() == COLORSCALE_FORMULA)
                             {
                                 rtl::OUString sFormula = pFormatData->mpUpperLimit->GetFormula(formula::FormulaGrammar::GRAM_ODFF);
                                 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula);
diff --git a/sc/source/ui/condformat/colorformat.cxx b/sc/source/ui/condformat/colorformat.cxx
index daa14a8..71f3bc7 100644
--- a/sc/source/ui/condformat/colorformat.cxx
+++ b/sc/source/ui/condformat/colorformat.cxx
@@ -71,18 +71,27 @@ namespace {
 
 void SetType(const ScColorScaleEntry* pEntry, ListBox& aLstBox)
 {
-    if(pEntry->GetMin())
-        aLstBox.SelectEntryPos(0);
-    else if(pEntry->GetMax())
-        aLstBox.SelectEntryPos(1);
-    else if(pEntry->GetPercentile())
-        aLstBox.SelectEntryPos(2);
-    else if(pEntry->GetPercent())
-        aLstBox.SelectEntryPos(3);
-    else if(pEntry->HasFormula())
-        aLstBox.SelectEntryPos(5);
-    else
-        aLstBox.SelectEntryPos(4);
+    switch(pEntry->GetType())
+    {
+        case COLORSCALE_MIN:
+            aLstBox.SelectEntryPos(0);
+            break;
+        case COLORSCALE_MAX:
+            aLstBox.SelectEntryPos(1);
+            break;
+        case COLORSCALE_PERCENTILE:
+            aLstBox.SelectEntryPos(2);
+            break;
+        case COLORSCALE_PERCENT:
+            aLstBox.SelectEntryPos(3);
+            break;
+        case COLORSCALE_FORMULA:
+            aLstBox.SelectEntryPos(5);
+            break;
+        case COLORSCALE_VALUE:
+            aLstBox.SelectEntryPos(4);
+            break;
+    }
 }
 
 void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry, SvNumberFormatter* pNumberFormatter )
@@ -92,24 +101,24 @@ void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry,
     switch(rLstBox.GetSelectEntryPos())
     {
         case 0:
-            pEntry->SetMin(true);
+            pEntry->SetType(COLORSCALE_MIN);
             break;
         case 1:
-            pEntry->SetMax(true);
+            pEntry->SetType(COLORSCALE_MAX);
             break;
         case 2:
-            pEntry->SetPercentile(true);
+            pEntry->SetType(COLORSCALE_PERCENTILE);
             pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
             pEntry->SetValue(nVal);
             break;
         case 3:
-            pEntry->SetPercent(true);
+            pEntry->SetType(COLORSCALE_PERCENT);
             pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
             pEntry->SetValue(nVal);
             break;
         case 4:
             pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
-            pEntry->SetHasValue();
+            pEntry->SetType(COLORSCALE_VALUE);
             pEntry->SetValue(nVal);
             break;
         case 5:
@@ -119,9 +128,9 @@ void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry,
 
 void SetValue( ScColorScaleEntry* pEntry, Edit& aEdit)
 {
-    if(pEntry->HasFormula())
+    if(pEntry->GetType() == COLORSCALE_FORMULA)
         aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
-    else if(!pEntry->GetMin() && !pEntry->GetMax())
+    else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
         aEdit.SetText(rtl::OUString::valueOf(pEntry->GetValue()));
     else
         aEdit.Disable();
diff --git a/sc/source/ui/condformat/condformatdlg.cxx b/sc/source/ui/condformat/condformatdlg.cxx
index cd850ac..6b4270a 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -56,58 +56,59 @@ namespace {
 
 void SetColorScaleEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit, ColorListBox& rLbCol )
 {
-    if(rEntry.GetMin())
-        rLbType.SelectEntryPos(0);
-    else if(rEntry.GetMax())
-        rLbType.SelectEntryPos(1);
-    else if(rEntry.GetPercentile())
+    switch(rEntry.GetType())
     {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(2);
-    }
-    else if(rEntry.GetPercent())
-    {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(4);
-    }
-    else if(rEntry.HasFormula())
-    {
-        rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
-        rLbType.SelectEntryPos(5);
-    }
-    else
-    {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(3);
+        case COLORSCALE_MIN:
+            rLbType.SelectEntryPos(0);
+            break;
+        case COLORSCALE_MAX:
+            rLbType.SelectEntryPos(1);
+            break;
+        case COLORSCALE_PERCENTILE:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(2);
+            break;
+        case COLORSCALE_PERCENT:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(4);
+            break;
+        case COLORSCALE_FORMULA:
+            rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
+            rLbType.SelectEntryPos(5);
+            break;
+        case COLORSCALE_VALUE:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(3);
+            break;
     }
     rLbCol.SelectEntry(rEntry.GetColor());
 }
 
 void SetDataBarEntryTypes( const ScColorScaleEntry& rEntry, ListBox& rLbType, Edit& rEdit )
 {
-    if(rEntry.GetMin())
-        rLbType.SelectEntryPos(0);
-    else if(rEntry.GetMax())
-        rLbType.SelectEntryPos(1);
-    else if(rEntry.GetPercentile())
+    switch(rEntry.GetType())
     {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(2);
-    }
-    else if(rEntry.GetPercent())
-    {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(4);
-    }
-    else if(rEntry.HasFormula())
-    {
-        rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
-        rLbType.SelectEntryPos(5);
-    }
-    else
-    {
-        rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
-        rLbType.SelectEntryPos(3);
+        case COLORSCALE_MIN:
+            rLbType.SelectEntryPos(0);
+            break;
+        case COLORSCALE_MAX:
+            rLbType.SelectEntryPos(1);
+        case COLORSCALE_PERCENTILE:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(2);
+            break;
+        case COLORSCALE_PERCENT:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(4);
+            break;
+        case COLORSCALE_FORMULA:
+            rEdit.SetText(rEntry.GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
+            rLbType.SelectEntryPos(5);
+            break;
+        case COLORSCALE_VALUE:
+            rEdit.SetText(rtl::OUString::valueOf(rEntry.GetValue()));
+            rLbType.SelectEntryPos(3);
+            break;
     }
 }
 
@@ -403,8 +404,8 @@ void ScCondFrmtEntry::Init()
     mpDataBarData.reset(new ScDataBarFormatData());
     mpDataBarData->mpUpperLimit.reset(new ScColorScaleEntry());
     mpDataBarData->mpLowerLimit.reset(new ScColorScaleEntry());
-    mpDataBarData->mpLowerLimit->SetMin(true);
-    mpDataBarData->mpUpperLimit->SetMax(true);
+    mpDataBarData->mpLowerLimit->SetType(COLORSCALE_MIN);
+    mpDataBarData->mpUpperLimit->SetType(COLORSCALE_MAX);
     mpDataBarData->maPositiveColor = COL_LIGHTBLUE;
 }
 
@@ -702,24 +703,24 @@ void SetColorScaleEntry( ScColorScaleEntry* pEntry, const ListBox& rType, const
     switch(rType.GetSelectEntryPos())
     {
         case 0:
-            pEntry->SetMin(true);
+            pEntry->SetType(COLORSCALE_MIN);
             break;
         case 1:
-            pEntry->SetMax(true);
+            pEntry->SetType(COLORSCALE_MAX);
             break;
         case 2:
-            pEntry->SetPercentile(true);
+            pEntry->SetType(COLORSCALE_PERCENTILE);
             pEntry->SetValue(nVal);
             break;
         case 3:
-            pEntry->SetValue(nVal);
-            pEntry->SetHasValue();
+            pEntry->SetType(COLORSCALE_VALUE);
             break;
         case 4:
-            pEntry->SetPercent(true);
+            pEntry->SetType(COLORSCALE_PERCENT);
             pEntry->SetValue(nVal);
             break;
         case 5:
+            pEntry->SetType(COLORSCALE_FORMULA);
             pEntry->SetFormula(rValue.GetText(), pDoc, rPos);
             break;
         default:


More information about the Libreoffice-commits mailing list