Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/3475 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/75/3475/1 fdo#61541 : Count Number of selected Cells in calc Change-Id: If2951dad8463231b4f9c98daa3dfcb8a19ff268e --- M sc/inc/global.hxx M sc/inc/globstr.hrc M sc/source/core/data/column2.cxx M sc/source/core/data/documen4.cxx M sc/source/filter/xml/XMLConverter.cxx M sc/source/ui/src/globstr.src M sc/source/ui/view/tabvwsha.cxx M svx/inc/helpid.hrc M svx/source/stbctrls/stbctrls.h M svx/source/stbctrls/stbctrls.src 10 files changed, 116 insertions(+), 27 deletions(-) diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 44bd67a..0ef1bd8 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -741,7 +741,8 @@ SUBTOTAL_FUNC_STDP = 8, SUBTOTAL_FUNC_SUM = 9, SUBTOTAL_FUNC_VAR = 10, - SUBTOTAL_FUNC_VARP = 11 + SUBTOTAL_FUNC_VARP = 11, + SUBTOTAL_FUNC_SELECTION_COUNT = 12 }; class ScArea; diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index fa41d1d..24727b7 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -679,7 +679,9 @@ #define STR_UNDO_L2R 544 #define STR_UNDO_R2L 545 -#define STR_COUNT 546 +#define STR_FUN_TEXT_SELECTION_COUNT 546 + +#define STR_COUNT 547 #endif diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index c818c49..82f03cc 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -1972,15 +1972,58 @@ const ScMarkData& rMark, ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, bool bDoExclude, SCROW nExStartRow, SCROW nExEndRow) const { - SCSIZE nIndex; - ScMarkedDataIter aDataIter(this, &rMark, false); - while (aDataIter.Next( nIndex )) + if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT ) { - SCROW nRow = maItems[nIndex].nRow; - bool bRowHidden = rHiddenRows.getValue(nRow); - if ( !bRowHidden ) - if ( !bDoExclude || nRow < nExStartRow || nRow > nExEndRow ) - lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); + SCSIZE nIndex; + ScMarkedDataIter aDataIter(this, &rMark, false); + while (aDataIter.Next( nIndex )) + { + SCROW nRow = maItems[nIndex].nRow; + bool bRowHidden = rHiddenRows.getValue(nRow); + if ( !bRowHidden ) + if ( !bDoExclude || nRow < nExStartRow || nRow > nExEndRow ) + lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); + } + } + else + { + SCROW nTop, nBottom; + + // ScMarkData::GetArray() returns a valid array only if + // 'rMark.IsMultiMarked()' returns true. + // Since ScTable::UpdateSelectionFunction() already checked that first + // before calling this method it does not need to be repeated here. + + ScMarkArrayIter aIter(rMark.GetArray() + nCol); + ScFlatBoolRowSegments::RangeData aData; + + while (aIter.Next( nTop, nBottom )) + { + sal_Int32 nCellCount = 0; // to get the count of selected visible cells + SCROW nRow = nTop; + + while ( nRow <= nBottom ) + { + if (!rHiddenRows.getRangeData(nRow, aData)) // failed to get range data + break; + + if (aData.mnRow2 > nBottom) + aData.mnRow2 = nBottom; + + if (!aData.mbValue) + { + nCellCount += aData.mnRow2 - nRow + 1; + + // Till this point, nCellCount also includes count of those cells which are excluded + // So, they should be decremented now. + + if ( bDoExclude && nExStartRow >= nRow && nExEndRow <= aData.mnRow2 ) + nCellCount -= nExEndRow - nExStartRow + 1; + } + nRow = aData.mnRow2 + 1; + } + rData.nCount += nCellCount; + } } } @@ -1988,15 +2031,37 @@ void ScColumn::UpdateAreaFunction( ScFunctionData& rData, ScFlatBoolRowSegments& rHiddenRows, SCROW nStartRow, SCROW nEndRow) const { - SCSIZE nIndex; - Search( nStartRow, nIndex ); - while ( nIndex<maItems.size() && maItems[nIndex].nRow<=nEndRow ) + if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT ) { - SCROW nRow = maItems[nIndex].nRow; - bool bRowHidden = rHiddenRows.getValue(nRow); - if ( !bRowHidden ) - lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); - ++nIndex; + SCSIZE nIndex; + Search( nStartRow, nIndex ); + while ( nIndex<maItems.size() && maItems[nIndex].nRow<=nEndRow ) + { + SCROW nRow = maItems[nIndex].nRow; + bool bRowHidden = rHiddenRows.getValue(nRow); + if ( !bRowHidden ) + if ( rData.eFunc != SUBTOTAL_FUNC_SELECTION_COUNT ) + lcl_UpdateSubTotal( rData, maItems[nIndex].pCell ); + ++nIndex; + } + } + else + { + sal_Int32 nCellCount = 0; // to get the count of selected visible cells + SCROW nRow = nStartRow; + ScFlatBoolRowSegments::RangeData aData; + + while (nRow <= nEndRow) + { + if (!rHiddenRows.getRangeData(nRow, aData)) + break; + + if (!aData.mbValue) + nCellCount += (aData.mnRow2 <= nEndRow ? aData.mnRow2 : nEndRow) - nRow + 1; + + nRow = aData.mnRow2 + 1; + } + rData.nCount += nCellCount; } } diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 5ce49e2..f19cd8c 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -486,6 +486,7 @@ SCTAB nMax = static_cast<SCTAB>(maTabs.size()); ScMarkData::const_iterator itr = rMark.begin(), itrEnd = rMark.end(); + for (; itr != itrEnd && *itr < nMax && !aData.bError; ++itr) if (maTabs[*itr]) maTabs[*itr]->UpdateSelectionFunction( aData, @@ -499,6 +500,9 @@ case SUBTOTAL_FUNC_SUM: rResult = aData.nVal; break; + case SUBTOTAL_FUNC_SELECTION_COUNT: + rResult = aData.nCount; + break; case SUBTOTAL_FUNC_CNT: case SUBTOTAL_FUNC_CNT2: rResult = aData.nCount; diff --git a/sc/source/filter/xml/XMLConverter.cxx b/sc/source/filter/xml/XMLConverter.cxx index ae58cef..da12592 100644 --- a/sc/source/filter/xml/XMLConverter.cxx +++ b/sc/source/filter/xml/XMLConverter.cxx @@ -154,6 +154,9 @@ case SUBTOTAL_FUNC_STD: sFuncStr = GetXMLToken( XML_STDEV ); break; case SUBTOTAL_FUNC_STDP: sFuncStr = GetXMLToken( XML_STDEVP ); break; case SUBTOTAL_FUNC_SUM: sFuncStr = GetXMLToken( XML_SUM ); break; + case SUBTOTAL_FUNC_SELECTION_COUNT: break; + // it is not needed as it is only a UI value and not document content + case SUBTOTAL_FUNC_VAR: sFuncStr = GetXMLToken( XML_VAR ); break; case SUBTOTAL_FUNC_VARP: sFuncStr = GetXMLToken( XML_VARP ); break; } diff --git a/sc/source/ui/src/globstr.src b/sc/source/ui/src/globstr.src index e5fe2dc..375db7b 100644 --- a/sc/source/ui/src/globstr.src +++ b/sc/source/ui/src/globstr.src @@ -686,6 +686,10 @@ { Text [ en-US ] = "Sum" ; }; + String STR_FUN_TEXT_SELECTION_COUNT + { + Text [ en-US ] = "Selection count" ; + }; String STR_FUN_TEXT_COUNT { Text [ en-US ] = "Count" ; diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index e9a5e6b..1cc39fd 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -80,6 +80,8 @@ case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break; case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break; case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break; + case SUBTOTAL_FUNC_SELECTION_COUNT: nGlobStrId = STR_FUN_TEXT_SELECTION_COUNT; break; + default: { // added to avoid warnings @@ -106,7 +108,7 @@ // Number in the standard format, the other on the cursor position SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); sal_uInt32 nNumFmt = 0; - if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 ) + if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 && eFunc != SUBTOTAL_FUNC_SELECTION_COUNT) { // Zahlformat aus Attributen oder Formel pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt ); diff --git a/svx/inc/helpid.hrc b/svx/inc/helpid.hrc index 5455b33..b2088f6 100644 --- a/svx/inc/helpid.hrc +++ b/svx/inc/helpid.hrc @@ -134,6 +134,7 @@ #define HID_MNU_FUNC_MIN "SVX_HID_MNU_FUNC_MIN" #define HID_MNU_FUNC_NONE "SVX_HID_MNU_FUNC_NONE" #define HID_MNU_FUNC_SUM "SVX_HID_MNU_FUNC_SUM" +#define HID_MNU_FUNC_SELECTION_COUNT "SVX_HID_MNU_FUNC_SELECTION_COUNT" #define HID_MNU_ZOOM_100 "SVX_HID_MNU_ZOOM_100" #define HID_MNU_ZOOM_150 "SVX_HID_MNU_ZOOM_150" #define HID_MNU_ZOOM_200 "SVX_HID_MNU_ZOOM_200" diff --git a/svx/source/stbctrls/stbctrls.h b/svx/source/stbctrls/stbctrls.h index 7482c0b..0b5e56d 100644 --- a/svx/source/stbctrls/stbctrls.h +++ b/svx/source/stbctrls/stbctrls.h @@ -31,15 +31,16 @@ #define ZOOM_PAGE_WIDTH 7 #define ZOOM_WHOLE_PAGE 8 -// IDs wie SUBTOTAL_FUNC im Calc +// IDs as in SUBTOTAL_FUNC of Calc -#define PSZ_FUNC_AVG 1 -#define PSZ_FUNC_COUNT2 3 -#define PSZ_FUNC_COUNT 2 -#define PSZ_FUNC_MAX 4 -#define PSZ_FUNC_MIN 5 -#define PSZ_FUNC_SUM 9 -#define PSZ_FUNC_NONE 16 +#define PSZ_FUNC_AVG 1 +#define PSZ_FUNC_COUNT2 3 +#define PSZ_FUNC_COUNT 2 +#define PSZ_FUNC_MAX 4 +#define PSZ_FUNC_MIN 5 +#define PSZ_FUNC_SUM 9 +#define PSZ_FUNC_SELECTION_COUNT 12 +#define PSZ_FUNC_NONE 16 #define XMLSEC_CALL 1 diff --git a/svx/source/stbctrls/stbctrls.src b/svx/source/stbctrls/stbctrls.src index a5b6799..8d5beeb 100644 --- a/svx/source/stbctrls/stbctrls.src +++ b/svx/source/stbctrls/stbctrls.src @@ -218,6 +218,12 @@ }; MenuItem { + Identifier = PSZ_FUNC_SELECTION_COUNT ; + HelpId = HID_MNU_FUNC_SELECTION_COUNT ; + Text [ en-US ] = "Selection count" ; + }; + MenuItem + { Identifier = PSZ_FUNC_NONE ; HelpId = HID_MNU_FUNC_NONE ; Text [ en-US ] = "None" ; -- To view, visit https://gerrit.libreoffice.org/3475 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If2951dad8463231b4f9c98daa3dfcb8a19ff268e Gerrit-PatchSet: 1 Gerrit-Project: core Gerrit-Branch: master Gerrit-Owner: Prashant Pandey <prashant3.yi...@gmail.com> _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice