LibreOffice Module sc (master)  1
gridwin_dbgutil.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <iostream>
11 
12 #include <gridwin.hxx>
13 #include <svx/svdpage.hxx>
14 #include <libxml/xmlwriter.h>
15 #include <viewdata.hxx>
16 #include <document.hxx>
17 #include <patattr.hxx>
18 #include <userdat.hxx>
19 #include <dpobject.hxx>
20 
21 namespace {
22 
23 std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr)
24 {
25  rStrm << "Col: " << rAddr.Col() << ", Row: " << rAddr.Row() << ", Tab: " << rAddr.Tab();
26  return rStrm;
27 }
28 
29 void dumpScDrawObjData(const ScGridWindow& rWindow, const ScDrawObjData& rData, MapUnit eMapUnit)
30 {
31  const Point& rStartOffset = rData.maStartOffset;
32  Point aStartOffsetPixel = rWindow.LogicToPixel(rStartOffset, MapMode(eMapUnit));
33  std::cout << " Start: " << rData.maStart << ", Offset: " << aStartOffsetPixel << std::endl;
34 
35  const Point& rEndOffset = rData.maEndOffset;
36  Point aEndOffsetPixel = rWindow.LogicToPixel(rEndOffset, MapMode(eMapUnit));
37  std::cout << " End: : " << rData.maEnd << ", Offset: " << aEndOffsetPixel << std::endl;
38 }
39 
40 }
41 
43 {
45  SCTAB nTab = mrViewData.GetTabNo();
46  for (SCCOL nCol = 0; nCol <= 20; ++nCol)
47  {
48  sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
49  tools::Long nPixel = LogicToPixel(Point(nWidth, 0), MapMode(MapUnit::MapTwip)).getX();
50  std::cout << "Column: " << nCol << ", Width: " << nPixel << "px" << std::endl;
51  }
52 }
53 
55 {
57  SCTAB nTab = mrViewData.GetTabNo();
58  for (SCCOL nCol = 0; nCol <= 20; ++nCol)
59  {
60  sal_uInt16 nWidth = rDoc.GetColWidth(nCol, nTab);
61  tools::Long nPixel = LogicToLogic(Point(nWidth, 0), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM)).getX();
62  std::cout << "Column: " << nCol << ", Width: " << nPixel << "hmm" << std::endl;
63  }
64 }
65 
67 {
69  const ScMarkData& rMark = mrViewData.GetMarkData();
70  SCTAB nTab = mrViewData.GetTabNo();
71 
72  ScRangeList aList;
73  if (rMark.IsMultiMarked())
74  {
75  aList = rMark.GetMarkedRangesForTab(nTab);
76  }
77  else if (rMark.IsMarked())
78  {
79  ScRange aRange;
80  rMark.GetMarkArea(aRange);
81  aList.Join(aRange);
82  }
83  else
84  {
85  SCCOL nCol = mrViewData.GetCurX();
86  SCROW nRow = mrViewData.GetCurY();
87 
88  ScRange aRange(nCol, nRow, nTab);
89  aList.Join(aRange, false);
90  }
91 
92  xmlTextWriterPtr writer = xmlNewTextWriterFilename( "dump.xml", 0 );
93  xmlTextWriterSetIndent(writer,1);
94  xmlTextWriterSetIndentString(writer, BAD_CAST(" "));
95 
96  xmlTextWriterStartDocument( writer, nullptr, nullptr, nullptr );
97 
98  xmlTextWriterStartElement(writer, BAD_CAST("selection"));
99 
100  for (size_t i = 0, n = aList.size(); i < n; ++i)
101  {
102  ScRange const & rRange = aList[i];
103 
104  for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
105  {
106  for (SCROW nRow = rRange.aStart.Row(); nRow <= rRange.aEnd.Row(); ++nRow)
107  {
108  const ScPatternAttr* pPatternAttr = rDoc.GetPattern(nCol, nRow, nTab);
109  xmlTextWriterStartElement(writer, BAD_CAST("cell"));
110  xmlTextWriterWriteAttribute(writer, BAD_CAST("column"), BAD_CAST(OString::number(nCol).getStr()));
111  xmlTextWriterWriteAttribute(writer, BAD_CAST("row"), BAD_CAST(OString::number(nRow).getStr()));
112  xmlTextWriterWriteAttribute(writer, BAD_CAST("tab"), BAD_CAST(OString::number(nTab).getStr()));
113 
114  pPatternAttr->GetItemSet().dumpAsXml(writer);
115 
116  xmlTextWriterEndElement(writer);
117  }
118  }
119  }
120 
121  xmlTextWriterEndElement(writer);
122 
123  xmlTextWriterEndDocument( writer );
124  xmlFreeTextWriter (writer);
125 }
126 
128 {
130  ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
131  if (!pDrawLayer)
132  return;
133 
134  sal_uInt16 nPageCount = pDrawLayer->GetPageCount();
135  for (sal_uInt16 nPage = 0; nPage < nPageCount; ++nPage)
136  {
137  SdrPage* pPage = pDrawLayer->GetPage(nPage);
138  size_t nObjCount = pPage->GetObjCount();
139  for (size_t nObj = 0; nObj < nObjCount; ++nObj)
140  {
141  SdrObject* pObj = pPage->GetObj(nObj);
142  std::cout << "Graphic Object" << std::endl;
143  ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObj);
144  if (pObjData)
145  dumpScDrawObjData(*this, *pObjData, pDrawLayer->GetScaleUnit());
146 
147  const tools::Rectangle& rRect = pObj->GetSnapRect();
148  tools::Rectangle aRect = LogicToPixel(rRect, MapMode(pDrawLayer->GetScaleUnit()));
149  std::cout << "Snap Rectangle (in pixel): " << aRect << std::endl;
150  }
151  }
152 }
153 
155 {
156  // Get the current cursor position.
157  ScAddress aCurPos = mrViewData.GetCurPos();
158 
160  const ScDPObject* pDP = rDoc.GetDPAtCursor(aCurPos.Col(), aCurPos.Row(), aCurPos.Tab());
161  if (pDP)
162  {
163  // Dump the pivot table info if the cursor is over a pivot table.
164  pDP->Dump();
165  pDP->DumpCache();
166  return;
167  }
168 
169  // Dump the column cell storage info.
170  rDoc.DumpColumnStorage(aCurPos.Tab(), aCurPos.Col());
171 }
172 
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:372
ScAddress aStart
Definition: address.hxx:500
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void dumpAsXml(xmlTextWriterPtr pWriter) const
struct _xmlTextWriter * xmlTextWriterPtr
SCROW Row() const
Definition: address.hxx:262
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void dumpColumnInformationHmm()
long Long
SCROW GetCurY() const
Definition: viewdata.hxx:402
static ScDrawObjData * GetObjData(SdrObject *pObj, bool bCreate=false)
Definition: drwlayer.cxx:2282
sal_Int64 n
ScViewData & mrViewData
Definition: gridwin.hxx:150
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
const SfxItemSet & GetItemSet() const
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:501
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
void dumpGraphicInformation()
ScAddress maStart
Definition: userdat.hxx:38
void dumpColumnCellStorage()
virtual const tools::Rectangle & GetSnapRect() const
void GetMarkArea(ScRange &rRange) const
Definition: markdata.cxx:112
MapUnit GetScaleUnit() const
bool IsMultiMarked() const
Definition: markdata.hxx:83
SCTAB Tab() const
Definition: address.hxx:271
Point maEndOffset
Definition: userdat.hxx:41
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4735
void DumpCache() const
SC_DLLPUBLIC void DumpColumnStorage(SCTAB nTab, SCCOL nCol) const
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const ParamIfsResult &rRes)
Definition: interpre.hxx:73
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1059
bool IsMarked() const
Definition: markdata.hxx:82
#define nPixel
int i
sal_Int16 SCCOL
Definition: types.hxx:22
void dumpColumnInformationPixel()
const SdrPage * GetPage(sal_uInt16 nPgNum) const
size_t size() const
Definition: rangelst.hxx:90
Point maStartOffset
Definition: userdat.hxx:40
SCCOL Col() const
Definition: address.hxx:267
ScAddress GetCurPos() const
Definition: viewdata.cxx:4007
void Dump() const
Point LogicToPixel(const Point &rLogicPt) const
sal_Int32 SCROW
Definition: types.hxx:18
void Join(const ScRange &, bool bIsInList=false)
Definition: rangelst.cxx:166
void dumpCellProperties()
ScRangeList GetMarkedRangesForTab(SCTAB nTab) const
Get marked ranges with sheet-tab set to nTab.
Definition: markdata.cxx:472
MapUnit
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4120
ScAddress maEnd
Definition: userdat.hxx:39
sal_uInt16 GetPageCount() const
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401