Commits

Anonymous committed d75ea4d

calcdatatables: create and use style sheets according to properties; fine tuned header and total row style usage

Comments (0)

Files changed (2)

sc/inc/datatablestyle.hxx

             FIRST_COL,
             LAST_COL,
             HEADER_ROW,
-            TOTAL_ROW,
             FIRST_HEADER_CELL,
             LAST_HEADER_CELL,
+            TOTAL_ROW,
             FIRST_TOTAL_CELL,
             LAST_TOTAL_CELL,
             OUTSIDE,
         const String&               GetStyleName( StyleType eType ) const;
         SfxStyleSheetBase*          GetStyleSheet( StyleType eType ) const;
 
+        /** Create all necessary styles if they aren't set already and don't 
+            exist already and set them.
+
+            Which styles are created depends on properties (mbBandedRows, 
+            mbBandedCols, ...) to not bloat the Stylist with unnecessary 
+            entries.
+
+            @param rPrefix
+                   Prefix to be used for style names to form "Prefix_...".
+
+            @returns Vector of newly created style names with offsets == StyleType.
+         */
+        ::std::vector<String>       CreateAndSetStyles( const String& rPrefix );
+
         void                        SetTableRange( const ScRange& rRange )  { maRange = rRange; }
         void                        SetHeaderRowFlag( bool bVal )   { mbHeaderRow = bVal; }
         void                        SetTotalRowFlag( bool bVal )    { mbTotalRow = bVal; }

sc/source/core/data/datatablestyle.cxx

 #include "stlpool.hxx"
 #include "refupdat.hxx"
 #include "stlsheet.hxx"
+#include "global.hxx"
+#include "globstr.hrc"
 
 #include <memory.h>
 
 }
 
 
