dump the whole selection and not just one cell

Change-Id: I059b5547d07c5e8f042e22f9de34ce51ffe49c38
Reviewed-on: https://gerrit.libreoffice.org/36313
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
diff --git a/sc/README b/sc/README
index 7c3bcfe1..8dfb5ec 100644
--- a/sc/README
+++ b/sc/README
@@ -12,5 +12,5 @@ Dumps the graphic objects and their position and size in pixel.

=== CTRL+SHIFT+F9 ===

Dumps the SfxItemSet representing the cell properties of the
current cell as a xml file.
Dumps the SfxItemSet representing the cell properties' of the
current selection as a xml file. The file will be named dump.xml
diff --git a/sc/source/ui/view/gridwin_dbgutil.cxx b/sc/source/ui/view/gridwin_dbgutil.cxx
index 36e7f85..70a594e 100644
--- a/sc/source/ui/view/gridwin_dbgutil.cxx
+++ b/sc/source/ui/view/gridwin_dbgutil.cxx
@@ -67,20 +67,62 @@ void ScGridWindow::dumpColumnInformationHmm()
void ScGridWindow::dumpCellProperties()
{
    ScDocument* pDoc = pViewData->GetDocument();

    const ScMarkData& rMark = pViewData->GetMarkData();
    SCTAB nTab = pViewData->GetTabNo();
    SCCOL nCol = pViewData->GetCurX();
    SCROW nRow = pViewData->GetCurY();
    const ScPatternAttr* pPatternAttr = pDoc->GetPattern(nCol,nRow,nTab);

    ScRangeList aList;
    if (rMark.IsMultiMarked())
    {
        aList = rMark.GetMarkedRangesForTab(nTab);
    }
    else if (rMark.IsMarked())
    {
        ScRange aRange;
        rMark.GetMarkArea(aRange);
        aList.Join(aRange);
    }
    else
    {
        SCCOL nCol = pViewData->GetCurX();
        SCROW nRow = pViewData->GetCurY();

        ScRange aRange(nCol, nRow, nTab);
        aList.Join(aRange, false);
    }

    OString aOutputFile("dump.xml");
    xmlTextWriterPtr writer = xmlNewTextWriterFilename( aOutputFile.getStr(), 0 );
    xmlTextWriterSetIndent(writer,1);
    xmlTextWriterSetIndentString(writer, BAD_CAST("  "));
    xmlTextWriterSetIndentString(writer, BAD_CAST("    "));

    xmlTextWriterStartDocument( writer, nullptr, nullptr, nullptr );

    pPatternAttr->GetItemSet().dumpAsXml(writer);
    xmlTextWriterStartElement(writer, BAD_CAST("selection"));

    for (size_t i = 0, n = aList.size(); i < n; ++i)
    {
        ScRange* pRange = aList[i];
        if (!pRange)
            continue;

        for (SCCOL nCol = pRange->aStart.Col(); nCol <= pRange->aEnd.Col(); ++nCol)
        {
            for (SCROW nRow = pRange->aStart.Row(); nRow <= pRange->aEnd.Row(); ++nRow)
            {
                const ScPatternAttr* pPatternAttr = pDoc->GetPattern(nCol, nRow, nTab);
                xmlTextWriterStartElement(writer, BAD_CAST("cell"));
                xmlTextWriterWriteAttribute(writer, BAD_CAST("column"), BAD_CAST(OString::number(nCol).getStr()));
                xmlTextWriterWriteAttribute(writer, BAD_CAST("row"), BAD_CAST(OString::number(nRow).getStr()));
                xmlTextWriterWriteAttribute(writer, BAD_CAST("tab"), BAD_CAST(OString::number(nTab).getStr()));

                pPatternAttr->GetItemSet().dumpAsXml(writer);

                xmlTextWriterEndElement(writer);
            }
        }
    }

    xmlTextWriterEndElement(writer);

    xmlTextWriterEndDocument( writer );
    xmlFreeTextWriter (writer);