summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-04-28 03:56:50 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-04-28 03:56:50 +0200
commit08f4273d7513e92f3dafa40b888467aaaf3c4b9f (patch)
tree48cd65c23544ae46b5c40de5c4e7da15fa2531a7 /chart2
parentbeccf477581b1f3e85100d43be81ea55d3b3f912 (diff)
we can't move that into a test only lib
Revert "move xshape dumper into test" This reverts commit beccf477581b1f3e85100d43be81ea55d3b3f912.
Diffstat (limited to 'chart2')
-rw-r--r--chart2/Library_chartview.mk1
-rw-r--r--chart2/source/view/main/ChartView.cxx116
2 files changed, 113 insertions, 4 deletions
diff --git a/chart2/Library_chartview.mk b/chart2/Library_chartview.mk
index 3977a779b41f..ab3952e1d7af 100644
--- a/chart2/Library_chartview.mk
+++ b/chart2/Library_chartview.mk
@@ -54,7 +54,6 @@ $(eval $(call gb_Library_use_libraries,chartview,\
svl \
svt \
svxcore \
- test \
tl \
utl \
vcl \
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 3f44b851d136..9020d7bf5266 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -113,7 +113,9 @@
#include <rtl/strbuf.hxx>
#include <rtl/oustringostreaminserter.hxx>
-#include <test/xshape_dumper.hxx>
+//libxml2 for dumping
+#include <libxml/xmlwriter.h>
+
//.............................................................................
namespace chart
@@ -3024,6 +3026,102 @@ uno::Sequence< ::rtl::OUString > ChartView::getAvailableServiceNames() throw (un
return aServiceNames;
}
+namespace {
+
+#define DEBUG_DUMPER 0
+
+int writeCallback(void* pContext, const char* sBuffer, int nLen)
+{
+ rtl::OStringBuffer* pBuffer = static_cast<rtl::OStringBuffer*>(pContext);
+ pBuffer->append(sBuffer);
+ return nLen;
+}
+
+int closeCallback(void* )
+{
+ return 0;
+}
+
+void dumpPositionAsAttribute(const awt::Point& rPoint, xmlTextWriterPtr xmlWriter)
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("positionX"), "%" SAL_PRIdINT32, rPoint.X);
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("positionY"), "%" SAL_PRIdINT32, rPoint.Y);
+}
+
+void dumpSizeAsAttribute(const awt::Size& rSize, xmlTextWriterPtr xmlWriter)
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("sizeX"), "%" SAL_PRIdINT32, rSize.Width);
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("sizeY"), "%" SAL_PRIdINT32, rSize.Height);
+}
+
+void dumpShapeDescriptorAsAttribute( uno::Reference< drawing::XShapeDescriptor > xDescr, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST("type"), "%s", rtl::OUStringToOString(xDescr->getShapeType(), RTL_TEXTENCODING_UTF8).getStr());
+}
+
+void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter );
+
+void dumpXShape( uno::Reference< drawing::XShape > xShape, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShape" ) );
+
+ dumpPositionAsAttribute(xShape->getPosition(), xmlWriter);
+ dumpSizeAsAttribute(xShape->getSize(), xmlWriter);
+ uno::Reference< drawing::XShapeDescriptor > xDescr(xShape, uno::UNO_QUERY_THROW);
+ dumpShapeDescriptorAsAttribute(xDescr, xmlWriter);
+
+ uno::Reference< lang::XServiceInfo > xServiceInfo( xShape, uno::UNO_QUERY_THROW );
+ uno::Sequence< rtl::OUString > aServiceNames = xServiceInfo->getSupportedServiceNames();
+
+ uno::Reference< beans::XPropertySet > xPropSet(xShape, uno::UNO_QUERY_THROW);
+ uno::Any aAny = xPropSet->getPropertyValue("Name");
+ rtl::OUString aName;
+ if (aAny >>= aName)
+ {
+ if (!aName.isEmpty())
+ xmlTextWriterWriteFormatAttribute( xmlWriter, BAD_CAST("name"), "%s", rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ if (xServiceInfo->supportsService("com.sun.star.drawing.Text"))
+ {
+ uno::Reference< text::XText > xText(xShape, uno::UNO_QUERY_THROW);
+ rtl::OUString aText = xText->getString();
+ if(!aText.isEmpty())
+ xmlTextWriterWriteFormatAttribute( xmlWriter, BAD_CAST("text"), "%s", rtl::OUStringToOString(aText, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ else if(xServiceInfo->supportsService("com.sun.star.drawing.GroupShape"))
+ {
+ uno::Reference< drawing::XShapes > xShapes(xShape, uno::UNO_QUERY_THROW);
+ dumpXShapes(xShapes, xmlWriter);
+ }
+#if DEBUG_DUMPER
+ sal_Int32 nServices = aServiceNames.getLength();
+ for (sal_Int32 i = 0; i < nServices; ++i)
+ {
+ xmlTextWriterStartElement(xmlWriter, BAD_CAST( "ServiceName" ));
+ xmlTextWriterWriteFormatAttribute(xmlWriter, BAD_CAST( "name" ), "%s", rtl::OUStringToOString(aServiceNames[i], RTL_TEXTENCODING_UTF8).getStr());
+ xmlTextWriterEndElement( xmlWriter );
+ }
+#endif
+
+ xmlTextWriterEndElement( xmlWriter );
+}
+
+void dumpXShapes( uno::Reference< drawing::XShapes > xShapes, xmlTextWriterPtr xmlWriter )
+{
+ xmlTextWriterStartElement( xmlWriter, BAD_CAST( "XShapes" ) );
+ uno::Reference< container::XIndexAccess > xIA( xShapes, uno::UNO_QUERY_THROW);
+ sal_Int32 nLength = xIA->getCount();
+ for (sal_Int32 i = 0; i < nLength; ++i)
+ {
+ uno::Reference< drawing::XShape > xShape( xIA->getByIndex( i ), uno::UNO_QUERY_THROW );
+ dumpXShape( xShape, xmlWriter );
+ }
+
+ xmlTextWriterEndElement( xmlWriter );
+}
+
+}
+
rtl::OUString ChartView::dump() throw (uno::RuntimeException)
{
impl_updateView();
@@ -3033,8 +3131,20 @@ rtl::OUString ChartView::dump() throw (uno::RuntimeException)
if (!xPageShapes.is())
return rtl::OUString();
- XShapeDumper aDumper(xPageShapes);
- return aDumper.dump();
+ rtl::OStringBuffer aString;
+ xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO( writeCallback, closeCallback, &aString, NULL );
+ xmlTextWriterPtr xmlWriter = xmlNewTextWriter( xmlOutBuffer );
+ xmlTextWriterSetIndent( xmlWriter, 1 );
+
+ xmlTextWriterStartDocument( xmlWriter, NULL, NULL, NULL );
+
+ dumpXShapes( xPageShapes, xmlWriter );
+
+ xmlTextWriterEndDocument( xmlWriter );
+ xmlFreeTextWriter( xmlWriter );
+
+
+ return OStringToOUString(aString.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
}
//.............................................................................