-ScDataTableFormat::StyleType ScDataTableFormat::GetStyleType( const ScAddress& rPos  ) const
+ScDataTableFormat::StyleType ScDataTableFormat::GetStyleType( const ScAddress& rPos ) const
 {
     if (!maRange.In( rPos))
         return OUTSIDE;
 
+    if (mbHeaderRow && rPos.Row() == maRange.aStart.Row())
+    {
+        // Precedence:
+        // 1. first/last header cell
+        // 2. header row
+        // 3. first/last column
+        // 4. whole table
+        // NO banded rows or columns
+        const StyleType eRow = (maStyleName[HEADER_ROW].Len() ? HEADER_ROW : WHOLE_TABLE);
+        if (rPos.Col() == maRange.aStart.Col())
+        {
+            if (maStyleName[FIRST_HEADER_CELL].Len())
+                return FIRST_HEADER_CELL;
+            if (eRow == WHOLE_TABLE && mbFirstCol && maStyleName[FIRST_COL].Len())
+                return FIRST_COL;
+        }
+        else if (rPos.Col() == maRange.aEnd.Col())
+        {
+            if (maStyleName[LAST_HEADER_CELL].Len())
+                return LAST_HEADER_CELL;
+            if (eRow == WHOLE_TABLE && mbLastCol && maStyleName[LAST_COL].Len())
+                return FIRST_COL;
+        }
+        return eRow;
+    }
     if (mbTotalRow && rPos.Row() == maRange.aEnd.Row())
     {
+        // Precedence:
+        // 1. first/last total cell
+        // 2. total row
+        // 3. first/last column
+        // 4. whole table
+        // NO banded rows or columns
+        const StyleType eRow = (maStyleName[TOTAL_ROW].Len() ? TOTAL_ROW : WHOLE_TABLE);
         if (rPos.Col() == maRange.aStart.Col())
         {
             if (maStyleName[FIRST_TOTAL_CELL].Len())
                 return FIRST_TOTAL_CELL;
-            if (maStyleName[FIRST_COL].Len())
+            if (eRow == WHOLE_TABLE && mbFirstCol && maStyleName[FIRST_COL].Len())
                 return FIRST_COL;
         }
         else if (rPos.Col() == maRange.aEnd.Col())
         {
             if (maStyleName[LAST_TOTAL_CELL].Len())
                 return LAST_TOTAL_CELL;
-            if (maStyleName[LAST_COL].Len())
+            if (eRow == WHOLE_TABLE && mbLastCol && maStyleName[LAST_COL].Len())
                 return LAST_COL;
         }
-        if (maStyleName[TOTAL_ROW].Len())
-            return TOTAL_ROW;
-        return WHOLE_TABLE;
-    }
-    if (mbHeaderRow && rPos.Row() == maRange.aStart.Row())
-    {
-        if (rPos.Col() == maRange.aStart.Col())
-        {
-            if (maStyleName[FIRST_HEADER_CELL].Len())
-                return FIRST_HEADER_CELL;
-            if (maStyleName[FIRST_COL].Len())
-                return FIRST_COL;
-        }
-        else if (rPos.Col() == maRange.aEnd.Col())
-        {
-            if (maStyleName[LAST_HEADER_CELL].Len())
-                return LAST_HEADER_CELL;
-            if (maStyleName[LAST_COL].Len())
-                return LAST_COL;
-        }
-        if (maStyleName[HEADER_ROW].Len())
-            return HEADER_ROW;
-        return WHOLE_TABLE;
+        return eRow;
     }
     if (mbFirstCol && rPos.Col() == maRange.aStart.Col() && maStyleName[FIRST_COL].Len())
         return FIRST_COL;
     if (mbBandedRows)
     {
         SCROW nRow = rPos.Row();
-        const SCROW nStartRow = maRange.aStart.Row();
+        const SCROW nStartRow = (mbHeaderRow ? maRange.aStart.Row() + 1 : maRange.aStart.Row());
         if (mpDoc->HasHiddenRows( nStartRow, nRow, maRange.aStart.Tab()))
         {
             // Hidden or filtered, use visible area.
 }
 
 
+::std::vector<String> ScDataTableFormat::CreateAndSetStyles( const String& rPrefix )
+{
+    ::std::vector<String> aNames( STYLE_COUNT);
+    ScStyleSheetPool* pStyleSheetPool = mpDoc->GetStyleSheetPool();
+    for (size_t i=0; i < STYLE_COUNT; ++i)
+    {
+        if (maStyleName[i].Len())
+            continue;
+
+        String aName( rPrefix);
+        aName += '_';
+        if (i <= 9)
+            aName += '0';
+        aName += String::CreateFromInt32(i);
+        aName += '_';
+        bool bSet = false;
+        switch (i)
+        {
+            /* FIXME: obtain names from localizable resource strings. */
+            case WHOLE_TABLE:
+                aName += String( RTL_CONSTASCII_USTRINGPARAM( "whole_table"));
+                bSet = true;
+                break;
+            case COL_STRIPE_1:
+                if (mbBandedCols)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "col_stripe_1"));
+                    bSet = true;
+                }
+                break;
+            case COL_STRIPE_2:
+                if (mbBandedCols)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "col_stripe_2"));
+                    bSet = true;
+                }
+                break;
+            case ROW_STRIPE_1:
+                if (mbBandedRows)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "row_stripe_1"));
+                    bSet = true;
+                }
+                break;
+            case ROW_STRIPE_2:
+                if (mbBandedRows)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "row_stripe_2"));
+                    bSet = true;
+                }
+                break;
+            case FIRST_COL:
+                if (mbFirstCol)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "first_col"));
+                    bSet = true;
+                }
+                break;
+            case LAST_COL:
+                if (mbLastCol)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "last_col"));
+                    bSet = true;
+                }
+                break;
+            case HEADER_ROW:
+                if (mbHeaderRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "header_row"));
+                    bSet = true;
+                }
+                break;
+            case FIRST_HEADER_CELL:
+                if (mbHeaderRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "first_header_cell"));
+                    bSet = true;
+                }
+                break;
+            case LAST_HEADER_CELL:
+                if (mbHeaderRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "last_header_cell"));
+                    bSet = true;
+                }
+                break;
+            case TOTAL_ROW:
+                if (mbTotalRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "total_row"));
+                    bSet = true;
+                }
+                break;
+            case FIRST_TOTAL_CELL:
+                if (mbTotalRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "first_total_cell"));
+                    bSet = true;
+                }
+                break;
+            case LAST_TOTAL_CELL:
+                if (mbTotalRow)
+                {
+                    aName += String( RTL_CONSTASCII_USTRINGPARAM( "last_total_cell"));
+                    bSet = true;
+                }
+                break;
+            case OUTSIDE:
+#if OSL_DEBUG_LEVEL > 1
+                // Outside style can be used to visualize invalid attribution 
+                // during cut/copy/paste/insert/delete/..., e.g. set to grey 
+                // background.
+                aName += String( RTL_CONSTASCII_USTRINGPARAM( "outside"));
+                bSet = true;
+#endif
+                break;
+        }
+        if (bSet)
+        {
+            SetStyleName( static_cast<StyleType>(i), aName);
+            ScStyleSheet* pStyle = static_cast<ScStyleSheet*>( 
+                    pStyleSheetPool->Find( aName, SFX_STYLE_FAMILY_PARA));
+            if (!pStyle)
+            {
+                aNames[i] = aName;
+                pStyle = &static_cast<ScStyleSheet&>( pStyleSheetPool->Make( 
+                            aName, SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_USERDEF));
+                //! Setting parents depends on order of enums!
+                switch (i)
+                {
+                    case WHOLE_TABLE:
+                        pStyle->SetParent( ScGlobal::GetRscString( STR_STYLENAME_STANDARD));
+                        break;
+                    case COL_STRIPE_1:
+                    case COL_STRIPE_2:
+                    case ROW_STRIPE_1:
+                    case ROW_STRIPE_2:
+                    case FIRST_COL:
+                    case LAST_COL:
+                    case HEADER_ROW:
+                    case TOTAL_ROW:
+                        pStyle->SetParent( maStyleName[WHOLE_TABLE]);
+                        break;
+                    case FIRST_HEADER_CELL:
+                    case LAST_HEADER_CELL:
+                        pStyle->SetParent( maStyleName[HEADER_ROW]);
+                        break;
+                    case FIRST_TOTAL_CELL:
+                    case LAST_TOTAL_CELL:
+                        pStyle->SetParent( maStyleName[TOTAL_ROW]);
+                        break;
+                    case OUTSIDE:
+                        pStyle->SetParent( ScGlobal::GetRscString( STR_STYLENAME_STANDARD));
+                        break;
+                }
+            }
+        }
+    }
+    return aNames;
+}
+
+
+// === ScDataTableFormatList =================================================
+
 void ScDataTableFormatList::UpdateReference( UpdateRefMode eUpdateRefMode,
                                 const ScRange& rRange, SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
 {