summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/view/gridwin_dbgutil.cxx
blob: b141bddd7619d9cda6f943cb60df8fd9d3dbb56f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* -*- 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/.
 */

#include <iostream>

#include <gridwin.hxx>
#include <svx/svdpage.hxx>
#include <libxml/xmlwriter.h>
#include <viewdata.hxx>
#include <document.hxx>
#include <patattr.hxx>
#include <userdat.hxx>
#include <dpobject.hxx>

namespace {

std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr)
{
    rStrm << "Col: " << rAddr.Col() << ", Row: " << rAddr.Row() << ", Tab: " << rAddr.Tab();
    return rStrm;
}

void dumpScDrawObjData(const ScGridWindow& rWindow, const ScDrawObjData& rData, MapUnit eMapUnit)
{
    const Point& rStartOffset = rData.maStartOffset;
    Point aStartOffsetPixel = rWindow.LogicToPixel(rStartOffset, MapMode(eMapUnit));
    std::cout << "  Start: " << rData.maStart << ", Offset: " << aStartOffsetPixel << std::endl;

    const Point& rEndOffset = rData.maEndOffset;
    Point aEndOffsetPixel = rWindow.LogicToPixel(rEndOffset, MapMode(eMapUnit));
    std::cout << "  End: : " << rData.maEnd << ", Offset: " << aEndOffsetPixel << std::endl;
}

}

void ScGridWindow::dumpColumnInformationPixel()
{
    ScDocument& rDoc = mrViewData.GetDocument();
    SCTAB nTab = mrViewData.GetTabNo();
    for (SCCOL nCol = 0; nCol <= 20; ++nCol)
    {
        sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
        tools::Long nPixel = LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::MapTwip)).getX();
        std::cout << "Column: " << nCol << ", Width: " << nPixel << "px" << std::endl;
    }
}

void ScGridWindow::dumpColumnInformationHmm()
{
    ScDocument& rDoc = mrViewData.GetDocument();
    SCTAB nTab = mrViewData.GetTabNo();
    for (SCCOL nCol = 0; nCol <= 20; ++nCol)
    {
        sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
        tools::Long nPixel = o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100);
        std::cout << "Column: " << nCol << ", Width: " << nPixel << "hmm" << std::endl;
    }
}

void ScGridWindow::dumpCellProperties()
{
    ScDocument& rDoc = mrViewData.GetDocument();
    const ScMarkData& rMark = mrViewData.GetMarkData();
    SCTAB nTab = mrViewData.GetTabNo();

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

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

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

    (void)xmlTextWriterStartDocument( writer, nullptr, nullptr, nullptr );

    (void)xmlTextWriterStartElement(writer, BAD_CAST("selection"));

    for (size_t i = 0, n = aList.size(); i < n; ++i)
    {
        ScRange const & rRange = aList[i];

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

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

                (void)xmlTextWriterEndElement(writer);
            }
        }
    }

    (void)xmlTextWriterEndElement(writer);

    (void)xmlTextWriterEndDocument( writer );
    xmlFreeTextWriter (writer);
}

void ScGridWindow::dumpGraphicInformation()
{
    ScDocument& rDoc = mrViewData.GetDocument();
    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
    if (!pDrawLayer)
        return;

    sal_uInt16 nPageCount = pDrawLayer->GetPageCount();
    for (sal_uInt16 nPage = 0; nPage < nPageCount; ++nPage)
    {
        SdrPage* pPage = pDrawLayer->GetPage(nPage);
        size_t nObjCount = pPage->GetObjCount();
        for (size_t nObj = 0; nObj < nObjCount; ++nObj)
        {
            SdrObject* pObj = pPage->GetObj(nObj);
            std::cout << "Graphic Object" << std::endl;
            ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObj);
            if (pObjData)
                dumpScDrawObjData(*this, *pObjData, pDrawLayer->GetScaleUnit());

            const tools::Rectangle& rRect = pObj->GetSnapRect();
            tools::Rectangle aRect = LogicToPixel(rRect, MapMode(pDrawLayer->GetScaleUnit()));
            std::cout << "Snap Rectangle (in pixel): " << aRect << std::endl;
        }
    }
}

void ScGridWindow::dumpColumnCellStorage()
{
    // Get the current cursor position.
    ScAddress aCurPos = mrViewData.GetCurPos();

    ScDocument& rDoc = mrViewData.GetDocument();
    const ScDPObject* pDP = rDoc.GetDPAtCursor(aCurPos.Col(), aCurPos.Row(), aCurPos.Tab());
    if (pDP)
    {
        // Dump the pivot table info if the cursor is over a pivot table.
        pDP->Dump();
        pDP->DumpCache();
        return;
    }

    // Dump the column cell storage info.
    rDoc.DumpColumnStorage(aCurPos.Tab(), aCurPos.Col());
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */