summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkash Shetye <shetyeakash@gmail.com>2013-08-19 07:59:01 +0530
committerAkash Shetye <shetyeakash@gmail.com>2013-08-19 07:59:01 +0530
commit5085cff67f055ca8f9ea540873962567702aff69 (patch)
tree6c4e40045dc4d8965e33a2325e2fa5113a7b8cfc
parentc3a6f0390fbfe415ac500f440337c17cb9502c85 (diff)
Added the DB Formatting calculation code
Change-Id: Id617118221b97f4fee3160e30d65225b6316610d
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/inc/dbdata.hxx1
-rw-r--r--sc/source/core/tool/dbdata2.cxx112
3 files changed, 114 insertions, 0 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 4fd1df13059a..5b24e6b246f6 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -204,6 +204,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/tool/compiler \
sc/source/core/tool/consoli \
sc/source/core/tool/dbdata \
+ sc/source/core/tool/dbdata2 \
sc/source/core/tool/dbdataformatting \
sc/source/core/tool/ddelink \
sc/source/core/tool/defaultsoptions \
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index a87f72fe584a..e6a35ede65c7 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -156,6 +156,7 @@ public:
SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
void ExtendDataArea(ScDocument* pDoc);
+ const OUString& GetCellStyle( const ScAddress& rPos, bool bRowStripe );
};
class SC_DLLPUBLIC ScDBCollection
diff --git a/sc/source/core/tool/dbdata2.cxx b/sc/source/core/tool/dbdata2.cxx
new file mode 100644
index 000000000000..c34d194a84a2
--- /dev/null
+++ b/sc/source/core/tool/dbdata2.cxx
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "dbdata.hxx"
+#include "dbdataformatting.hxx"
+
+const OUString& ScDBData::GetCellStyle( const ScAddress& rPos, bool bRowStripe )
+{
+ //first see if the DB Range has any DB Formatting at all
+ if( !HasFormatting() )
+ return OUString("Default");
+ //Calculating which style sheet is applicable to the give cell begins now
+ //Create a whole row stripe map
+ std::vector< OUString > aRowStripeSeq;
+ //Create a whole column stripe map
+ std::vector< OUString > aColStripeSeq;
+ //The above two vectors represent a whole row/col stripe by
+ //using consecutive entries of stylenames into the vector
+ //just as it would look like in a rendered single stripe.
+ ScDBDataFormatting aDBFormatting;
+ GetTableFormatting( aDBFormatting );
+ sal_Int32 i;
+ sal_Int32 nFirstSize;
+ sal_Int32 nSecondSize;
+ OUString aFirstStyle;
+ OUString aSecondStyle;
+ if ( bRowStripe )
+ {
+ //Fill the row stripe sequence
+ nFirstSize = aDBFormatting.GetFirstRowStripeSize();
+ aFirstStyle = aDBFormatting.GetFirstRowStripeStyle();
+ nSecondSize = aDBFormatting.GetSecondRowStripeSize();
+ aSecondStyle = aDBFormatting.GetSecondRowStripeStyle();
+ for ( i = 1; i <= nFirstSize; ++i )
+ {
+ //Add the first row stripe style to the RowStripeSeq vector nFirstSize
+ //many times.
+ aRowStripeSeq.push_back( aFirstStyle );
+ }
+ for ( i = 1; i<= nSecondSize; ++i )
+ {
+ //Similarly
+ aRowStripeSeq.push_back( aSecondStyle );
+ }
+ }
+ //Fill the column stripe sequence
+ else
+ {
+ nFirstSize = aDBFormatting.GetFirstColStripeSize();
+ aFirstStyle = aDBFormatting.GetFirstColStripeStyle();
+ nSecondSize = aDBFormatting.GetSecondColStripeSize();
+ aSecondStyle = aDBFormatting.GetSecondColStripeStyle();
+ for ( i = 1; i<=nFirstSize; ++i )
+ {
+ aColStripeSeq.push_back( aFirstStyle );
+ }
+ for ( i = 1; i<=nSecondSize; ++i )
+ {
+ aColStripeSeq.push_back( aSecondStyle );
+ }
+ }
+ //This approach of calculating the stripe sequence will be bad
+ //if stripe sizes are huge, they generally aren't.
+ //Now the math.
+ //We used 1-based addressing for this instead of the 0-based used in Calc
+ if ( bRowStripe )
+ {
+ sal_Int32 nStyleIndex = ( rPos.Row() + 1 ) % ( aRowStripeSeq.size() );
+ if ( nStyleIndex == 0 )
+ {
+ //Return the last entry in the vector
+ return aRowStripeSeq[ ( aRowStripeSeq.size() - 1 ) ];
+ }
+ else
+ {
+ //Return the nStyleIndex'th entry
+ return aRowStripeSeq[ ( nStyleIndex - 1) ];
+ }
+ }
+ else
+ {
+ sal_Int32 nStyleIndex = ( rPos.Row() + 1 ) % ( aRowStripeSeq.size() );
+ if ( nStyleIndex == 0 )
+ {
+ //Return the last entry in the vector
+ return aColStripeSeq[ ( aColStripeSeq.size() - 1 ) ];
+ }
+ else
+ {
+ //Return the nStyleIndex'th entry
+ return aColStripeSeq[ ( nStyleIndex - 1 ) ];
+ }
+ }
+}
+